diff --git a/pkg/generator/credentials.go b/pkg/generator/credentials.go index e2d22c129..232e49016 100644 --- a/pkg/generator/credentials.go +++ b/pkg/generator/credentials.go @@ -53,7 +53,7 @@ func genCredentialSet(namespace string, name string, creds map[string]bundle.Cre sort.Strings(credentialNames) for _, name := range credentialNames { - c, err := fn(name, surveyCredentials) + c, err := fn(name, surveyCredentials, creds[name].Required) if err != nil { return cs, err } diff --git a/pkg/generator/generator.go b/pkg/generator/generator.go index a3f14c659..405fa6a6f 100644 --- a/pkg/generator/generator.go +++ b/pkg/generator/generator.go @@ -36,24 +36,29 @@ const ( questionSkip = "skip" ) -type generator func(name string, surveyType SurveyType) (secrets.SourceMap, error) +type generator func(name string, surveyType SurveyType, required bool) (secrets.SourceMap, error) -func genEmptySet(name string, surveyType SurveyType) (secrets.SourceMap, error) { +func genEmptySet(name string, surveyType SurveyType, required bool) (secrets.SourceMap, error) { return secrets.SourceMap{ Name: name, Source: secrets.Source{Hint: "TODO"}, }, nil } -func genSurvey(name string, surveyType SurveyType) (secrets.SourceMap, error) { +func genSurvey(name string, surveyType SurveyType, required bool) (secrets.SourceMap, error) { if surveyType != surveyCredentials && surveyType != surveyParameters { return secrets.SourceMap{}, fmt.Errorf("unsupported survey type: %s", surveyType) } + surveyOptions := []string{questionSecret, questionValue, questionEnvVar, questionPath, questionCommand} + if !required { + surveyOptions = append(surveyOptions, questionSkip) + } + // extra space-suffix to align question and answer. Unfortunately misaligns help text sourceTypePrompt := &survey.Select{ Message: fmt.Sprintf("How would you like to set %s %q\n ", surveyType, name), - Options: []string{questionSecret, questionValue, questionEnvVar, questionPath, questionCommand, questionSkip}, + Options: surveyOptions, Default: "environment variable", } diff --git a/pkg/generator/generator_test.go b/pkg/generator/generator_test.go index 464fd2446..7ada6cb31 100644 --- a/pkg/generator/generator_test.go +++ b/pkg/generator/generator_test.go @@ -15,13 +15,13 @@ func Test_genEmptySet(t *testing.T) { Source: secrets.Source{Hint: "TODO"}, } - got, err := genEmptySet("emptyset", surveyParameters) + got, err := genEmptySet("emptyset", surveyParameters, false) require.NoError(t, err) require.Equal(t, expected, got) } func Test_genSurvey_unsupported(t *testing.T) { - got, err := genSurvey("myturtleset", SurveyType("turtles")) + got, err := genSurvey("myturtleset", SurveyType("turtles"), false) require.EqualError(t, err, "unsupported survey type: turtles") require.Equal(t, secrets.SourceMap{}, got) } diff --git a/pkg/generator/parameters.go b/pkg/generator/parameters.go index 3007fabc8..b878f3ddc 100644 --- a/pkg/generator/parameters.go +++ b/pkg/generator/parameters.go @@ -54,7 +54,7 @@ func (opts *GenerateParametersOptions) genParameterSet(fn generator) (storage.Pa if opts.Bundle.IsInternalParameter(name) { continue } - c, err := fn(name, surveyParameters) + c, err := fn(name, surveyParameters, opts.Bundle.Parameters[name].Required) if err != nil { return pset, err }