mirror of
https://gitlab.com/psuapp/psu.git
synced 2024-08-30 18:12:34 +00:00
Move PrintVerbose() calls in client to it's callers
This commit is contained in:
parent
955a79de6f
commit
1830fea7b7
@ -10,8 +10,6 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/greenled/portainer-stack-utils/util"
|
||||
)
|
||||
|
||||
type StackListFilter struct {
|
||||
@ -171,8 +169,6 @@ func (n *portainerClientImp) AfterResponse(hook func(resp *http.Response) (err e
|
||||
|
||||
// Authenticate a user to get an auth token
|
||||
func (n *portainerClientImp) Authenticate() (token string, err error) {
|
||||
util.PrintVerbose("Getting auth token...")
|
||||
|
||||
reqBody := AuthenticateUserRequest{
|
||||
Username: n.user,
|
||||
Password: n.password,
|
||||
@ -197,15 +193,12 @@ func (n *portainerClientImp) Authenticate() (token string, err error) {
|
||||
|
||||
// Get endpoints
|
||||
func (n *portainerClientImp) GetEndpoints() (endpoints []EndpointSubset, err error) {
|
||||
util.PrintVerbose("Getting endpoints...")
|
||||
err = n.doJSON("endpoints", http.MethodGet, nil, &endpoints)
|
||||
return
|
||||
}
|
||||
|
||||
// Get stacks, optionally filtered by swarmId and endpointId
|
||||
func (n *portainerClientImp) GetStacks(swarmId string, endpointId uint32) (stacks []Stack, err error) {
|
||||
util.PrintVerbose("Getting stacks...")
|
||||
|
||||
filter := StackListFilter{
|
||||
SwarmId: swarmId,
|
||||
EndpointId: endpointId,
|
||||
@ -220,8 +213,6 @@ func (n *portainerClientImp) GetStacks(swarmId string, endpointId uint32) (stack
|
||||
|
||||
// Create swarm stack
|
||||
func (n *portainerClientImp) CreateSwarmStack(stackName string, environmentVariables []StackEnv, stackFileContent string, swarmClusterId string, endpointId string) (err error) {
|
||||
util.PrintVerbose("Deploying stack...")
|
||||
|
||||
reqBody := StackCreateRequest{
|
||||
Name: stackName,
|
||||
Env: environmentVariables,
|
||||
@ -235,8 +226,6 @@ func (n *portainerClientImp) CreateSwarmStack(stackName string, environmentVaria
|
||||
|
||||
// Create compose stack
|
||||
func (n *portainerClientImp) CreateComposeStack(stackName string, environmentVariables []StackEnv, stackFileContent string, endpointId string) (err error) {
|
||||
util.PrintVerbose("Deploying stack...")
|
||||
|
||||
reqBody := StackCreateRequest{
|
||||
Name: stackName,
|
||||
Env: environmentVariables,
|
||||
@ -249,8 +238,6 @@ func (n *portainerClientImp) CreateComposeStack(stackName string, environmentVar
|
||||
|
||||
// Update stack
|
||||
func (n *portainerClientImp) UpdateStack(stack Stack, environmentVariables []StackEnv, stackFileContent string, prune bool, endpointId string) (err error) {
|
||||
util.PrintVerbose("Updating stack...")
|
||||
|
||||
reqBody := StackUpdateRequest{
|
||||
Env: environmentVariables,
|
||||
StackFileContent: stackFileContent,
|
||||
@ -263,16 +250,12 @@ func (n *portainerClientImp) UpdateStack(stack Stack, environmentVariables []Sta
|
||||
|
||||
// Delete stack
|
||||
func (n *portainerClientImp) DeleteStack(stackId uint32) (err error) {
|
||||
util.PrintVerbose("Deleting stack...")
|
||||
|
||||
err = n.doJSON(fmt.Sprintf("stacks/%d", stackId), http.MethodDelete, nil, nil)
|
||||
return
|
||||
}
|
||||
|
||||
// Get stack file content
|
||||
func (n *portainerClientImp) GetStackFileContent(stackId uint32) (content string, err error) {
|
||||
util.PrintVerbose("Getting stack file content...")
|
||||
|
||||
var respBody StackFileInspectResponse
|
||||
|
||||
err = n.doJSON(fmt.Sprintf("stacks/%v/file", stackId), http.MethodGet, nil, &respBody)
|
||||
@ -287,8 +270,6 @@ func (n *portainerClientImp) GetStackFileContent(stackId uint32) (content string
|
||||
|
||||
// Get endpoint Docker info
|
||||
func (n *portainerClientImp) GetEndpointDockerInfo(endpointId string) (info map[string]interface{}, err error) {
|
||||
util.PrintVerbose("Getting endpoint Docker info...")
|
||||
|
||||
err = n.doJSON(fmt.Sprintf("endpoints/%v/docker/info", endpointId), http.MethodGet, nil, &info)
|
||||
return
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ var endpointListCmd = &cobra.Command{
|
||||
client, err := common.GetClient()
|
||||
common.CheckError(err)
|
||||
|
||||
util.PrintVerbose("Getting endpoints...")
|
||||
endpoints, err := client.GetEndpoints()
|
||||
common.CheckError(err)
|
||||
|
||||
|
@ -3,6 +3,8 @@ package cmd
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/greenled/portainer-stack-utils/util"
|
||||
|
||||
"github.com/greenled/portainer-stack-utils/common"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
@ -17,6 +19,7 @@ var loginCmd = &cobra.Command{
|
||||
client, err := common.GetDefaultClient()
|
||||
common.CheckError(err)
|
||||
|
||||
util.PrintVerbose("Getting auth token...")
|
||||
authToken, err := client.Authenticate()
|
||||
common.CheckError(err)
|
||||
|
||||
|
@ -47,6 +47,7 @@ var stackDeployCmd = &cobra.Command{
|
||||
common.CheckError(loadingErr)
|
||||
} else {
|
||||
var stackFileContentRetrievalErr error
|
||||
util.PrintVerbose("Getting stack file content...")
|
||||
stackFileContent, stackFileContentRetrievalErr = portainerClient.GetStackFileContent(retrievedStack.Id)
|
||||
common.CheckError(stackFileContentRetrievalErr)
|
||||
}
|
||||
@ -72,6 +73,7 @@ var stackDeployCmd = &cobra.Command{
|
||||
}
|
||||
}
|
||||
|
||||
util.PrintVerbose("Updating stack...")
|
||||
err := portainerClient.UpdateStack(retrievedStack, newEnvironmentVariables, stackFileContent, viper.GetBool("stack.deploy.prune"), viper.GetString("stack.deploy.endpoint"))
|
||||
common.CheckError(err)
|
||||
case *common.StackNotFoundError:
|
||||
@ -89,11 +91,13 @@ var stackDeployCmd = &cobra.Command{
|
||||
case nil:
|
||||
// It's a swarm cluster
|
||||
util.PrintVerbose(fmt.Sprintf("Swarm cluster found with id %s", swarmClusterId))
|
||||
util.PrintVerbose("Deploying stack...")
|
||||
deploymentErr := portainerClient.CreateSwarmStack(stackName, loadedEnvironmentVariables, stackFileContent, swarmClusterId, viper.GetString("stack.deploy.endpoint"))
|
||||
common.CheckError(deploymentErr)
|
||||
case *valueNotFoundError:
|
||||
// It's not a swarm cluster
|
||||
util.PrintVerbose("Swarm cluster not found")
|
||||
util.PrintVerbose("Deploying stack...")
|
||||
deploymentErr := portainerClient.CreateComposeStack(stackName, loadedEnvironmentVariables, stackFileContent, viper.GetString("stack.deploy.endpoint"))
|
||||
common.CheckError(deploymentErr)
|
||||
default:
|
||||
@ -129,6 +133,7 @@ func getSwarmClusterId() (id string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
util.PrintVerbose("Getting endpoint Docker info...")
|
||||
result, err := client.GetEndpointDockerInfo(viper.GetString("stack.deploy.endpoint"))
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -22,6 +22,7 @@ var stackListCmd = &cobra.Command{
|
||||
client, err := common.GetClient()
|
||||
common.CheckError(err)
|
||||
|
||||
util.PrintVerbose("Getting stacks...")
|
||||
stacks, err := client.GetStacks(viper.GetString("stack.list.swarm"), viper.GetUint32("stack.list.endpoint"))
|
||||
common.CheckError(err)
|
||||
|
||||
|
@ -34,6 +34,7 @@ var stackRemoveCmd = &cobra.Command{
|
||||
client, err := common.GetClient()
|
||||
common.CheckError(err)
|
||||
|
||||
util.PrintVerbose("Deleting stack...")
|
||||
err = client.DeleteStack(stackId)
|
||||
common.CheckError(err)
|
||||
case *common.StackNotFoundError:
|
||||
|
Loading…
x
Reference in New Issue
Block a user