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