mirror of
https://github.com/docker/compose.git
synced 2025-07-27 07:34:10 +02:00
cleanup
Signed-off-by: aiordache <anca.iordache@docker.com>
This commit is contained in:
parent
de0be8650e
commit
3066a1cdad
@ -18,6 +18,7 @@ package context
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -46,6 +47,9 @@ func createEcsCommand() *cobra.Command {
|
|||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
opts.Name = args[0]
|
opts.Name = args[0]
|
||||||
|
if opts.CredsFromEnv && opts.Profile != "" {
|
||||||
|
return fmt.Errorf("--profile and --from-env flags cannot be set at the same time")
|
||||||
|
}
|
||||||
if localSimulation {
|
if localSimulation {
|
||||||
return runCreateLocalSimulation(cmd.Context(), args[0], opts)
|
return runCreateLocalSimulation(cmd.Context(), args[0], opts)
|
||||||
}
|
}
|
||||||
|
@ -66,6 +66,53 @@ func newContextCreateHelper() contextCreateAWSHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h contextCreateAWSHelper) createContextData(_ context.Context, opts ContextParams) (interface{}, string, error) {
|
||||||
|
if opts.CredsFromEnv {
|
||||||
|
ecsCtx, descr := h.createContext(&opts)
|
||||||
|
return ecsCtx, descr, nil
|
||||||
|
}
|
||||||
|
if opts.Profile != "" {
|
||||||
|
// check profile exists
|
||||||
|
profilesList, err := getProfiles()
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
if !contains(profilesList, opts.Profile) {
|
||||||
|
return nil, "", fmt.Errorf("profile %q not found", opts.Profile)
|
||||||
|
}
|
||||||
|
ecsCtx, descr := h.createContext(&opts)
|
||||||
|
return ecsCtx, descr, nil
|
||||||
|
}
|
||||||
|
options := []string{
|
||||||
|
"An existing AWS profile",
|
||||||
|
"A new AWS profile",
|
||||||
|
"AWS environment variables",
|
||||||
|
}
|
||||||
|
|
||||||
|
selected, err := h.user.Select("Create a Docker context using:", options)
|
||||||
|
if err != nil {
|
||||||
|
if err == terminal.InterruptErr {
|
||||||
|
return nil, "", errdefs.ErrCanceled
|
||||||
|
}
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
switch selected {
|
||||||
|
case 0:
|
||||||
|
err = h.selectFromLocalProfile(&opts)
|
||||||
|
case 1:
|
||||||
|
err = h.createProfileFromCredentials(&opts)
|
||||||
|
case 2:
|
||||||
|
opts.CredsFromEnv = true
|
||||||
|
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
ecsCtx, descr := h.createContext(&opts)
|
||||||
|
return ecsCtx, descr, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (h contextCreateAWSHelper) createContext(c *ContextParams) (interface{}, string) {
|
func (h contextCreateAWSHelper) createContext(c *ContextParams) (interface{}, string) {
|
||||||
if c.Profile == "default" {
|
if c.Profile == "default" {
|
||||||
c.Profile = ""
|
c.Profile = ""
|
||||||
@ -134,41 +181,6 @@ func (h contextCreateAWSHelper) createProfileFromCredentials(opts *ContextParams
|
|||||||
return h.saveRegion(opts.Name, opts.Region)
|
return h.saveRegion(opts.Name, opts.Region)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h contextCreateAWSHelper) createContextData(_ context.Context, opts ContextParams) (interface{}, string, error) {
|
|
||||||
if opts.CredsFromEnv {
|
|
||||||
ecsCtx, descr := h.createContext(&opts)
|
|
||||||
return ecsCtx, descr, nil
|
|
||||||
}
|
|
||||||
options := []string{
|
|
||||||
"An existing AWS profile",
|
|
||||||
"A new AWS profile",
|
|
||||||
"AWS environment variables",
|
|
||||||
}
|
|
||||||
|
|
||||||
selected, err := h.user.Select("Create a Docker context using:", options)
|
|
||||||
if err != nil {
|
|
||||||
if err == terminal.InterruptErr {
|
|
||||||
return nil, "", errdefs.ErrCanceled
|
|
||||||
}
|
|
||||||
return nil, "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
switch selected {
|
|
||||||
case 0:
|
|
||||||
err = h.selectFromLocalProfile(&opts)
|
|
||||||
case 1:
|
|
||||||
err = h.createProfileFromCredentials(&opts)
|
|
||||||
case 2:
|
|
||||||
opts.CredsFromEnv = true
|
|
||||||
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return nil, "", err
|
|
||||||
}
|
|
||||||
ecsCtx, descr := h.createContext(&opts)
|
|
||||||
return ecsCtx, descr, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h contextCreateAWSHelper) saveCredentials(profile string, accessKeyID string, secretAccessKey string) error {
|
func (h contextCreateAWSHelper) saveCredentials(profile string, accessKeyID string, secretAccessKey string) error {
|
||||||
p := credentials.SharedCredentialsProvider{Profile: profile}
|
p := credentials.SharedCredentialsProvider{Profile: profile}
|
||||||
_, err := p.Retrieve()
|
_, err := p.Retrieve()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user