mirror of https://github.com/docker/compose.git
add secret interface
Signed-off-by: aiordache <anca.iordache@docker.com> Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
de365f41e9
commit
2ad9504d15
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/docker/cli/cli-plugins/manager"
|
||||
|
@ -45,6 +46,7 @@ func NewRootCmd(name string, dockerCli command.Cli) *cobra.Command {
|
|||
cmd.AddCommand(
|
||||
VersionCommand(),
|
||||
ComposeCommand(&opts),
|
||||
SecretCommand(&opts),
|
||||
)
|
||||
cmd.Flags().StringVarP(&opts.profile, "profile", "p", "default", "AWS Profile")
|
||||
cmd.Flags().StringVarP(&opts.cluster, "cluster", "c", "default", "ECS cluster")
|
||||
|
@ -164,3 +166,96 @@ func DownCommand(clusteropts *clusterOptions, projectOpts *compose.ProjectOption
|
|||
cmd.Flags().BoolVar(&opts.DeleteCluster, "delete-cluster", false, "Delete cluster")
|
||||
return cmd
|
||||
}
|
||||
|
||||
func SecretCommand(clusteropts *clusterOptions) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "secret",
|
||||
}
|
||||
opts := &compose.ProjectOptions{}
|
||||
opts.AddFlags(cmd.Flags())
|
||||
|
||||
cmd.AddCommand(
|
||||
CreateSecret(clusteropts),
|
||||
InspectSecret(clusteropts),
|
||||
ListSecrets(clusteropts),
|
||||
DeleteSecret(clusteropts),
|
||||
)
|
||||
return cmd
|
||||
}
|
||||
|
||||
type createSecretOptions struct {
|
||||
Label string
|
||||
}
|
||||
|
||||
func CreateSecret(clusteropts *clusterOptions) *cobra.Command {
|
||||
//opts := createSecretOptions{}
|
||||
cmd := &cobra.Command{
|
||||
Use: "create [NAME]",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
client, err := amazon.NewClient(clusteropts.profile, clusteropts.cluster, clusteropts.region)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(args) == 0 {
|
||||
return errors.New("Missing mandatory parameter: [NAME]")
|
||||
}
|
||||
name := args[0]
|
||||
content := "blabla"
|
||||
id, err := client.CreateSecret(context.Background(), name, content)
|
||||
fmt.Println(id)
|
||||
return err
|
||||
},
|
||||
}
|
||||
//cmd.Flags().BoolVar(&opts.Label, "label", false, "Secret label")
|
||||
return cmd
|
||||
}
|
||||
|
||||
func InspectSecret(clusteropts *clusterOptions) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "inspect [NAME]",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
client, err := amazon.NewClient(clusteropts.profile, clusteropts.cluster, clusteropts.region)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(args) == 0 {
|
||||
return errors.New("Missing mandatory parameter: [NAME]")
|
||||
}
|
||||
name := args[0]
|
||||
return client.InspectSecret(context.Background(), name)
|
||||
},
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
func ListSecrets(clusteropts *clusterOptions) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "list",
|
||||
Aliases: []string{"ls"},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
client, err := amazon.NewClient(clusteropts.profile, clusteropts.cluster, clusteropts.region)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return client.ListSecrets(context.Background())
|
||||
},
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
func DeleteSecret(clusteropts *clusterOptions) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "delete [NAME]",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
client, err := amazon.NewClient(clusteropts.profile, clusteropts.cluster, clusteropts.region)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(args) == 0 {
|
||||
return errors.New("Missing mandatory parameter: [NAME]")
|
||||
}
|
||||
return client.DeleteSecret(context.Background(), args[0])
|
||||
},
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
|
|
@ -6,4 +6,5 @@ type API interface {
|
|||
downAPI
|
||||
upAPI
|
||||
convertAPI
|
||||
secretsAPI
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ import (
|
|||
"github.com/aws/aws-sdk-go/service/elbv2/elbv2iface"
|
||||
"github.com/aws/aws-sdk-go/service/iam"
|
||||
"github.com/aws/aws-sdk-go/service/iam/iamiface"
|
||||
"github.com/aws/aws-sdk-go/service/secretsmanager"
|
||||
"github.com/aws/aws-sdk-go/service/secretsmanager/secretsmanageriface"
|
||||
cf "github.com/awslabs/goformation/v4/cloudformation"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
@ -30,6 +32,7 @@ type sdk struct {
|
|||
CW cloudwatchlogsiface.CloudWatchLogsAPI
|
||||
IAM iamiface.IAMAPI
|
||||
CF cloudformationiface.CloudFormationAPI
|
||||
SM secretsmanageriface.SecretsManagerAPI
|
||||
}
|
||||
|
||||
func NewAPI(sess *session.Session) API {
|
||||
|
@ -40,6 +43,7 @@ func NewAPI(sess *session.Session) API {
|
|||
CW: cloudwatchlogs.New(sess),
|
||||
IAM: iam.New(sess),
|
||||
CF: cloudformation.New(sess),
|
||||
SM: secretsmanager.New(sess),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -193,3 +197,23 @@ func (s sdk) DeleteStack(ctx context.Context, name string) error {
|
|||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (s sdk) CreateSecret(ctx context.Context, name string, content string) (string, error) {
|
||||
logrus.Debug("Create secret " + name)
|
||||
return "test", nil
|
||||
}
|
||||
|
||||
func (s sdk) InspectSecret(ctx context.Context, name string) error {
|
||||
fmt.Printf("... done. \n")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s sdk) ListSecrets(ctx context.Context) error {
|
||||
fmt.Printf("... done. \n")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s sdk) DeleteSecret(ctx context.Context, name string) error {
|
||||
fmt.Printf("... done. \n")
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package amazon
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type secretsAPI interface {
|
||||
CreateSecret(ctx context.Context, name string, content string) (string, error)
|
||||
InspectSecret(ctx context.Context, name string) error
|
||||
ListSecrets(ctx context.Context) error
|
||||
DeleteSecret(ctx context.Context, name string) error
|
||||
}
|
||||
|
||||
func (c client) CreateSecret(ctx context.Context, name string, content string) (string, error) {
|
||||
return c.api.CreateSecret(ctx, name, content)
|
||||
}
|
||||
|
||||
func (c client) InspectSecret(ctx context.Context, name string) error {
|
||||
return c.api.InspectSecret(ctx, name)
|
||||
}
|
||||
|
||||
func (c client) ListSecrets(ctx context.Context) error {
|
||||
return c.api.ListSecrets(ctx)
|
||||
}
|
||||
|
||||
func (c client) DeleteSecret(ctx context.Context, name string) error {
|
||||
return c.api.DeleteSecret(ctx, name)
|
||||
}
|
|
@ -10,4 +10,9 @@ type API interface {
|
|||
Convert(ctx context.Context, project *Project) (*cloudformation.Template, error)
|
||||
ComposeUp(ctx context.Context, project *Project) error
|
||||
ComposeDown(ctx context.Context, projectName string, deleteCluster bool) error
|
||||
|
||||
CreateSecret(ctx context.Context, name string, content string) (string, error)
|
||||
InspectSecret(ctx context.Context, name string) error
|
||||
ListSecrets(ctx context.Context) error
|
||||
DeleteSecret(ctx context.Context, name string) error
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue