50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strings"
|
|
|
|
"coopcloud.tech/abra/pkg/i18n"
|
|
"github.com/docker/docker/api/types/filters"
|
|
"github.com/docker/docker/api/types/swarm"
|
|
"github.com/docker/docker/client"
|
|
)
|
|
|
|
func GetConfigs(cl *client.Client, ctx context.Context, server string, fs filters.Args) ([]swarm.Config, error) {
|
|
configList, err := cl.ConfigList(ctx, swarm.ConfigListOptions{Filters: fs})
|
|
if err != nil {
|
|
return configList, err
|
|
}
|
|
|
|
return configList, nil
|
|
}
|
|
|
|
func GetConfigNames(configs []swarm.Config) []string {
|
|
var confNames []string
|
|
|
|
for _, conf := range configs {
|
|
confNames = append(confNames, conf.Spec.Name)
|
|
}
|
|
|
|
return confNames
|
|
}
|
|
|
|
func RemoveConfigs(cl *client.Client, ctx context.Context, configNames []string, force bool) error {
|
|
for _, confName := range configNames {
|
|
if err := cl.ConfigRemove(context.Background(), confName); err != nil {
|
|
return errors.New(i18n.G("conf %s: %s", confName, err))
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func GetConfigNameAndVersion(fullName string, stackName string) (string, string, error) {
|
|
name := strings.TrimPrefix(fullName, stackName+"_")
|
|
if lastUnderscore := strings.LastIndex(name, "_"); lastUnderscore != -1 {
|
|
return name[0:lastUnderscore], name[lastUnderscore+1:], nil
|
|
} else {
|
|
return "", "", errors.New(i18n.G("can't parse version from config '%s'", fullName))
|
|
}
|
|
}
|