Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

info: guide to obtain credentials #195

Merged
merged 1 commit into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/config/moduleconfig/module_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Parameter struct {
Execute string `yaml:"execute,omitempty"`
Value string `yaml:"value,omitempty"`
Default string `yaml:"default,omitempty"`
Info string `yaml:"info,omitempty"`
}

type TemplateConfig struct {
Expand Down
67 changes: 37 additions & 30 deletions internal/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,49 +119,49 @@ func promptAllModules(modules map[string]moduleconfig.ModuleConfig, projectCrede
// requires the projectName to populate defaults
func getProjectNamePrompt() PromptHandler {
return PromptHandler{
moduleconfig.Parameter{
Parameter: moduleconfig.Parameter{
Field: "projectName",
Label: "Project Name",
Default: "",
},
NoCondition,
NoValidation,
Condition: NoCondition,
Validate: NoValidation,
}
}

func getProjectPrompts(projectName string, modules map[string]moduleconfig.ModuleConfig) map[string]PromptHandler {
handlers := map[string]PromptHandler{
"ShouldPushRepositories": {
moduleconfig.Parameter{
Parameter: moduleconfig.Parameter{
Field: "ShouldPushRepositories",
Label: "Should the created projects be checked into github automatically? (y/n)",
Default: "y",
},
NoCondition,
SpecificValueValidation("y", "n"),
Condition: NoCondition,
Validate: SpecificValueValidation("y", "n"),
},
"GithubRootOrg": {
moduleconfig.Parameter{
Parameter: moduleconfig.Parameter{
Field: "GithubRootOrg",
Label: "What's the root of the github org to create repositories in?",
Default: "github.com/",
},
KeyMatchCondition("ShouldPushRepositories", "y"),
NoValidation,
Condition: KeyMatchCondition("ShouldPushRepositories", "y"),
Validate: NoValidation,
},
}

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

handlers[moduleName] = PromptHandler{
moduleconfig.Parameter{
Parameter: moduleconfig.Parameter{
Field: moduleName,
Label: label,
Default: module.OutputDir,
},
NoCondition,
NoValidation,
Condition: NoCondition,
Validate: NoValidation,
}
}

Expand Down Expand Up @@ -215,63 +215,70 @@ func mapVendorToPrompts(projectCred globalconfig.ProjectCredential, vendor strin
case "aws":
awsPrompts := []PromptHandler{
{
moduleconfig.Parameter{
Parameter: moduleconfig.Parameter{
Field: "use_aws_profile",
Label: "Use credentials from existing AWS profiles?",
Options: []string{awsPickProfile, awsManualInputCredentials},
},
customAwsPickProfileCondition,
NoValidation,
Condition: customAwsPickProfileCondition,
Validate: NoValidation,
},
{
moduleconfig.Parameter{
Parameter: moduleconfig.Parameter{
Field: "aws_profile",
Label: "Select AWS Profile",
Options: profiles,
},
KeyMatchCondition("use_aws_profile", awsPickProfile),
NoValidation,
Condition: KeyMatchCondition("use_aws_profile", awsPickProfile),
Validate: NoValidation,
},
{
moduleconfig.Parameter{
Parameter: moduleconfig.Parameter{
Field: "accessKeyId",
Label: "AWS Access Key ID",
Default: projectCred.AWSResourceConfig.AccessKeyID,
Info: `AWS Access Key ID/Secret: used for provisioning infrastructure in AWS
The token can be generated at https://console.aws.amazon.com/iam/home?#/security_credentials`,
},
CustomCondition(customAwsMustInputCondition),
ValidateAKID,
Condition: CustomCondition(customAwsMustInputCondition),
Validate: ValidateAKID,
},
{
moduleconfig.Parameter{
Parameter: moduleconfig.Parameter{
Field: "secretAccessKey",
Label: "AWS Secret access key",
Default: projectCred.AWSResourceConfig.SecretAccessKey,
},
CustomCondition(customAwsMustInputCondition),
ValidateSAK,
Condition: CustomCondition(customAwsMustInputCondition),
Validate: ValidateSAK,
},
}
prompts = append(prompts, awsPrompts...)
case "github":
githubPrompt := PromptHandler{
moduleconfig.Parameter{
Parameter: moduleconfig.Parameter{
Field: "accessToken",
Label: "Github Personal Access Token with access to the above organization",
Default: projectCred.GithubResourceConfig.AccessToken,
Info: `Github personal access token: used for creating repositories for your project
Requires the following permissions: [repo::public_repo, admin::orgread:org]
The token can be created at https://github.com/settings/tokens`,
},
NoCondition,
NoValidation,
Condition: NoCondition,
Validate: NoValidation,
}
prompts = append(prompts, githubPrompt)
case "circleci":
circleCiPrompt := PromptHandler{
moduleconfig.Parameter{
Parameter: moduleconfig.Parameter{
Field: "apiKey",
Label: "Circleci api key for CI/CD",
Default: projectCred.CircleCiResourceConfig.ApiKey,
Info: `CircleCI api token: used for setting up CI/CD for your project
The token can be created at https://app.circleci.com/settings/user/tokens`,
},
NoCondition,
NoValidation,
Condition: NoCondition,
Validate: NoValidation,
}
prompts = append(prompts, circleCiPrompt)
}
Expand Down
11 changes: 8 additions & 3 deletions internal/init/prompts.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/commitdev/zero/internal/util"
"github.com/commitdev/zero/pkg/credentials"
"github.com/commitdev/zero/pkg/util/exit"
"github.com/commitdev/zero/pkg/util/flog"
"github.com/manifoldco/promptui"
"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -91,7 +92,11 @@ func ValidateSAK(input string) error {
func (p PromptHandler) GetParam(projectParams map[string]string) string {
var err error
var result string

if p.Condition(projectParams) {
if p.Parameter.Info != "" {
flog.Guidef(p.Parameter.Info)
}
// TODO: figure out scope of projectParams per project
// potentially dangerous to have cross module env leaking
// so if community module has an `execute: twitter tweet $ENV`
Expand Down Expand Up @@ -173,9 +178,9 @@ func PromptModuleParams(moduleConfig moduleconfig.ModuleConfig, parameters map[s
}

promptHandler := PromptHandler{
promptConfig,
NoCondition,
NoValidation,
Parameter: promptConfig,
Condition: NoCondition,
Validate: NoValidation,
}
// merging the context of param and credentals
// this treats credentialEnvs as throwaway, parameters is shared between modules
Expand Down
1 change: 1 addition & 0 deletions internal/init/prompts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

func TestGetParam(t *testing.T) {

projectParams := map[string]string{}
t.Run("Should execute params without prompt", func(t *testing.T) {
param := moduleconfig.Parameter{
Expand Down
6 changes: 6 additions & 0 deletions pkg/util/flog/log.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package flog

import (
"fmt"
"log"

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

// Infof prints out a timestamp as prefix, Guidef just prints the message
func Guidef(format string, a ...interface{}) {
fmt.Println(aurora.Cyan(emoji.Sprintf(format, a...)))
}

// Successf logs a formatted success message
func Successf(format string, a ...interface{}) {
log.Println(aurora.Green(emoji.Sprintf(":white_check_mark: "+format, a...)))
Expand Down