Skip to content

Commit

Permalink
Support skipping parameters and credentials during generate
Browse files Browse the repository at this point in the history
Adds a `skip` option to the prompt allow users to skip parameter
and credential generation of specific entries.

Signed-off-by: Kim Christensen <kimworking@gmail.com>
  • Loading branch information
kichristensen committed May 7, 2024
1 parent 47919a1 commit e1479cb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
questionEnvVar = "environment variable"
questionPath = "file path"
questionCommand = "shell command"
questionSkip = "skip"
)

type generator func(name string, surveyType SurveyType) (secrets.SourceMap, error)
Expand All @@ -52,7 +53,7 @@ func genSurvey(name string, surveyType SurveyType) (secrets.SourceMap, error) {
// 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},
Options: []string{questionSecret, questionValue, questionEnvVar, questionPath, questionCommand, questionSkip},
Default: "environment variable",
}

Expand All @@ -78,6 +79,12 @@ func genSurvey(name string, surveyType SurveyType) (secrets.SourceMap, error) {
promptMsg = fmt.Sprintf(sourceValuePromptTemplate, "path", surveyType, name)
case questionCommand:
promptMsg = fmt.Sprintf(sourceValuePromptTemplate, "command", surveyType, name)
case questionSkip:
promptMsg = fmt.Sprintf(sourceValuePromptTemplate, "skip", surveyType, name)
}

if source == questionSkip {
return secrets.SourceMap{}, nil
}

sourceValuePrompt := &survey.Input{
Expand Down
4 changes: 4 additions & 0 deletions pkg/porter/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ func (p *Porter) GenerateCredentials(ctx context.Context, opts CredentialOptions
return span.Error(fmt.Errorf("unable to generate credentials: %w", err))
}

if len(cs.Credentials) == 0 {
return nil
}

cs.Status.Created = time.Now()
cs.Status.Modified = cs.Status.Created

Expand Down
4 changes: 4 additions & 0 deletions pkg/porter/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ func (p *Porter) GenerateParameters(ctx context.Context, opts ParameterOptions)
return fmt.Errorf("unable to generate parameter set: %w", err)
}

if len(pset.Parameters) == 0 {
return nil
}

pset.Status.Created = time.Now()
pset.Status.Modified = pset.Status.Created

Expand Down

0 comments on commit e1479cb

Please sign in to comment.