From 17b941d10824b7bc492e934b25770a4eedb73aa5 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:48:59 -0400 Subject: [PATCH] Add options object for PortainerClient.StackCreateCompose() --- client/client.go | 20 ++++++++++++++------ cmd/stackDeploy.go | 7 ++++++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/client/client.go b/client/client.go index fdf975a..7cb1b22 100644 --- a/client/client.go +++ b/client/client.go @@ -33,6 +33,14 @@ type StackCreateSwarmOptions struct { EndpointID portainer.EndpointID } +// StackCreateComposeOptions represents options passed to PortainerClient.StackCreateCompose() +type StackCreateComposeOptions struct { + StackName string + EnvironmentVariables []portainer.Pair + StackFileContent string + EndpointID portainer.EndpointID +} + // Config represents a Portainer client configuration type Config struct { URL *url.URL @@ -61,7 +69,7 @@ type PortainerClient interface { StackCreateSwarm(options StackCreateSwarmOptions) (stack portainer.Stack, err error) // Create compose stack - StackCreateCompose(stackName string, environmentVariables []portainer.Pair, stackFileContent string, endpointID portainer.EndpointID) (stack portainer.Stack, err error) + 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 @@ -265,14 +273,14 @@ func (n *portainerClientImp) StackCreateSwarm(options StackCreateSwarmOptions) ( return } -func (n *portainerClientImp) StackCreateCompose(stackName string, environmentVariables []portainer.Pair, stackFileContent string, endpointID portainer.EndpointID) (stack portainer.Stack, err error) { +func (n *portainerClientImp) StackCreateCompose(options StackCreateComposeOptions) (stack portainer.Stack, err error) { reqBody := StackCreateRequest{ - Name: stackName, - Env: environmentVariables, - StackFileContent: stackFileContent, + Name: options.StackName, + Env: options.EnvironmentVariables, + StackFileContent: options.StackFileContent, } - err = n.doJSONWithToken(fmt.Sprintf("stacks?type=%v&method=%s&endpointId=%v", 2, "string", endpointID), http.MethodPost, http.Header{}, &reqBody, &stack) + err = n.doJSONWithToken(fmt.Sprintf("stacks?type=%v&method=%s&endpointId=%v", 2, "string", options.EndpointID), http.MethodPost, http.Header{}, &reqBody, &stack) return } diff --git a/cmd/stackDeploy.go b/cmd/stackDeploy.go index 4b0b0c5..2d5a293 100644 --- a/cmd/stackDeploy.go +++ b/cmd/stackDeploy.go @@ -156,7 +156,12 @@ var stackDeployCmd = &cobra.Command{ "stack": stackName, "endpoint": endpoint.Name, }).Info("Creating stack") - stack, deploymentErr := portainerClient.StackCreateCompose(stackName, loadedEnvironmentVariables, stackFileContent, endpoint.ID) + stack, deploymentErr := portainerClient.StackCreateCompose(client.StackCreateComposeOptions{ + StackName: stackName, + EnvironmentVariables: loadedEnvironmentVariables, + StackFileContent: stackFileContent, + EndpointID: endpoint.ID, + }) common.CheckError(deploymentErr) logrus.WithFields(logrus.Fields{ "stack": stack.Name,