mirror of
https://gitlab.com/psuapp/psu.git
synced 2024-08-30 18:12:34 +00:00
Rename some identifiers to pass go-lint
This commit is contained in:
parent
c6b7c2ce25
commit
be51da44bf
@ -14,12 +14,12 @@ import (
|
||||
)
|
||||
|
||||
type StackListFilter struct {
|
||||
SwarmId string `json:",omitempty"`
|
||||
EndpointId portainer.EndpointID `json:",omitempty"`
|
||||
SwarmID string `json:"SwarmId,omitempty"`
|
||||
EndpointID portainer.EndpointID `json:"EndpointId,omitempty"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Url *url.URL
|
||||
URL *url.URL
|
||||
User string
|
||||
Password string
|
||||
Token string
|
||||
@ -38,25 +38,25 @@ type PortainerClient interface {
|
||||
GetEndpointGroups() ([]portainer.EndpointGroup, error)
|
||||
|
||||
// Get stacks, optionally filtered by swarmId and endpointId
|
||||
GetStacks(swarmId string, endpointId portainer.EndpointID) ([]portainer.Stack, error)
|
||||
GetStacks(swarmID string, endpointID portainer.EndpointID) ([]portainer.Stack, error)
|
||||
|
||||
// Create swarm stack
|
||||
CreateSwarmStack(stackName string, environmentVariables []portainer.Pair, stackFileContent string, swarmClusterId string, endpointId portainer.EndpointID) (stack portainer.Stack, err error)
|
||||
CreateSwarmStack(stackName string, environmentVariables []portainer.Pair, stackFileContent string, swarmClusterID string, endpointID portainer.EndpointID) (stack portainer.Stack, err error)
|
||||
|
||||
// Create compose stack
|
||||
CreateComposeStack(stackName string, environmentVariables []portainer.Pair, stackFileContent string, endpointId portainer.EndpointID) (stack portainer.Stack, err error)
|
||||
CreateComposeStack(stackName string, environmentVariables []portainer.Pair, stackFileContent string, endpointID portainer.EndpointID) (stack portainer.Stack, err error)
|
||||
|
||||
// Update stack
|
||||
UpdateStack(stack portainer.Stack, environmentVariables []portainer.Pair, stackFileContent string, prune bool, endpointId portainer.EndpointID) error
|
||||
UpdateStack(stack portainer.Stack, environmentVariables []portainer.Pair, stackFileContent string, prune bool, endpointID portainer.EndpointID) error
|
||||
|
||||
// Delete stack
|
||||
DeleteStack(stackId portainer.StackID) error
|
||||
DeleteStack(stackID portainer.StackID) error
|
||||
|
||||
// Get stack file content
|
||||
GetStackFileContent(stackId portainer.StackID) (content string, err error)
|
||||
GetStackFileContent(stackID portainer.StackID) (content string, err error)
|
||||
|
||||
// Get endpoint Docker info
|
||||
GetEndpointDockerInfo(endpointId portainer.EndpointID) (info map[string]interface{}, err error)
|
||||
GetEndpointDockerInfo(endpointID portainer.EndpointID) (info map[string]interface{}, err error)
|
||||
|
||||
// Get Portainer status info
|
||||
GetStatus() (portainer.Status, error)
|
||||
@ -103,12 +103,12 @@ func checkResponseForErrors(resp *http.Response) error {
|
||||
|
||||
// Do an http request
|
||||
func (n *portainerClientImp) do(uri, method string, request io.Reader, requestType string, headers http.Header) (resp *http.Response, err error) {
|
||||
requestUrl, err := n.url.Parse(uri)
|
||||
requestURL, err := n.url.Parse(uri)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(method, requestUrl.String(), request)
|
||||
req, err := http.NewRequest(method, requestURL.String(), request)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -230,62 +230,62 @@ func (n *portainerClientImp) GetEndpointGroups() (endpointGroups []portainer.End
|
||||
return
|
||||
}
|
||||
|
||||
func (n *portainerClientImp) GetStacks(swarmId string, endpointId portainer.EndpointID) (stacks []portainer.Stack, err error) {
|
||||
func (n *portainerClientImp) GetStacks(swarmID string, endpointID portainer.EndpointID) (stacks []portainer.Stack, err error) {
|
||||
filter := StackListFilter{
|
||||
SwarmId: swarmId,
|
||||
EndpointId: endpointId,
|
||||
SwarmID: swarmID,
|
||||
EndpointID: endpointID,
|
||||
}
|
||||
|
||||
filterJsonBytes, _ := json.Marshal(filter)
|
||||
filterJsonString := string(filterJsonBytes)
|
||||
filterJSONBytes, _ := json.Marshal(filter)
|
||||
filterJSONString := string(filterJSONBytes)
|
||||
|
||||
err = n.doJSON(fmt.Sprintf("stacks?filters=%s", filterJsonString), http.MethodGet, nil, &stacks)
|
||||
err = n.doJSON(fmt.Sprintf("stacks?filters=%s", filterJSONString), http.MethodGet, nil, &stacks)
|
||||
return
|
||||
}
|
||||
|
||||
func (n *portainerClientImp) CreateSwarmStack(stackName string, environmentVariables []portainer.Pair, stackFileContent string, swarmClusterId string, endpointId portainer.EndpointID) (stack portainer.Stack, err error) {
|
||||
func (n *portainerClientImp) CreateSwarmStack(stackName string, environmentVariables []portainer.Pair, stackFileContent string, swarmClusterID string, endpointID portainer.EndpointID) (stack portainer.Stack, err error) {
|
||||
reqBody := StackCreateRequest{
|
||||
Name: stackName,
|
||||
Env: environmentVariables,
|
||||
SwarmID: swarmClusterId,
|
||||
SwarmID: swarmClusterID,
|
||||
StackFileContent: stackFileContent,
|
||||
}
|
||||
|
||||
err = n.doJSON(fmt.Sprintf("stacks?type=%v&method=%s&endpointId=%v", 1, "string", endpointId), http.MethodPost, &reqBody, &stack)
|
||||
err = n.doJSON(fmt.Sprintf("stacks?type=%v&method=%s&endpointId=%v", 1, "string", endpointID), http.MethodPost, &reqBody, &stack)
|
||||
return
|
||||
}
|
||||
|
||||
func (n *portainerClientImp) CreateComposeStack(stackName string, environmentVariables []portainer.Pair, stackFileContent string, endpointId portainer.EndpointID) (stack portainer.Stack, err error) {
|
||||
func (n *portainerClientImp) CreateComposeStack(stackName string, environmentVariables []portainer.Pair, stackFileContent string, endpointID portainer.EndpointID) (stack portainer.Stack, err error) {
|
||||
reqBody := StackCreateRequest{
|
||||
Name: stackName,
|
||||
Env: environmentVariables,
|
||||
StackFileContent: stackFileContent,
|
||||
}
|
||||
|
||||
err = n.doJSON(fmt.Sprintf("stacks?type=%v&method=%s&endpointId=%v", 2, "string", endpointId), http.MethodPost, &reqBody, &stack)
|
||||
err = n.doJSON(fmt.Sprintf("stacks?type=%v&method=%s&endpointId=%v", 2, "string", endpointID), http.MethodPost, &reqBody, &stack)
|
||||
return
|
||||
}
|
||||
|
||||
func (n *portainerClientImp) UpdateStack(stack portainer.Stack, environmentVariables []portainer.Pair, stackFileContent string, prune bool, endpointId portainer.EndpointID) (err error) {
|
||||
func (n *portainerClientImp) UpdateStack(stack portainer.Stack, environmentVariables []portainer.Pair, stackFileContent string, prune bool, endpointID portainer.EndpointID) (err error) {
|
||||
reqBody := StackUpdateRequest{
|
||||
Env: environmentVariables,
|
||||
StackFileContent: stackFileContent,
|
||||
Prune: prune,
|
||||
}
|
||||
|
||||
err = n.doJSON(fmt.Sprintf("stacks/%v?endpointId=%v", stack.ID, endpointId), http.MethodPut, &reqBody, nil)
|
||||
err = n.doJSON(fmt.Sprintf("stacks/%v?endpointId=%v", stack.ID, endpointID), http.MethodPut, &reqBody, nil)
|
||||
return
|
||||
}
|
||||
|
||||
func (n *portainerClientImp) DeleteStack(stackId portainer.StackID) (err error) {
|
||||
err = n.doJSON(fmt.Sprintf("stacks/%d", stackId), http.MethodDelete, nil, nil)
|
||||
func (n *portainerClientImp) DeleteStack(stackID portainer.StackID) (err error) {
|
||||
err = n.doJSON(fmt.Sprintf("stacks/%d", stackID), http.MethodDelete, nil, nil)
|
||||
return
|
||||
}
|
||||
|
||||
func (n *portainerClientImp) GetStackFileContent(stackId portainer.StackID) (content string, err error) {
|
||||
func (n *portainerClientImp) GetStackFileContent(stackID portainer.StackID) (content string, err error) {
|
||||
var respBody StackFileInspectResponse
|
||||
|
||||
err = n.doJSON(fmt.Sprintf("stacks/%v/file", stackId), http.MethodGet, nil, &respBody)
|
||||
err = n.doJSON(fmt.Sprintf("stacks/%v/file", stackID), http.MethodGet, nil, &respBody)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -295,8 +295,8 @@ func (n *portainerClientImp) GetStackFileContent(stackId portainer.StackID) (con
|
||||
return
|
||||
}
|
||||
|
||||
func (n *portainerClientImp) GetEndpointDockerInfo(endpointId portainer.EndpointID) (info map[string]interface{}, err error) {
|
||||
err = n.doJSON(fmt.Sprintf("endpoints/%v/docker/info", endpointId), http.MethodGet, nil, &info)
|
||||
func (n *portainerClientImp) GetEndpointDockerInfo(endpointID portainer.EndpointID) (info map[string]interface{}, err error) {
|
||||
err = n.doJSON(fmt.Sprintf("endpoints/%v/docker/info", endpointID), http.MethodGet, nil, &info)
|
||||
return
|
||||
}
|
||||
|
||||
@ -309,7 +309,7 @@ func (n *portainerClientImp) GetStatus() (status portainer.Status, err error) {
|
||||
func NewClient(httpClient *http.Client, config Config) PortainerClient {
|
||||
return &portainerClientImp{
|
||||
httpClient: httpClient,
|
||||
url: config.Url,
|
||||
url: config.URL,
|
||||
user: config.User,
|
||||
password: config.Password,
|
||||
token: config.Token,
|
||||
|
@ -12,24 +12,24 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func readRequestBodyAsJson(req *http.Request, body *map[string]interface{}) (err error) {
|
||||
func readRequestBodyAsJSON(req *http.Request, body *map[string]interface{}) (err error) {
|
||||
bodyBytes, err := ioutil.ReadAll(req.Body)
|
||||
defer req.Body.Close()
|
||||
err = json.Unmarshal(bodyBytes, body)
|
||||
return
|
||||
}
|
||||
|
||||
func writeResponseBodyAsJson(w http.ResponseWriter, body map[string]interface{}) (err error) {
|
||||
func writeResponseBodyAsJSON(w http.ResponseWriter, body map[string]interface{}) (err error) {
|
||||
bodyBytes, err := json.Marshal(body)
|
||||
fmt.Fprintln(w, string(bodyBytes))
|
||||
return
|
||||
}
|
||||
|
||||
func TestNewClient(t *testing.T) {
|
||||
apiUrl, _ := url.Parse("http://validurl.com/api")
|
||||
apiURL, _ := url.Parse("http://validurl.com/api")
|
||||
|
||||
validClient := NewClient(http.DefaultClient, Config{
|
||||
Url: apiUrl,
|
||||
URL: apiURL,
|
||||
})
|
||||
assert.NotNil(t, validClient)
|
||||
}
|
||||
@ -37,7 +37,7 @@ func TestNewClient(t *testing.T) {
|
||||
func TestClientAuthenticates(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
var body map[string]interface{}
|
||||
err := readRequestBodyAsJson(req, &body)
|
||||
err := readRequestBodyAsJSON(req, &body)
|
||||
|
||||
assert.Equal(t, req.Method, http.MethodPost)
|
||||
assert.Equal(t, req.RequestURI, "/api/auth")
|
||||
@ -53,16 +53,16 @@ func TestClientAuthenticates(t *testing.T) {
|
||||
assert.NotNil(t, body["Password"])
|
||||
assert.Equal(t, body["Password"], "a")
|
||||
|
||||
writeResponseBodyAsJson(w, map[string]interface{}{
|
||||
writeResponseBodyAsJSON(w, map[string]interface{}{
|
||||
"jwt": "somerandomtoken",
|
||||
})
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
apiUrl, _ := url.Parse(ts.URL + "/api/")
|
||||
apiURL, _ := url.Parse(ts.URL + "/api/")
|
||||
|
||||
customClient := NewClient(ts.Client(), Config{
|
||||
Url: apiUrl,
|
||||
URL: apiURL,
|
||||
User: "admin",
|
||||
Password: "a",
|
||||
UserAgent: "GE007",
|
||||
|
@ -77,9 +77,9 @@ var configListCmd = &cobra.Command{
|
||||
common.CheckError(flushErr)
|
||||
case "json":
|
||||
// Print configs in a json format
|
||||
statusJsonBytes, err := json.Marshal(configs)
|
||||
statusJSONBytes, err := json.Marshal(configs)
|
||||
common.CheckError(err)
|
||||
fmt.Println(string(statusJsonBytes))
|
||||
fmt.Println(string(statusJSONBytes))
|
||||
default:
|
||||
// Print configs in a custom format
|
||||
template, templateParsingErr := template.New("configTpl").Parse(viper.GetString("config.list.format"))
|
||||
|
@ -44,9 +44,9 @@ var endpointGroupInspectCmd = &cobra.Command{
|
||||
common.CheckError(err)
|
||||
case "json":
|
||||
// Print endpoint group in a json format
|
||||
endpointJsonBytes, err := json.Marshal(endpointGroup)
|
||||
endpointJSONBytes, err := json.Marshal(endpointGroup)
|
||||
common.CheckError(err)
|
||||
fmt.Println(string(endpointJsonBytes))
|
||||
fmt.Println(string(endpointJSONBytes))
|
||||
default:
|
||||
// Print endpoint group in a custom format
|
||||
template, err := template.New("endpointGroupTpl").Parse(viper.GetString("endpoint.group.inspect.format"))
|
||||
|
@ -55,9 +55,9 @@ var endpointGroupListCmd = &cobra.Command{
|
||||
common.CheckError(flushErr)
|
||||
case "json":
|
||||
// Print endpoint groups in a json format
|
||||
statusJsonBytes, err := json.Marshal(endpointGroups)
|
||||
statusJSONBytes, err := json.Marshal(endpointGroups)
|
||||
common.CheckError(err)
|
||||
fmt.Println(string(statusJsonBytes))
|
||||
fmt.Println(string(statusJSONBytes))
|
||||
default:
|
||||
// Print endpoint groups in a custom format
|
||||
template, templateParsingErr := template.New("endpointGroupTpl").Parse(viper.GetString("endpoint.group.list.format"))
|
||||
|
@ -74,9 +74,9 @@ var endpointInspectCmd = &cobra.Command{
|
||||
common.CheckError(err)
|
||||
case "json":
|
||||
// Print endpoint in a json format
|
||||
endpointJsonBytes, err := json.Marshal(endpoint)
|
||||
endpointJSONBytes, err := json.Marshal(endpoint)
|
||||
common.CheckError(err)
|
||||
fmt.Println(string(endpointJsonBytes))
|
||||
fmt.Println(string(endpointJSONBytes))
|
||||
default:
|
||||
// Print endpoint in a custom format
|
||||
template, err := template.New("endpointTpl").Parse(viper.GetString("endpoint.inspect.format"))
|
||||
|
@ -71,9 +71,9 @@ var endpointListCmd = &cobra.Command{
|
||||
common.CheckError(flushErr)
|
||||
case "json":
|
||||
// Print endpoints in a json format
|
||||
statusJsonBytes, err := json.Marshal(endpoints)
|
||||
statusJSONBytes, err := json.Marshal(endpoints)
|
||||
common.CheckError(err)
|
||||
fmt.Println(string(statusJsonBytes))
|
||||
fmt.Println(string(statusJSONBytes))
|
||||
default:
|
||||
// Print endpoints in a custom format
|
||||
template, templateParsingErr := template.New("endpointTpl").Parse(viper.GetString("endpoint.list.format"))
|
||||
|
@ -56,7 +56,7 @@ var stackDeployCmd = &cobra.Command{
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"endpoint": endpoint.Name,
|
||||
}).Debug("Getting endpoint's Docker info")
|
||||
endpointSwarmClusterId, selectionErr := common.GetEndpointSwarmClusterId(endpoint.ID)
|
||||
endpointSwarmClusterID, selectionErr := common.GetEndpointSwarmClusterID(endpoint.ID)
|
||||
if selectionErr == nil {
|
||||
// It's a swarm cluster
|
||||
} else if selectionErr == common.ErrStackClusterNotFound {
|
||||
@ -70,7 +70,7 @@ var stackDeployCmd = &cobra.Command{
|
||||
"stack": stackName,
|
||||
"endpoint": endpoint.Name,
|
||||
}).Debug("Getting stack")
|
||||
retrievedStack, stackRetrievalErr := common.GetStackByName(stackName, endpointSwarmClusterId, endpoint.ID)
|
||||
retrievedStack, stackRetrievalErr := common.GetStackByName(stackName, endpointSwarmClusterID, endpoint.ID)
|
||||
if stackRetrievalErr == nil {
|
||||
// We are updating an existing stack
|
||||
logrus.WithFields(logrus.Fields{
|
||||
@ -129,13 +129,13 @@ var stackDeployCmd = &cobra.Command{
|
||||
stackFileContent, loadingErr := loadStackFile(viper.GetString("stack.deploy.stack-file"))
|
||||
common.CheckError(loadingErr)
|
||||
|
||||
if endpointSwarmClusterId != "" {
|
||||
if endpointSwarmClusterID != "" {
|
||||
// It's a swarm cluster
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"stack": stackName,
|
||||
"endpoint": endpoint.Name,
|
||||
}).Info("Creating stack")
|
||||
stack, deploymentErr := portainerClient.CreateSwarmStack(stackName, loadedEnvironmentVariables, stackFileContent, endpointSwarmClusterId, endpoint.ID)
|
||||
stack, deploymentErr := portainerClient.CreateSwarmStack(stackName, loadedEnvironmentVariables, stackFileContent, endpointSwarmClusterID, endpoint.ID)
|
||||
common.CheckError(deploymentErr)
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"stack": stack.Name,
|
||||
|
@ -24,7 +24,7 @@ var stackInspectCmd = &cobra.Command{
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
stackName := args[0]
|
||||
var endpointSwarmClusterId string
|
||||
var endpointSwarmClusterID string
|
||||
var stack portainer.Stack
|
||||
|
||||
var endpoint portainer.Endpoint
|
||||
@ -51,14 +51,14 @@ var stackInspectCmd = &cobra.Command{
|
||||
"endpoint": endpoint.Name,
|
||||
}).Debug("Getting endpoint's Docker info")
|
||||
var selectionErr, stackRetrievalErr error
|
||||
endpointSwarmClusterId, selectionErr = common.GetEndpointSwarmClusterId(endpoint.ID)
|
||||
endpointSwarmClusterID, selectionErr = common.GetEndpointSwarmClusterID(endpoint.ID)
|
||||
if selectionErr == nil {
|
||||
// It's a swarm cluster
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"stack": stackName,
|
||||
"endpoint": endpoint.Name,
|
||||
}).Debug("Getting stack")
|
||||
stack, stackRetrievalErr = common.GetStackByName(stackName, endpointSwarmClusterId, endpoint.ID)
|
||||
stack, stackRetrievalErr = common.GetStackByName(stackName, endpointSwarmClusterID, endpoint.ID)
|
||||
} else if selectionErr == common.ErrStackClusterNotFound {
|
||||
// It's not a swarm cluster
|
||||
logrus.WithFields(logrus.Fields{
|
||||
@ -95,9 +95,9 @@ var stackInspectCmd = &cobra.Command{
|
||||
common.CheckError(flushErr)
|
||||
case "json":
|
||||
// Print stack in a json format
|
||||
stackJsonBytes, err := json.Marshal(stack)
|
||||
stackJSONBytes, err := json.Marshal(stack)
|
||||
common.CheckError(err)
|
||||
fmt.Println(string(stackJsonBytes))
|
||||
fmt.Println(string(stackJSONBytes))
|
||||
default:
|
||||
// Print stack in a custom format
|
||||
template, templateParsingErr := template.New("stackTpl").Parse(viper.GetString("stack.inspect.format"))
|
||||
|
@ -36,7 +36,7 @@ var stackListCmd = &cobra.Command{
|
||||
endpoints, endpointsRetrievalErr := portainerClient.GetEndpoints()
|
||||
common.CheckError(endpointsRetrievalErr)
|
||||
|
||||
var endpointSwarmClusterId string
|
||||
var endpointSwarmClusterID string
|
||||
var stacks []portainer.Stack
|
||||
if endpointName := viper.GetString("stack.list.endpoint"); endpointName != "" {
|
||||
// Get endpoint by name
|
||||
@ -47,13 +47,13 @@ var stackListCmd = &cobra.Command{
|
||||
"endpoint": endpoint.Name,
|
||||
}).Debug("Getting endpoint's Docker info")
|
||||
var selectionErr error
|
||||
endpointSwarmClusterId, selectionErr = common.GetEndpointSwarmClusterId(endpoint.ID)
|
||||
endpointSwarmClusterID, selectionErr = common.GetEndpointSwarmClusterID(endpoint.ID)
|
||||
if selectionErr == nil {
|
||||
// It's a swarm cluster
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"endpoint": endpoint.Name,
|
||||
}).Debug("Getting stacks")
|
||||
stacks, err = portainerClient.GetStacks(endpointSwarmClusterId, endpoint.ID)
|
||||
stacks, err = portainerClient.GetStacks(endpointSwarmClusterID, endpoint.ID)
|
||||
common.CheckError(err)
|
||||
} else if selectionErr == common.ErrStackClusterNotFound {
|
||||
// It's not a swarm cluster
|
||||
@ -83,7 +83,7 @@ var stackListCmd = &cobra.Command{
|
||||
})
|
||||
common.CheckError(err)
|
||||
for _, s := range stacks {
|
||||
stackEndpoint, err := common.GetEndpointFromListById(endpoints, s.EndpointID)
|
||||
stackEndpoint, err := common.GetEndpointFromListByID(endpoints, s.EndpointID)
|
||||
common.CheckError(err)
|
||||
_, err = fmt.Fprintln(writer, fmt.Sprintf(
|
||||
"%v\t%s\t%v\t%s",
|
||||
@ -98,9 +98,9 @@ var stackListCmd = &cobra.Command{
|
||||
common.CheckError(flushErr)
|
||||
case "json":
|
||||
// Print stacks in a json format
|
||||
stacksJsonBytes, err := json.Marshal(stacks)
|
||||
stacksJSONBytes, err := json.Marshal(stacks)
|
||||
common.CheckError(err)
|
||||
fmt.Println(string(stacksJsonBytes))
|
||||
fmt.Println(string(stacksJSONBytes))
|
||||
default:
|
||||
// Print stacks in a custom format
|
||||
template, templateParsingErr := template.New("stackTpl").Parse(viper.GetString("stack.list.format"))
|
||||
|
@ -22,7 +22,7 @@ var stackRemoveCmd = &cobra.Command{
|
||||
common.CheckError(clientRetrievalErr)
|
||||
|
||||
stackName := args[0]
|
||||
var endpointSwarmClusterId string
|
||||
var endpointSwarmClusterID string
|
||||
var stack portainer.Stack
|
||||
|
||||
var endpoint portainer.Endpoint
|
||||
@ -49,14 +49,14 @@ var stackRemoveCmd = &cobra.Command{
|
||||
"endpoint": endpoint.Name,
|
||||
}).Debug("Getting endpoint's Docker info")
|
||||
var selectionErr, stackRetrievalErr error
|
||||
endpointSwarmClusterId, selectionErr = common.GetEndpointSwarmClusterId(endpoint.ID)
|
||||
endpointSwarmClusterID, selectionErr = common.GetEndpointSwarmClusterID(endpoint.ID)
|
||||
if selectionErr == nil {
|
||||
// It's a swarm cluster
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"stack": stackName,
|
||||
"endpoint": endpoint.Name,
|
||||
}).Debug("Getting stack")
|
||||
stack, stackRetrievalErr = common.GetStackByName(stackName, endpointSwarmClusterId, endpoint.ID)
|
||||
stack, stackRetrievalErr = common.GetStackByName(stackName, endpointSwarmClusterID, endpoint.ID)
|
||||
} else if selectionErr == common.ErrStackClusterNotFound {
|
||||
// It's not a swarm cluster
|
||||
logrus.WithFields(logrus.Fields{
|
||||
@ -71,13 +71,13 @@ var stackRemoveCmd = &cobra.Command{
|
||||
|
||||
if stackRetrievalErr == nil {
|
||||
// The stack exists
|
||||
stackId := stack.ID
|
||||
stackID := stack.ID
|
||||
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"stack": stackName,
|
||||
"endpoint": endpoint.Name,
|
||||
}).Info("Removing stack")
|
||||
err := portainerClient.DeleteStack(stackId)
|
||||
err := portainerClient.DeleteStack(stackID)
|
||||
common.CheckError(err)
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"stack": stack.Name,
|
||||
|
@ -53,9 +53,9 @@ var statusCmd = &cobra.Command{
|
||||
common.CheckError(flushErr)
|
||||
case "json":
|
||||
// Print status in a json format
|
||||
statusJsonBytes, err := json.Marshal(respBody)
|
||||
statusJSONBytes, err := json.Marshal(respBody)
|
||||
common.CheckError(err)
|
||||
fmt.Println(string(statusJsonBytes))
|
||||
fmt.Println(string(statusJSONBytes))
|
||||
default:
|
||||
// Print status in a custom format
|
||||
template, templateParsingErr := template.New("statusTpl").Parse(viper.GetString("status.format"))
|
||||
|
@ -36,7 +36,7 @@ func GetDefaultClient() (c client.PortainerClient, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
c = client.NewClient(GetDefaultHttpClient(), config)
|
||||
c = client.NewClient(GetDefaultHTTPClient(), config)
|
||||
|
||||
c.BeforeRequest(func(req *http.Request) (err error) {
|
||||
var bodyString string
|
||||
@ -84,13 +84,13 @@ func GetDefaultClient() (c client.PortainerClient, err error) {
|
||||
|
||||
// Get the default config for a client
|
||||
func GetDefaultClientConfig() (config client.Config, err error) {
|
||||
apiUrl, err := url.Parse(strings.TrimRight(viper.GetString("url"), "/") + "/api/")
|
||||
apiURL, err := url.Parse(strings.TrimRight(viper.GetString("url"), "/") + "/api/")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
config = client.Config{
|
||||
Url: apiUrl,
|
||||
URL: apiURL,
|
||||
User: viper.GetString("user"),
|
||||
Password: viper.GetString("password"),
|
||||
Token: viper.GetString("auth-token"),
|
||||
@ -102,7 +102,7 @@ func GetDefaultClientConfig() (config client.Config, err error) {
|
||||
}
|
||||
|
||||
// Get the default http client for a Portainer client
|
||||
func GetDefaultHttpClient() *http.Client {
|
||||
func GetDefaultHTTPClient() *http.Client {
|
||||
return &http.Client{
|
||||
Timeout: viper.GetDuration("timeout"),
|
||||
Transport: &http.Transport{
|
||||
|
@ -53,13 +53,13 @@ func GetDefaultEndpoint() (endpoint portainer.Endpoint, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func GetStackByName(name string, swarmId string, endpointId portainer.EndpointID) (stack portainer.Stack, err error) {
|
||||
func GetStackByName(name string, swarmID string, endpointID portainer.EndpointID) (stack portainer.Stack, err error) {
|
||||
portainerClient, err := GetClient()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
stacks, err := portainerClient.GetStacks(swarmId, endpointId)
|
||||
stacks, err := portainerClient.GetStacks(swarmID, endpointID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -113,7 +113,7 @@ func GetEndpointGroupByName(name string) (endpointGroup portainer.EndpointGroup,
|
||||
return
|
||||
}
|
||||
|
||||
func GetEndpointFromListById(endpoints []portainer.Endpoint, id portainer.EndpointID) (endpoint portainer.Endpoint, err error) {
|
||||
func GetEndpointFromListByID(endpoints []portainer.Endpoint, id portainer.EndpointID) (endpoint portainer.Endpoint, err error) {
|
||||
for i := range endpoints {
|
||||
if endpoints[i].ID == id {
|
||||
return endpoints[i], err
|
||||
@ -131,14 +131,14 @@ func GetEndpointFromListByName(endpoints []portainer.Endpoint, name string) (end
|
||||
return endpoint, ErrEndpointNotFound
|
||||
}
|
||||
|
||||
func GetEndpointSwarmClusterId(endpointId portainer.EndpointID) (endpointSwarmClusterId string, err error) {
|
||||
func GetEndpointSwarmClusterID(endpointID portainer.EndpointID) (endpointSwarmClusterID string, err error) {
|
||||
// Get docker information for endpoint
|
||||
portainerClient, err := GetClient()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
result, err := portainerClient.GetEndpointDockerInfo(endpointId)
|
||||
result, err := portainerClient.GetEndpointDockerInfo(endpointID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -146,7 +146,7 @@ func GetEndpointSwarmClusterId(endpointId portainer.EndpointID) (endpointSwarmCl
|
||||
// Get swarm (if any) information for endpoint
|
||||
id, selectionErr := selectValue(result, []string{"Swarm", "Cluster", "ID"})
|
||||
if selectionErr == nil {
|
||||
endpointSwarmClusterId = id.(string)
|
||||
endpointSwarmClusterID = id.(string)
|
||||
} else if selectionErr == valueNotFoundError {
|
||||
err = ErrStackClusterNotFound
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user