Is password set field
This commit is contained in:
parent
2077271306
commit
5f80da8cbd
5 changed files with 29 additions and 3 deletions
|
@ -115,7 +115,7 @@ func (a *AppsProcessor) Update(name string, SSHPort int, HTTPPort int, image str
|
|||
}
|
||||
|
||||
// UpdateResources updates various metrics saved in the database
|
||||
func (a *AppsProcessor) UpdateResources(name string, state string, OOMKilled bool, CPUUsage float64, memory int, diskUsageBytes int, diskUsageInodes int, flags detector.Flags) error {
|
||||
func (a *AppsProcessor) UpdateResources(name string, state string, OOMKilled bool, CPUUsage float64, memory int, diskUsageBytes int, diskUsageInodes int, flags detector.Flags, isPasswordSet bool) error {
|
||||
err := a.DB.Model(&App{}).Where("name = ?", name).Updates(App{
|
||||
State: state,
|
||||
OOMKilled: OOMKilled,
|
||||
|
@ -124,6 +124,7 @@ func (a *AppsProcessor) UpdateResources(name string, state string, OOMKilled boo
|
|||
DiskUsageBytes: diskUsageBytes,
|
||||
DiskUsageInodes: diskUsageInodes,
|
||||
Flags: flags.String(),
|
||||
IsPasswordSet: isPasswordSet,
|
||||
}).Error
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ func TestAppsProcessorUpdateResources(t *testing.T) {
|
|||
err := processor.New("updateresources_1224", 1002, 1003, "testimage", 2, 256)
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = processor.UpdateResources("updateresources_1224", "running", true, 1000, 256, 100, 200, detector.Flags{"test"})
|
||||
err = processor.UpdateResources("updateresources_1224", "running", true, 1000, 256, 100, 200, detector.Flags{"test"}, true)
|
||||
assert.Nil(t, err)
|
||||
|
||||
app, err := processor.Get("updateresources_1224")
|
||||
|
@ -107,6 +107,7 @@ func TestAppsProcessorUpdateResources(t *testing.T) {
|
|||
assert.Equal(t, 256, app.MemoryUsage)
|
||||
assert.Equal(t, 100, app.DiskUsageBytes)
|
||||
assert.Equal(t, 200, app.DiskUsageInodes)
|
||||
assert.Equal(t, true, app.IsPasswordSet)
|
||||
assert.Contains(t, app.Flags, "test")
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ type AppState struct {
|
|||
DiskUsageBytes int `json:"disk_usage_bytes"`
|
||||
DiskUsageInodes int `json:"disk_usage_inodes"`
|
||||
Flags detector.Flags `json:"flags"`
|
||||
IsPasswordSet bool `json:"is_password_set"`
|
||||
}
|
||||
|
||||
// Apps is list of applications
|
||||
|
@ -94,7 +95,8 @@ type App struct {
|
|||
// Disk usage in inodes
|
||||
DiskUsageInodes int `json:"disk_usage_inodes"`
|
||||
// Flags from detector of problems in the container
|
||||
Flags string `json:"flags"` // flags are separated by comma
|
||||
Flags string `json:"flags"` // flags are separated by comma
|
||||
IsPasswordSet bool `json:"is_password_set"` // True if the password is set in the container (file with the password exists)
|
||||
|
||||
// this is gathered in docker package and has to be assembled externally
|
||||
Techs AppTechs `json:"techs,omitempty" gorm:"-"` // list of available technologies in the image
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -17,6 +18,7 @@ import (
|
|||
const appUsername = "app"
|
||||
const owner = "app:app"
|
||||
const passwordFile = "/srv/.rosti"
|
||||
const passwordFileNoPath = ".rosti"
|
||||
const deployKeyType = "ed25519"
|
||||
const deployKeyPrefix = "rosti_deploy"
|
||||
|
||||
|
@ -96,6 +98,11 @@ func (c *Container) GetState() (*apps.AppState, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
isPasswordSet, err := c.IsPasswordSet()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
state := apps.AppState{
|
||||
State: status.Status,
|
||||
OOMKilled: status.OOMKilled,
|
||||
|
@ -106,6 +113,7 @@ func (c *Container) GetState() (*apps.AppState, error) {
|
|||
DiskUsageBytes: bytes,
|
||||
DiskUsageInodes: inodes,
|
||||
Flags: flags,
|
||||
IsPasswordSet: isPasswordSet,
|
||||
}
|
||||
|
||||
return &state, nil
|
||||
|
@ -135,6 +143,19 @@ func (c *Container) DiskUsage() (int, int, error) {
|
|||
return du(c.VolumeHostPath())
|
||||
}
|
||||
|
||||
// IsPasswordSet returns true if the password is set for the container (file with the password exists)
|
||||
func (c *Container) IsPasswordSet() (bool, error) {
|
||||
_, err := os.Stat(path.Join(c.VolumeHostPath(), passwordFileNoPath))
|
||||
if err != nil && os.IsNotExist(err) {
|
||||
return false, nil
|
||||
}
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// ResourceUsage returns amount of memory in B and CPU in % that the app occupies
|
||||
func (c *Container) ResourceUsage() (float64, int, error) {
|
||||
driver := c.getDriver()
|
||||
|
|
|
@ -59,6 +59,7 @@ func (s *StatsProcessor) UpdateUsage(name string) error {
|
|||
state.DiskUsageBytes,
|
||||
state.DiskUsageInodes,
|
||||
state.Flags,
|
||||
state.IsPasswordSet,
|
||||
)
|
||||
|
||||
return err
|
||||
|
|
Loading…
Reference in a new issue