From fe8aa885e788ea72bf19c814b4d4f1671af71ce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C5=A0trauch?= Date: Sat, 14 Oct 2023 01:10:14 +0200 Subject: [PATCH] Add env --- apps/main.go | 6 +++++- glue/main.go | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/main.go b/apps/main.go index 1ee7c6b..b79790f 100644 --- a/apps/main.go +++ b/apps/main.go @@ -67,7 +67,7 @@ func (a *AppsProcessor) New(name string, SSHPort int, HTTPPort int, image string } // 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 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 } + if len(env) != 0 { + app.Env = env + } + validationErrors := app.Validate() if len(validationErrors) != 0 { return &app, ValidationError{ diff --git a/glue/main.go b/glue/main.go index a291cf7..ae8ae63 100644 --- a/glue/main.go +++ b/glue/main.go @@ -306,8 +306,12 @@ func (p *Processor) Register(appTemplate apps.App) error { // Update updates application func (p *Processor) Update(appTemplate apps.App) error { + if appTemplate.Env == nil { + appTemplate.Env = make(map[string]string) + } + 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 validationError, ok := err.(apps.ValidationError); ok { return fmt.Errorf("validation error: %v", validationError.Error())