From 282b02b3a87d9ccf28b2c01548ac9d2159083f6b Mon Sep 17 00:00:00 2001 From: ArrisLee Date: Thu, 19 Aug 2021 15:41:50 +1200 Subject: [PATCH] updates based on tech review feedback --- api/http/handler/stacks/stack_update.go | 16 ++++++++-------- .../handler/stacks/stack_update_git_redeploy.go | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/api/http/handler/stacks/stack_update.go b/api/http/handler/stacks/stack_update.go index 4845ef829..99aeab570 100644 --- a/api/http/handler/stacks/stack_update.go +++ b/api/http/handler/stacks/stack_update.go @@ -128,6 +128,14 @@ func (handler *Handler) stackUpdate(w http.ResponseWriter, r *http.Request) *htt return updateError } + user, err := handler.DataStore.User().User(securityContext.UserID) + if err != nil { + return &httperror.HandlerError{StatusCode: http.StatusBadRequest, Message: "Cannot find context user", Err: errors.Wrap(err, "failed to fetch the user")} + } + stack.UpdatedBy = user.Username + stack.UpdateDate = time.Now().Unix() + stack.Status = portainer.StackStatusActive + err = handler.DataStore.Stack().UpdateStack(stack.ID, stack) if err != nil { return &httperror.HandlerError{StatusCode: http.StatusInternalServerError, Message: "Unable to persist the stack changes inside the database", Err: err} @@ -173,10 +181,6 @@ func (handler *Handler) updateComposeStack(r *http.Request, stack *portainer.Sta return configErr } - stack.UpdateDate = time.Now().Unix() - stack.UpdatedBy = config.user.Username - stack.Status = portainer.StackStatusActive - err = handler.deployComposeStack(config) if err != nil { return &httperror.HandlerError{StatusCode: http.StatusInternalServerError, Message: err.Error(), Err: err} @@ -205,10 +209,6 @@ func (handler *Handler) updateSwarmStack(r *http.Request, stack *portainer.Stack return configErr } - stack.UpdateDate = time.Now().Unix() - stack.UpdatedBy = config.user.Username - stack.Status = portainer.StackStatusActive - err = handler.deploySwarmStack(config) if err != nil { return &httperror.HandlerError{StatusCode: http.StatusInternalServerError, Message: err.Error(), Err: err} diff --git a/api/http/handler/stacks/stack_update_git_redeploy.go b/api/http/handler/stacks/stack_update_git_redeploy.go index c9558ba3f..3dfb5e8af 100644 --- a/api/http/handler/stacks/stack_update_git_redeploy.go +++ b/api/http/handler/stacks/stack_update_git_redeploy.go @@ -179,7 +179,7 @@ func (handler *Handler) stackGitRedeploy(w http.ResponseWriter, r *http.Request) err = handler.DataStore.Stack().UpdateStack(stack.ID, stack) if err != nil { - return &httperror.HandlerError{StatusCode: http.StatusInternalServerError, Message: "Unable to persist the stack changes inside the database", Err: err} + return &httperror.HandlerError{StatusCode: http.StatusInternalServerError, Message: "Unable to persist the stack changes inside the database", Err: errors.Wrap(err, "failed to update the stack")} } if stack.GitConfig != nil && stack.GitConfig.Authentication != nil && stack.GitConfig.Authentication.Password != "" {