@@ -10,27 +10,48 @@ import (
1010
1111 "github.com/commitdev/zero/internal/config/globalconfig"
1212 "github.com/commitdev/zero/internal/config/moduleconfig"
13+ "github.com/commitdev/zero/pkg/credentials"
1314 "github.com/commitdev/zero/pkg/util/exit"
1415 "github.com/manifoldco/promptui"
1516 "gopkg.in/yaml.v2"
1617)
1718
19+ // Constant to maintain prompt orders so users can have the same flow,
20+ // modules get downloaded asynchronously therefore its easier to just hardcode an order
21+ var AvailableVendorOrders = []string {"aws" , "github" , "circleci" }
22+
23+ const awsPickProfile = "Existing AWS Profiles"
24+ const awsManualInputCredentials = "Enter my own AWS credentials"
25+
1826type PromptHandler struct {
1927 moduleconfig.Parameter
20- Condition func ( map [ string ] string ) bool
28+ Condition CustomConditionSignature
2129 Validate func (string ) error
2230}
2331
32+ type CredentialPrompts struct {
33+ Vendor string
34+ Prompts []PromptHandler
35+ }
36+
37+ type CustomConditionSignature func (map [string ]string ) bool
38+
2439func NoCondition (map [string ]string ) bool {
2540 return true
2641}
2742
28- func KeyMatchCondition (key string , value string ) func ( map [ string ] string ) bool {
43+ func KeyMatchCondition (key string , value string ) CustomConditionSignature {
2944 return func (param map [string ]string ) bool {
3045 return param [key ] == value
3146 }
3247}
3348
49+ func CustomCondition (fn CustomConditionSignature ) CustomConditionSignature {
50+ return func (param map [string ]string ) bool {
51+ return fn (param )
52+ }
53+ }
54+
3455func NoValidation (string ) error {
3556 return nil
3657}
@@ -150,24 +171,32 @@ func PromptModuleParams(moduleConfig moduleconfig.ModuleConfig, parameters map[s
150171 return parameters , nil
151172}
152173
153- func promptCredentialsAndFillProjectCreds (credentialPrompts map [ string ][] PromptHandler , credentials globalconfig.ProjectCredential ) globalconfig.ProjectCredential {
174+ func promptCredentialsAndFillProjectCreds (credentialPrompts [] CredentialPrompts , creds globalconfig.ProjectCredential ) globalconfig.ProjectCredential {
154175 promptsValues := map [string ]map [string ]string {}
155176
156- for vendor , prompts := range credentialPrompts {
177+ for _ , prompts := range credentialPrompts {
178+ vendor := prompts .Vendor
157179 vendorPromptValues := map [string ]string {}
158180
159181 // vendors like AWS have multiple prompts (accessKeyId and secretAccessKey)
160- for _ , prompt := range prompts {
161- vendorPromptValues [prompt .Field ] = prompt .GetParam (map [ string ] string {} )
182+ for _ , prompt := range prompts . Prompts {
183+ vendorPromptValues [prompt .Field ] = prompt .GetParam (vendorPromptValues )
162184 }
163185 promptsValues [vendor ] = vendorPromptValues
164186 }
165187
166188 // FIXME: what is a good way to dynamically modify partial data of a struct
167189 // current just marashing to yaml, then unmarshaling into the base struct
168190 yamlContent , _ := yaml .Marshal (promptsValues )
169- yaml .Unmarshal (yamlContent , & credentials )
170- return credentials
191+ yaml .Unmarshal (yamlContent , & creds )
192+
193+ // Fill AWS credentials based on profile from ~/.aws/credentials
194+ if val , ok := promptsValues ["aws" ]; ok {
195+ if val ["use_aws_profile" ] == awsPickProfile {
196+ creds = credentials .GetAWSProfileProjectCredentials (val ["aws_profile" ], creds )
197+ }
198+ }
199+ return creds
171200}
172201
173202func appendToSet (set []string , toAppend []string ) []string {
0 commit comments