From d17b9eb9f546dce936908fab1926a8d54cf96748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Carlos=20Mej=C3=ADas=20Rodr=C3=ADguez?= Date: Mon, 26 Aug 2019 01:52:41 -0400 Subject: [PATCH] Add options object for PortainerClient.StackUpdate() --- client/client.go | 21 +++++++++++++++------ cmd/stackDeploy.go | 8 +++++++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/client/client.go b/client/client.go index 7cb1b22..e80be22 100644 --- a/client/client.go +++ b/client/client.go @@ -41,6 +41,15 @@ type StackCreateComposeOptions struct { EndpointID portainer.EndpointID } +// StackUpdateOptions represents options passed to PortainerClient.StackUpdate() +type StackUpdateOptions struct { + Stack portainer.Stack + EnvironmentVariables []portainer.Pair + StackFileContent string + Prune bool + EndpointID portainer.EndpointID +} + // Config represents a Portainer client configuration type Config struct { URL *url.URL @@ -72,7 +81,7 @@ type PortainerClient interface { StackCreateCompose(options StackCreateComposeOptions) (stack portainer.Stack, err error) // Update stack - StackUpdate(stack portainer.Stack, environmentVariables []portainer.Pair, stackFileContent string, prune bool, endpointID portainer.EndpointID) error + StackUpdate(options StackUpdateOptions) error // Delete stack StackDelete(stackID portainer.StackID) error @@ -284,14 +293,14 @@ func (n *portainerClientImp) StackCreateCompose(options StackCreateComposeOption return } -func (n *portainerClientImp) StackUpdate(stack portainer.Stack, environmentVariables []portainer.Pair, stackFileContent string, prune bool, endpointID portainer.EndpointID) (err error) { +func (n *portainerClientImp) StackUpdate(options StackUpdateOptions) (err error) { reqBody := StackUpdateRequest{ - Env: environmentVariables, - StackFileContent: stackFileContent, - Prune: prune, + Env: options.EnvironmentVariables, + StackFileContent: options.StackFileContent, + Prune: options.Prune, } - err = n.doJSONWithToken(fmt.Sprintf("stacks/%v?endpointId=%v", stack.ID, endpointID), http.MethodPut, http.Header{}, &reqBody, nil) + err = n.doJSONWithToken(fmt.Sprintf("stacks/%v?endpointId=%v", options.Stack.ID, options.EndpointID), http.MethodPut, http.Header{}, &reqBody, nil) return } diff --git a/cmd/stackDeploy.go b/cmd/stackDeploy.go index 2d5a293..dfdde9e 100644 --- a/cmd/stackDeploy.go +++ b/cmd/stackDeploy.go @@ -117,7 +117,13 @@ var stackDeployCmd = &cobra.Command{ logrus.WithFields(logrus.Fields{ "stack": retrievedStack.Name, }).Info("Updating stack") - err := portainerClient.StackUpdate(retrievedStack, newEnvironmentVariables, stackFileContent, viper.GetBool("stack.deploy.prune"), endpoint.ID) + err := portainerClient.StackUpdate(client.StackUpdateOptions{ + Stack: retrievedStack, + EnvironmentVariables: newEnvironmentVariables, + StackFileContent: stackFileContent, + Prune: viper.GetBool("stack.deploy.prune"), + EndpointID: endpoint.ID, + }) common.CheckError(err) } else if stackRetrievalErr == common.ErrStackNotFound { // We are deploying a new stack