psu/common/utils.go

42 lines
722 B
Go
Raw Normal View History

2019-07-21 02:00:04 +00:00
package common
import (
"fmt"
"github.com/greenled/portainer-stack-utils/util"
"github.com/greenled/portainer-stack-utils/client"
2019-07-21 02:00:04 +00:00
)
func GetStackByName(name string) (stack client.Stack, err error) {
client, err := GetClient()
2019-07-21 02:00:04 +00:00
if err != nil {
return
2019-07-21 02:00:04 +00:00
}
stacks, err := client.GetStacks("", 0)
2019-07-21 02:00:04 +00:00
if err != nil {
return
2019-07-21 02:00:04 +00:00
}
util.PrintVerbose(fmt.Sprintf("Getting stack %s...", name))
2019-07-21 02:00:04 +00:00
for _, stack := range stacks {
if stack.Name == name {
return stack, nil
}
}
err = &StackNotFoundError{
2019-07-21 02:00:04 +00:00
StackName: name,
}
return
2019-07-21 02:00:04 +00:00
}
// Custom customerrors
type StackNotFoundError struct {
StackName string
}
func (e *StackNotFoundError) Error() string {
return fmt.Sprintf("Stack %s not found", e.StackName)
}