Skip to content

Commit 4028ee3

Browse files
committed
info: guide to obtain credentials
1 parent 688992a commit 4028ee3

File tree

5 files changed

+53
-33
lines changed

5 files changed

+53
-33
lines changed

internal/config/moduleconfig/module_config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type Parameter struct {
2323
Execute string `yaml:"execute,omitempty"`
2424
Value string `yaml:"value,omitempty"`
2525
Default string `yaml:"default,omitempty"`
26+
Info string `yaml:"info,omitempty"`
2627
}
2728

2829
type TemplateConfig struct {

internal/init/init.go

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -119,49 +119,49 @@ func promptAllModules(modules map[string]moduleconfig.ModuleConfig, projectCrede
119119
// requires the projectName to populate defaults
120120
func getProjectNamePrompt() PromptHandler {
121121
return PromptHandler{
122-
moduleconfig.Parameter{
122+
Parameter: moduleconfig.Parameter{
123123
Field: "projectName",
124124
Label: "Project Name",
125125
Default: "",
126126
},
127-
NoCondition,
128-
NoValidation,
127+
Condition: NoCondition,
128+
Validate: NoValidation,
129129
}
130130
}
131131

132132
func getProjectPrompts(projectName string, modules map[string]moduleconfig.ModuleConfig) map[string]PromptHandler {
133133
handlers := map[string]PromptHandler{
134134
"ShouldPushRepositories": {
135-
moduleconfig.Parameter{
135+
Parameter: moduleconfig.Parameter{
136136
Field: "ShouldPushRepositories",
137137
Label: "Should the created projects be checked into github automatically? (y/n)",
138138
Default: "y",
139139
},
140-
NoCondition,
141-
SpecificValueValidation("y", "n"),
140+
Condition: NoCondition,
141+
Validate: SpecificValueValidation("y", "n"),
142142
},
143143
"GithubRootOrg": {
144-
moduleconfig.Parameter{
144+
Parameter: moduleconfig.Parameter{
145145
Field: "GithubRootOrg",
146146
Label: "What's the root of the github org to create repositories in?",
147147
Default: "github.com/",
148148
},
149-
KeyMatchCondition("ShouldPushRepositories", "y"),
150-
NoValidation,
149+
Condition: KeyMatchCondition("ShouldPushRepositories", "y"),
150+
Validate: NoValidation,
151151
},
152152
}
153153

154154
for moduleName, module := range modules {
155155
label := fmt.Sprintf("What do you want to call the %s project?", moduleName)
156156

157157
handlers[moduleName] = PromptHandler{
158-
moduleconfig.Parameter{
158+
Parameter: moduleconfig.Parameter{
159159
Field: moduleName,
160160
Label: label,
161161
Default: module.OutputDir,
162162
},
163-
NoCondition,
164-
NoValidation,
163+
Condition: NoCondition,
164+
Validate: NoValidation,
165165
}
166166
}
167167

@@ -215,63 +215,70 @@ func mapVendorToPrompts(projectCred globalconfig.ProjectCredential, vendor strin
215215
case "aws":
216216
awsPrompts := []PromptHandler{
217217
{
218-
moduleconfig.Parameter{
218+
Parameter: moduleconfig.Parameter{
219219
Field: "use_aws_profile",
220220
Label: "Use credentials from existing AWS profiles?",
221221
Options: []string{awsPickProfile, awsManualInputCredentials},
222222
},
223-
customAwsPickProfileCondition,
224-
NoValidation,
223+
Condition: customAwsPickProfileCondition,
224+
Validate: NoValidation,
225225
},
226226
{
227-
moduleconfig.Parameter{
227+
Parameter: moduleconfig.Parameter{
228228
Field: "aws_profile",
229229
Label: "Select AWS Profile",
230230
Options: profiles,
231231
},
232-
KeyMatchCondition("use_aws_profile", awsPickProfile),
233-
NoValidation,
232+
Condition: KeyMatchCondition("use_aws_profile", awsPickProfile),
233+
Validate: NoValidation,
234234
},
235235
{
236-
moduleconfig.Parameter{
236+
Parameter: moduleconfig.Parameter{
237237
Field: "accessKeyId",
238238
Label: "AWS Access Key ID",
239239
Default: projectCred.AWSResourceConfig.AccessKeyID,
240+
Info: `AWS Access Key ID/Secret: used for provisioning infrastructure in AWS
241+
The token can be generated at https://console.aws.amazon.com/iam/home?#/security_credentials`,
240242
},
241-
CustomCondition(customAwsMustInputCondition),
242-
ValidateAKID,
243+
Condition: CustomCondition(customAwsMustInputCondition),
244+
Validate: ValidateAKID,
243245
},
244246
{
245-
moduleconfig.Parameter{
247+
Parameter: moduleconfig.Parameter{
246248
Field: "secretAccessKey",
247249
Label: "AWS Secret access key",
248250
Default: projectCred.AWSResourceConfig.SecretAccessKey,
249251
},
250-
CustomCondition(customAwsMustInputCondition),
251-
ValidateSAK,
252+
Condition: CustomCondition(customAwsMustInputCondition),
253+
Validate: ValidateSAK,
252254
},
253255
}
254256
prompts = append(prompts, awsPrompts...)
255257
case "github":
256258
githubPrompt := PromptHandler{
257-
moduleconfig.Parameter{
259+
Parameter: moduleconfig.Parameter{
258260
Field: "accessToken",
259261
Label: "Github Personal Access Token with access to the above organization",
260262
Default: projectCred.GithubResourceConfig.AccessToken,
263+
Info: `Github personal access token: used for creating repositories for your project
264+
Requires the following permissions: [repo::public_repo, admin::orgread:org]
265+
The token can be created at https://github.com/settings/tokens`,
261266
},
262-
NoCondition,
263-
NoValidation,
267+
Condition: NoCondition,
268+
Validate: NoValidation,
264269
}
265270
prompts = append(prompts, githubPrompt)
266271
case "circleci":
267272
circleCiPrompt := PromptHandler{
268-
moduleconfig.Parameter{
273+
Parameter: moduleconfig.Parameter{
269274
Field: "apiKey",
270275
Label: "Circleci api key for CI/CD",
271276
Default: projectCred.CircleCiResourceConfig.ApiKey,
277+
Info: `CircleCI api token: used for setting up CI/CD for your project
278+
The token can be created at https://app.circleci.com/settings/user/tokens`,
272279
},
273-
NoCondition,
274-
NoValidation,
280+
Condition: NoCondition,
281+
Validate: NoValidation,
275282
}
276283
prompts = append(prompts, circleCiPrompt)
277284
}

internal/init/prompts.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/commitdev/zero/internal/util"
1515
"github.com/commitdev/zero/pkg/credentials"
1616
"github.com/commitdev/zero/pkg/util/exit"
17+
"github.com/commitdev/zero/pkg/util/flog"
1718
"github.com/manifoldco/promptui"
1819
"gopkg.in/yaml.v2"
1920
)
@@ -91,7 +92,11 @@ func ValidateSAK(input string) error {
9192
func (p PromptHandler) GetParam(projectParams map[string]string) string {
9293
var err error
9394
var result string
95+
9496
if p.Condition(projectParams) {
97+
if p.Parameter.Info != "" {
98+
flog.Guidef(p.Parameter.Info)
99+
}
95100
// TODO: figure out scope of projectParams per project
96101
// potentially dangerous to have cross module env leaking
97102
// so if community module has an `execute: twitter tweet $ENV`
@@ -173,9 +178,9 @@ func PromptModuleParams(moduleConfig moduleconfig.ModuleConfig, parameters map[s
173178
}
174179

175180
promptHandler := PromptHandler{
176-
promptConfig,
177-
NoCondition,
178-
NoValidation,
181+
Parameter: promptConfig,
182+
Condition: NoCondition,
183+
Validate: NoValidation,
179184
}
180185
// merging the context of param and credentals
181186
// this treats credentialEnvs as throwaway, parameters is shared between modules

internal/init/prompts_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
)
1212

1313
func TestGetParam(t *testing.T) {
14+
1415
projectParams := map[string]string{}
1516
t.Run("Should execute params without prompt", func(t *testing.T) {
1617
param := moduleconfig.Parameter{

pkg/util/flog/log.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package flog
22

33
import (
4+
"fmt"
45
"log"
56

67
"github.com/kyokomi/emoji"
@@ -12,6 +13,11 @@ func Infof(format string, a ...interface{}) {
1213
log.Println(aurora.Cyan(emoji.Sprintf(format, a...)))
1314
}
1415

16+
// Infof prints out a timestamp as prefix, Guidef just prints the message
17+
func Guidef(format string, a ...interface{}) {
18+
fmt.Println(aurora.Cyan(emoji.Sprintf(format, a...)))
19+
}
20+
1521
// Successf logs a formatted success message
1622
func Successf(format string, a ...interface{}) {
1723
log.Println(aurora.Green(emoji.Sprintf(":white_check_mark: "+format, a...)))

0 commit comments

Comments
 (0)