Add env
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Adam Štrauch 2023-10-14 01:10:14 +02:00
parent 00beda8137
commit fe8aa885e7
Signed by: cx
GPG Key ID: 7262DAFE292BCE20
2 changed files with 10 additions and 2 deletions

View File

@ -67,7 +67,7 @@ func (a *AppsProcessor) New(name string, SSHPort int, HTTPPort int, image string
} }
// Update changes value about app in the database // Update changes value about app in the database
func (a *AppsProcessor) Update(name string, SSHPort int, HTTPPort int, image string, CPU int, memory int) (*App, error) { func (a *AppsProcessor) Update(name string, SSHPort int, HTTPPort int, image string, CPU int, memory int, env map[string]string) (*App, error) {
var app App var app App
err := a.DB.Where("name = ?", name).First(&app).Error err := a.DB.Where("name = ?", name).First(&app).Error
@ -98,6 +98,10 @@ func (a *AppsProcessor) Update(name string, SSHPort int, HTTPPort int, image str
app.HTTPPort = HTTPPort app.HTTPPort = HTTPPort
} }
if len(env) != 0 {
app.Env = env
}
validationErrors := app.Validate() validationErrors := app.Validate()
if len(validationErrors) != 0 { if len(validationErrors) != 0 {
return &app, ValidationError{ return &app, ValidationError{

View File

@ -306,8 +306,12 @@ func (p *Processor) Register(appTemplate apps.App) error {
// Update updates application // Update updates application
func (p *Processor) Update(appTemplate apps.App) error { func (p *Processor) Update(appTemplate apps.App) error {
if appTemplate.Env == nil {
appTemplate.Env = make(map[string]string)
}
processor := p.getAppProcessor() processor := p.getAppProcessor()
app, err := processor.Update(appTemplate.Name, appTemplate.SSHPort, appTemplate.HTTPPort, appTemplate.Image, appTemplate.CPU, appTemplate.Memory) app, err := processor.Update(appTemplate.Name, appTemplate.SSHPort, appTemplate.HTTPPort, appTemplate.Image, appTemplate.CPU, appTemplate.Memory, appTemplate.Env)
if err != nil { if err != nil {
if validationError, ok := err.(apps.ValidationError); ok { if validationError, ok := err.(apps.ValidationError); ok {
return fmt.Errorf("validation error: %v", validationError.Error()) return fmt.Errorf("validation error: %v", validationError.Error())