Skip to content

Commit

Permalink
corrections
Browse files Browse the repository at this point in the history
Signed-off-by: div_bhasin <[email protected]>
  • Loading branch information
divbhasin committed Jul 1, 2021
1 parent 1b93de1 commit cb97d13
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pkg/generator/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func genCredentialSet(name string, creds map[string]bundle.Credential, fn genera
sort.Strings(credentialNames)

for _, name := range credentialNames {
c, err := fn(name, surveyCredentials, "")
c, err := fn(name, surveyCredentials, nil)
if err != nil {
return cs, err
}
Expand Down
12 changes: 5 additions & 7 deletions pkg/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@ const (
questionCommand = "shell command"
)

type generator func(name string, surveyType SurveyType, defaultVal string) (valuesource.Strategy, error)
type generator func(name string, surveyType SurveyType, defaultVal interface{}) (valuesource.Strategy, error)

func genEmptySet(name string, surveyType SurveyType, defaultVal string) (valuesource.Strategy, error) {
func genEmptySet(name string, surveyType SurveyType, defaultVal interface{}) (valuesource.Strategy, error) {
return valuesource.Strategy{
Name: name,
Source: valuesource.Source{Value: "TODO"},
}, nil
}

func genSurvey(name string, surveyType SurveyType, defaultVal string) (valuesource.Strategy, error) {
func genSurvey(name string, surveyType SurveyType, defaultVal interface{}) (valuesource.Strategy, error) {
if surveyType != surveyCredentials && surveyType != surveyParameters {
return valuesource.Strategy{}, fmt.Errorf("unsupported survey type: %s", surveyType)
}

options := []string{questionSecret, questionValue, questionEnvVar, questionPath, questionCommand}
questionDefault := fmt.Sprintf("use default value (%s)", defaultVal)

if defaultVal != "" {
if defaultVal != nil {
options = append(options, questionDefault)
}

Expand Down Expand Up @@ -93,15 +93,13 @@ func genSurvey(name string, surveyType SurveyType, defaultVal string) (valuesour
if err := survey.AskOne(sourceValuePrompt, &value, nil); err != nil {
return c, err
}
} else {
value = defaultVal
}

switch source {
case questionSecret:
c.Source.Key = secrets.SourceSecret
c.Source.Value = value
case questionValue, questionDefault:
case questionValue:
c.Source.Key = host.SourceValue
c.Source.Value = value
case questionEnvVar:
Expand Down
4 changes: 2 additions & 2 deletions pkg/generator/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ func Test_genEmptySet(t *testing.T) {
Source: valuesource.Source{Value: "TODO"},
}

got, err := genEmptySet("emptyset", surveyParameters, "")
got, err := genEmptySet("emptyset", surveyParameters, nil)
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"), nil)
require.EqualError(t, err, "unsupported survey type: turtles")
require.Equal(t, valuesource.Strategy{}, got)
}
12 changes: 7 additions & 5 deletions pkg/generator/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ func (opts *GenerateParametersOptions) genParameterSet(fn generator) (parameters
if parameters.IsInternal(name, opts.Bundle) {
continue
}
defaultVal, _ := getDefaultParamValue(opts.Bundle, name)
defaultVal, err := getDefaultParamValue(opts.Bundle, name)

if err != nil {
return pset, err
}

c, err := fn(name, surveyParameters, defaultVal)
if err != nil {
Expand All @@ -64,7 +68,7 @@ func (opts *GenerateParametersOptions) genParameterSet(fn generator) (parameters
return pset, nil
}

func getDefaultParamValue(bun bundle.Bundle, name string) (string, error) {
func getDefaultParamValue(bun bundle.Bundle, name string) (interface{}, error) {
for p, v := range bun.Parameters {
if p == name {
def, ok := bun.Definitions[v.Definition]
Expand All @@ -75,9 +79,7 @@ func getDefaultParamValue(bun bundle.Bundle, name string) (string, error) {
return "", fmt.Errorf("parameter definition for %s is empty", name)
}

if def.Default != nil {
return fmt.Sprintf("%s", def.Default), nil
}
return def.Default, nil
}
}
return "", nil
Expand Down

0 comments on commit cb97d13

Please sign in to comment.