mirror of
https://github.com/docker/compose.git
synced 2025-07-25 22:54:54 +02:00
fix lint issues
Signed-off-by: aiordache <anca.iordache@docker.com>
This commit is contained in:
parent
2fdc93786e
commit
879afa85c0
@ -49,7 +49,7 @@ type ContextParams struct {
|
|||||||
CredsFromEnv bool
|
CredsFromEnv bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c ContextParams) HaveRequiredCredentials() bool {
|
func (c ContextParams) haveRequiredCredentials() bool {
|
||||||
if c.AccessKey == "" || c.SecretKey == "" {
|
if c.AccessKey == "" || c.SecretKey == "" {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -81,8 +81,8 @@ func getEcsAPIService(ecsCtx store.EcsContext) (*ecsAPIService, error) {
|
|||||||
|
|
||||||
if ecsCtx.CredentialsFromEnv {
|
if ecsCtx.CredentialsFromEnv {
|
||||||
creds := getEnvVars()
|
creds := getEnvVars()
|
||||||
if !creds.HaveRequiredCredentials() {
|
if !creds.haveRequiredCredentials() {
|
||||||
return nil, fmt.Errorf(`context requires credentials to be passed as environment variable.`)
|
return nil, fmt.Errorf(`context requires credentials to be passed as environment variable`)
|
||||||
}
|
}
|
||||||
region = creds.Region
|
region = creds.Region
|
||||||
profile = creds.Profile
|
profile = creds.Profile
|
||||||
|
@ -125,6 +125,56 @@ func (h contextCreateAWSHelper) createContext(c *ContextParams) (interface{}, st
|
|||||||
}, description
|
}, description
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h contextCreateAWSHelper) selectFromLocalProfile(opts *ContextParams) error {
|
||||||
|
profilesList, err := getProfiles()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// choose profile
|
||||||
|
opts.Profile, err = h.chooseProfile(profilesList)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if opts.Region == "" {
|
||||||
|
region, isDefinedInProfile, err := getRegion(opts.Profile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if isDefinedInProfile {
|
||||||
|
opts.Region = region
|
||||||
|
} else {
|
||||||
|
fmt.Println("No region defined in the profile. Choose the region to use.")
|
||||||
|
opts.Region, err = h.chooseRegion(opts.Region, opts.Profile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h contextCreateAWSHelper) createProfileFromCredentials(opts *ContextParams) error {
|
||||||
|
accessKey, secretKey, err := h.askCredentials()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
opts.AccessKey = accessKey
|
||||||
|
opts.SecretKey = secretKey
|
||||||
|
// we need a region set -- either read it from profile or prompt user
|
||||||
|
// prompt for the region to use with this context
|
||||||
|
opts.Region, err = h.chooseRegion(opts.Region, opts.Profile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// save as a profile
|
||||||
|
if opts.Profile == "" {
|
||||||
|
opts.Profile = opts.Name
|
||||||
|
}
|
||||||
|
fmt.Printf("Saving credentials under profile %s\n", opts.Profile)
|
||||||
|
return h.createProfile(opts.Profile, opts)
|
||||||
|
}
|
||||||
|
|
||||||
func (h contextCreateAWSHelper) createContextData(_ context.Context, opts ContextParams) (interface{}, string, error) {
|
func (h contextCreateAWSHelper) createContextData(_ context.Context, opts ContextParams) (interface{}, string, error) {
|
||||||
if opts.CredsFromEnv {
|
if opts.CredsFromEnv {
|
||||||
ecsCtx, descr := h.createContext(&opts)
|
ecsCtx, descr := h.createContext(&opts)
|
||||||
@ -147,51 +197,15 @@ func (h contextCreateAWSHelper) createContextData(_ context.Context, opts Contex
|
|||||||
switch selected {
|
switch selected {
|
||||||
case 0:
|
case 0:
|
||||||
opts.CredsFromEnv = true
|
opts.CredsFromEnv = true
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
profilesList, err := getProfiles()
|
err = h.selectFromLocalProfile(&opts)
|
||||||
if err != nil {
|
|
||||||
return nil, "", err
|
|
||||||
}
|
|
||||||
// choose profile
|
|
||||||
opts.Profile, err = h.chooseProfile(profilesList)
|
|
||||||
if err != nil {
|
|
||||||
return nil, "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
if opts.Region == "" {
|
|
||||||
region, isDefinedInProfile, err := getRegion(opts.Profile)
|
|
||||||
if isDefinedInProfile {
|
|
||||||
opts.Region = region
|
|
||||||
} else {
|
|
||||||
fmt.Println("No region defined in the profile. Choose the region to use.")
|
|
||||||
opts.Region, err = h.chooseRegion(opts.Region, opts.Profile)
|
|
||||||
if err != nil {
|
|
||||||
return nil, "", err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case 2:
|
case 2:
|
||||||
accessKey, secretKey, err := h.askCredentials()
|
err = h.createProfileFromCredentials(&opts)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
opts.AccessKey = accessKey
|
|
||||||
opts.SecretKey = secretKey
|
|
||||||
// we need a region set -- either read it from profile or prompt user
|
|
||||||
// prompt for the region to use with this context
|
|
||||||
opts.Region, err = h.chooseRegion(opts.Region, opts.Profile)
|
|
||||||
if err != nil {
|
|
||||||
return nil, "", err
|
|
||||||
}
|
|
||||||
// save as a profile
|
|
||||||
if opts.Profile == "" {
|
|
||||||
opts.Profile = opts.Name
|
|
||||||
}
|
|
||||||
fmt.Printf("Saving credentials under profile %s\n", opts.Profile)
|
|
||||||
h.createProfile(opts.Profile, &opts)
|
|
||||||
}
|
|
||||||
|
|
||||||
ecsCtx, descr := h.createContext(&opts)
|
ecsCtx, descr := h.createContext(&opts)
|
||||||
return ecsCtx, descr, nil
|
return ecsCtx, descr, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user