mirror of
https://gitlab.com/psuapp/psu.git
synced 2024-08-30 18:12:34 +00:00
Add options object for PortainerClient.StackList()
This commit is contained in:
parent
f38481b008
commit
26a3efdd3a
@ -19,6 +19,11 @@ type StackListFilter struct {
|
||||
EndpointID portainer.EndpointID `json:"EndpointId,omitempty"`
|
||||
}
|
||||
|
||||
// StackListOptions represents options passed to PortainerClient.StackList()
|
||||
type StackListOptions struct {
|
||||
Filter StackListFilter
|
||||
}
|
||||
|
||||
// Config represents a Portainer client configuration
|
||||
type Config struct {
|
||||
URL *url.URL
|
||||
@ -41,7 +46,7 @@ type PortainerClient interface {
|
||||
EndpointGroupList() ([]portainer.EndpointGroup, error)
|
||||
|
||||
// Get stacks, optionally filtered by swarmId and endpointId
|
||||
StackList(swarmID string, endpointID portainer.EndpointID) ([]portainer.Stack, error)
|
||||
StackList(options StackListOptions) ([]portainer.Stack, error)
|
||||
|
||||
// Create swarm stack
|
||||
StackCreateSwarm(stackName string, environmentVariables []portainer.Pair, stackFileContent string, swarmClusterID string, endpointID portainer.EndpointID) (stack portainer.Stack, err error)
|
||||
@ -231,13 +236,8 @@ func (n *portainerClientImp) EndpointGroupList() (endpointGroups []portainer.End
|
||||
return
|
||||
}
|
||||
|
||||
func (n *portainerClientImp) StackList(swarmID string, endpointID portainer.EndpointID) (stacks []portainer.Stack, err error) {
|
||||
filter := StackListFilter{
|
||||
SwarmID: swarmID,
|
||||
EndpointID: endpointID,
|
||||
}
|
||||
|
||||
filterJSONBytes, _ := json.Marshal(filter)
|
||||
func (n *portainerClientImp) StackList(options StackListOptions) (stacks []portainer.Stack, err error) {
|
||||
filterJSONBytes, _ := json.Marshal(options.Filter)
|
||||
filterJSONString := string(filterJSONBytes)
|
||||
|
||||
err = n.doJSONWithToken(fmt.Sprintf("stacks?filters=%s", filterJSONString), http.MethodGet, http.Header{}, nil, &stacks)
|
||||
|
@ -53,14 +53,23 @@ var stackListCmd = &cobra.Command{
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"endpoint": endpoint.Name,
|
||||
}).Debug("Getting stacks")
|
||||
stacks, err = portainerClient.StackList(endpointSwarmClusterID, endpoint.ID)
|
||||
stacks, err = portainerClient.StackList(client.StackListOptions{
|
||||
Filter: client.StackListFilter{
|
||||
SwarmID: endpointSwarmClusterID,
|
||||
EndpointID: endpoint.ID,
|
||||
},
|
||||
})
|
||||
common.CheckError(err)
|
||||
} else if selectionErr == common.ErrStackClusterNotFound {
|
||||
// It's not a swarm cluster
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"endpoint": endpoint.Name,
|
||||
}).Debug("Getting stacks")
|
||||
stacks, err = portainerClient.StackList("", endpoint.ID)
|
||||
stacks, err = portainerClient.StackList(client.StackListOptions{
|
||||
Filter: client.StackListFilter{
|
||||
EndpointID: endpoint.ID,
|
||||
},
|
||||
})
|
||||
common.CheckError(err)
|
||||
} else {
|
||||
// Something else happened
|
||||
@ -68,7 +77,7 @@ var stackListCmd = &cobra.Command{
|
||||
}
|
||||
} else {
|
||||
logrus.Debug("Getting stacks")
|
||||
stacks, err = portainerClient.StackList("", 0)
|
||||
stacks, err = portainerClient.StackList(client.StackListOptions{})
|
||||
common.CheckError(err)
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,8 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/greenled/portainer-stack-utils/client"
|
||||
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
@ -63,7 +65,12 @@ func GetStackByName(name string, swarmID string, endpointID portainer.EndpointID
|
||||
return
|
||||
}
|
||||
|
||||
stacks, err := portainerClient.StackList(swarmID, endpointID)
|
||||
stacks, err := portainerClient.StackList(client.StackListOptions{
|
||||
Filter: client.StackListFilter{
|
||||
SwarmID: swarmID,
|
||||
EndpointID: endpointID,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user