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

(feat): show descriptions for params/creds at gen time #3089

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pkg/generator/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func GenerateCredentials(opts GenerateCredentialsOptions) (storage.CredentialSet
if opts.Silent {
generator = genEmptySet
}
credSet, err := genCredentialSet(opts.Namespace, opts.Name, opts.Credentials, generator)
credSet, err := genCredentialSet(opts.Namespace, opts.Name, opts.Description, opts.Credentials, generator)
if err != nil {
return storage.CredentialSet{}, err
}
Expand All @@ -37,8 +37,8 @@ func GenerateCredentials(opts GenerateCredentialsOptions) (storage.CredentialSet
return credSet, nil
}

func genCredentialSet(namespace string, name string, creds map[string]bundle.Credential, fn generator) (storage.CredentialSet, error) {
cs := storage.NewCredentialSet(namespace, name)
func genCredentialSet(namespace string, name string, description string, creds map[string]bundle.Credential, fn generator) (storage.CredentialSet, error) {
cs := storage.NewCredentialSet(namespace, name, description)
cs.Credentials = []secrets.SourceMap{}

if strings.ContainsAny(name, "./\\") {
Expand All @@ -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)
if err != nil {
return cs, err
}
Expand Down
18 changes: 12 additions & 6 deletions pkg/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import (
// GenerateOptions are the options to generate a parameter or credential set
type GenerateOptions struct {
// Name of the parameter or credential set.
Name string
Namespace string
Labels map[string]string
Name string
Namespace string
Description string
Labels map[string]string

// Should we survey?
Silent bool
Expand All @@ -35,16 +36,20 @@ const (
questionCommand = "shell command"
)

type generator func(name string, surveyType SurveyType) (secrets.SourceMap, error)
type generator func(name string, description string, surveyType SurveyType) (secrets.SourceMap, error)

func genEmptySet(name string, surveyType SurveyType) (secrets.SourceMap, error) {
func genEmptySet(name string, description string, surveyType SurveyType) (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, description string, surveyType SurveyType) (secrets.SourceMap, error) {
if description != "" {
fmt.Printf("Description: %s", description)
}

if surveyType != surveyCredentials && surveyType != surveyParameters {
return secrets.SourceMap{}, fmt.Errorf("unsupported survey type: %s", surveyType)
}
Expand Down Expand Up @@ -109,6 +114,7 @@ func genSurvey(name string, surveyType SurveyType) (secrets.SourceMap, error) {
c.Source.Strategy = host.SourceCommand
c.Source.Hint = value
}

return c, nil
}

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 @@ -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)
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", "my turtle description", SurveyType("turtles"))
require.EqualError(t, err, "unsupported survey type: turtles")
require.Equal(t, secrets.SourceMap{}, got)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/generator/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (opts *GenerateParametersOptions) GenerateParameters() (storage.ParameterSe
}

func (opts *GenerateParametersOptions) genParameterSet(fn generator) (storage.ParameterSet, error) {
pset := storage.NewParameterSet(opts.Namespace, opts.Name)
pset := storage.NewParameterSet(opts.Namespace, opts.Name, opts.Description)

if strings.ContainsAny(opts.Name, "./\\") {
return pset, fmt.Errorf("parameter set name '%s' cannot contain the following characters: './\\'", opts.Name)
Expand All @@ -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)
if err != nil {
return pset, err
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/porter/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ func (p *Porter) PrintCredentials(ctx context.Context, opts ListOptions) error {
if !ok {
return nil
}
return []string{cr.Namespace, cr.Name, tp.Format(cr.Status.Modified)}
return []string{cr.Namespace, cr.Name, cr.Description, tp.Format(cr.Status.Modified)}
}
return printer.PrintTable(p.Out, creds, printCredRow,
"NAMESPACE", "NAME", "MODIFIED")
"NAMESPACE", "NAME", "DESCRIPTION", "MODIFIED")
default:
return span.Error(fmt.Errorf("invalid format: %s", opts.Format))
}
Expand Down Expand Up @@ -288,6 +288,7 @@ func (p *Porter) ShowCredential(ctx context.Context, opts CredentialShowOptions)
// Note that we are not using span.Info because the command's output must go to standard out
fmt.Fprintf(p.Out, "Name: %s\n", credSet.Name)
fmt.Fprintf(p.Out, "Namespace: %s\n", credSet.Namespace)
fmt.Fprintf(p.Out, "Description: %s\n", credSet.Description)
fmt.Fprintf(p.Out, "Created: %s\n", tp.Format(credSet.Status.Created))
fmt.Fprintf(p.Out, "Modified: %s\n\n", tp.Format(credSet.Status.Modified))

Expand Down
12 changes: 6 additions & 6 deletions pkg/porter/credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ func TestPorter_ListCredentials(t *testing.T) {
defer p.Close()

ctx := context.Background()
p.TestCredentials.InsertCredentialSet(ctx, storage.NewCredentialSet("", "shared-mysql"))
p.TestCredentials.InsertCredentialSet(ctx, storage.NewCredentialSet("dev", "carolyn-wordpress"))
p.TestCredentials.InsertCredentialSet(ctx, storage.NewCredentialSet("dev", "vaughn-wordpress"))
p.TestCredentials.InsertCredentialSet(ctx, storage.NewCredentialSet("test", "staging-wordpress"))
p.TestCredentials.InsertCredentialSet(ctx, storage.NewCredentialSet("test", "iat-wordpress"))
p.TestCredentials.InsertCredentialSet(ctx, storage.NewCredentialSet("test", "shared-mysql"))
p.TestCredentials.InsertCredentialSet(ctx, storage.NewCredentialSet("", "shared-mysql", ""))
p.TestCredentials.InsertCredentialSet(ctx, storage.NewCredentialSet("dev", "carolyn-wordpress", ""))
p.TestCredentials.InsertCredentialSet(ctx, storage.NewCredentialSet("dev", "vaughn-wordpress", ""))
p.TestCredentials.InsertCredentialSet(ctx, storage.NewCredentialSet("test", "jeremy-wordpress", ""))
p.TestCredentials.InsertCredentialSet(ctx, storage.NewCredentialSet("test", "iat-wordpress", ""))
p.TestCredentials.InsertCredentialSet(ctx, storage.NewCredentialSet("test", "shared-mysql", ""))

t.Run("all-namespaces", func(t *testing.T) {
opts := ListOptions{AllNamespaces: true}
Expand Down
4 changes: 2 additions & 2 deletions pkg/porter/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func TestPorter_applyActionOptionsToInstallation_FollowsParameterHierarchy(t *te
bun, err := configadapter.ConvertToTestBundle(ctx, p.Config, m)
require.NoError(t, err)

err = p.TestParameters.InsertParameterSet(ctx, storage.NewParameterSet("", "myps",
err = p.TestParameters.InsertParameterSet(ctx, storage.NewParameterSet("", "myps", "",
storage.ValueStrategy("my-second-param", "via_paramset")))
require.NoError(t, err, "Create my-second-param parameter set failed")

Expand Down Expand Up @@ -515,7 +515,7 @@ func TestPorter_applyActionOptionsToInstallation_PreservesExistingParams(t *test
opts.Params = []string{nonsensitiveParamName + "=" + nonsensitiveParamValue}

i := storage.NewInstallation("", bun.Name)
i.Parameters = storage.NewParameterSet("", "internal-ps",
i.Parameters = storage.NewParameterSet("", "internal-ps", "",
storage.ValueStrategy("my-first-param", "1"),
storage.ValueStrategy("my-second-param", "2"),
)
Expand Down
12 changes: 6 additions & 6 deletions pkg/porter/parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ func TestPorter_ListParameters(t *testing.T) {
p := NewTestPorter(t)
defer p.Close()
ctx := context.Background()
p.TestParameters.InsertParameterSet(ctx, storage.NewParameterSet("", "shared-mysql"))
p.TestParameters.InsertParameterSet(ctx, storage.NewParameterSet("dev", "carolyn-wordpress"))
p.TestParameters.InsertParameterSet(ctx, storage.NewParameterSet("dev", "vaughn-wordpress"))
p.TestParameters.InsertParameterSet(ctx, storage.NewParameterSet("test", "staging-wordpress"))
p.TestParameters.InsertParameterSet(ctx, storage.NewParameterSet("test", "iat-wordpress"))
p.TestParameters.InsertParameterSet(ctx, storage.NewParameterSet("test", "shared-mysql"))
p.TestParameters.InsertParameterSet(ctx, storage.NewParameterSet("", "", "shared-mysql"))
p.TestParameters.InsertParameterSet(ctx, storage.NewParameterSet("dev", "", "carolyn-wordpress"))
p.TestParameters.InsertParameterSet(ctx, storage.NewParameterSet("dev", "", "vaughn-wordpress"))
p.TestParameters.InsertParameterSet(ctx, storage.NewParameterSet("test", "", "staging-wordpress"))
p.TestParameters.InsertParameterSet(ctx, storage.NewParameterSet("test", "", "iat-wordpress"))
p.TestParameters.InsertParameterSet(ctx, storage.NewParameterSet("test", "", "shared-mysql"))

t.Run("all-namespaces", func(t *testing.T) {
opts := ListOptions{AllNamespaces: true}
Expand Down
1 change: 1 addition & 0 deletions pkg/porter/testdata/credentials/kool-kreds.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"schemaVersion": "1.0.1",
"namespace": "dev",
"name": "kool-kreds",
"description": "",
"credentials": [
{
"name": "kool-config",
Expand Down
1 change: 1 addition & 0 deletions pkg/porter/testdata/credentials/kool-kreds.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Name: kool-kreds
Namespace: dev
Description:
Created: 2019-06-24
Modified: 2019-06-24

Expand Down
1 change: 1 addition & 0 deletions pkg/porter/testdata/credentials/kool-kreds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ schemaType: CredentialSet
schemaVersion: 1.0.1
namespace: dev
name: kool-kreds
description: ""
credentials:
- name: kool-config
source:
Expand Down
6 changes: 3 additions & 3 deletions pkg/porter/testdata/credentials/list-output.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-----------------------------
NAMESPACE NAME MODIFIED
-----------------------------
------------------------------------------
NAMESPACE NAME DESCRIPTION MODIFIED
------------------------------------------
1 change: 1 addition & 0 deletions pkg/porter/testdata/credentials/show-output.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"schemaVersion": "1.0.1",
"namespace": "dev",
"name": "kool-kreds",
"description": "",
"credentials": [
{
"name": "kool-config",
Expand Down
8 changes: 4 additions & 4 deletions pkg/porter/testdata/credentials/show-output.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-------------------------------------
NAMESPACE NAME MODIFIED
-------------------------------------
dev kool-kreds 2019-06-24
--------------------------------------------------
NAMESPACE NAME DESCRIPTION MODIFIED
--------------------------------------------------
dev kool-kreds 2019-06-24
1 change: 1 addition & 0 deletions pkg/porter/testdata/credentials/show-output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
schemaVersion: 1.0.1
namespace: dev
name: kool-kreds
description: ""
credentials:
- name: kool-config
source:
Expand Down
1 change: 1 addition & 0 deletions pkg/porter/testdata/parameters/mypset.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"schemaVersion": "1.0.1",
"namespace": "",
"name": "mypset",
"description": "",
"parameters": [
{
"name": "foo",
Expand Down
1 change: 1 addition & 0 deletions pkg/porter/testdata/parameters/mypset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ schemaType: ParameterSet
schemaVersion: 1.0.1
namespace: ""
name: mypset
description: ""
parameters:
- name: foo
source:
Expand Down
8 changes: 4 additions & 4 deletions pkg/storage/credential_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func TestCredentialStorage_CRUD(t *testing.T) {
cs := NewCredentialSet("dev", "sekrets", secrets.SourceMap{
cs := NewCredentialSet("dev", "sekrets", "", secrets.SourceMap{
Name: "password", Source: secrets.Source{
Strategy: "secret",
Hint: "dbPassword"}})
Expand Down Expand Up @@ -45,7 +45,7 @@ func TestCredentialStorage_CRUD(t *testing.T) {
require.NoError(t, err)
assert.Len(t, cs.Credentials, 2)

cs2 := NewCredentialSet("dev", "sekrets-2", secrets.SourceMap{
cs2 := NewCredentialSet("dev", "sekrets-2", "", secrets.SourceMap{
Name: "password-2", Source: secrets.Source{
Strategy: "secret-2",
Hint: "dbPassword-2"}})
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestCredentialStorage_CRUD(t *testing.T) {

func TestCredentialStorage_Validate_GoodSources(t *testing.T) {
s := CredentialStore{}
testCreds := NewCredentialSet("dev", "mycreds",
testCreds := NewCredentialSet("dev", "mycreds", "",
secrets.SourceMap{
Source: secrets.Source{
Strategy: "env",
Expand All @@ -93,7 +93,7 @@ func TestCredentialStorage_Validate_GoodSources(t *testing.T) {

func TestCredentialStorage_Validate_BadSources(t *testing.T) {
s := CredentialStore{}
testCreds := NewCredentialSet("dev", "mycreds",
testCreds := NewCredentialSet("dev", "mycreds", "",
secrets.SourceMap{
Source: secrets.Source{
Strategy: "wrongthing",
Expand Down
6 changes: 5 additions & 1 deletion pkg/storage/credentialset.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ type CredentialSetSpec struct {
// Name of the credential set.
Name string `json:"name" yaml:"name" toml:"name"`

// Description fo teh credential set.
Description string `json:"description" yaml:"description" toml:"description"`

// Labels applied to the credential set.
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty" toml:"labels,omitempty"`

Expand All @@ -74,13 +77,14 @@ func NewInternalCredentialSet(creds ...secrets.SourceMap) CredentialSet {
}

// NewCredentialSet creates a new CredentialSet with the required fields initialized.
func NewCredentialSet(namespace string, name string, creds ...secrets.SourceMap) CredentialSet {
func NewCredentialSet(namespace string, name string, description string, creds ...secrets.SourceMap) CredentialSet {
now := time.Now()
cs := CredentialSet{
CredentialSetSpec: CredentialSetSpec{
SchemaType: SchemaTypeCredentialSet,
SchemaVersion: DefaultCredentialSetSchemaVersion,
Name: name,
Description: description,
Namespace: namespace,
Credentials: creds,
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/credentialset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

func TestNewCredentialSet(t *testing.T) {
cs := NewCredentialSet("dev", "mycreds", secrets.SourceMap{
cs := NewCredentialSet("dev", "mycreds", "", secrets.SourceMap{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make sense assert that the description is added correctly like this test does with the other inputs?

Name: "password",
Source: secrets.Source{
Strategy: "env",
Expand Down Expand Up @@ -140,7 +140,7 @@ func TestDisplayCredentials_Validate(t *testing.T) {
}

func TestCredentialSet_Validate_DefaultSchemaType(t *testing.T) {
cs := NewCredentialSet("", "mycs")
cs := NewCredentialSet("", "mycs", "")
cs.SchemaType = ""
require.NoError(t, cs.Validate(context.Background(), schema.CheckStrategyExact))
assert.Equal(t, SchemaTypeCredentialSet, cs.SchemaType)
Expand Down
10 changes: 5 additions & 5 deletions pkg/storage/parameter_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestParameterStore_CRUD(t *testing.T) {
require.NoError(t, err)
require.Empty(t, params, "Find should return no entries")

myParamSet := NewParameterSet("dev", "myparams",
myParamSet := NewParameterSet("dev", "myparams", "",
secrets.SourceMap{
Name: "myparam",
Source: secrets.Source{
Expand Down Expand Up @@ -49,7 +49,7 @@ func TestParameterStore_CRUD(t *testing.T) {
require.NoError(t, err)
require.Equal(t, myParamSet, pset, "Get should return the saved parameter set")

myParamSet2 := NewParameterSet("dev", "myparams2",
myParamSet2 := NewParameterSet("dev", "myparams2", "",
secrets.SourceMap{
Name: "myparam2",
Source: secrets.Source{
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestParameterStore_CRUD(t *testing.T) {
func TestParameterStorage_ResolveAll(t *testing.T) {
// The inmemory secret store currently only supports secret sources
// So all of these have this same source
testParameterSet := NewParameterSet("", "myparamset",
testParameterSet := NewParameterSet("", "myparamset", "",
secrets.SourceMap{
Name: "param1",
Source: secrets.Source{
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestParameterStorage_Validate(t *testing.T) {
t.Run("valid sources", func(t *testing.T) {
s := ParameterStore{}

testParameterSet := NewParameterSet("", "myparams",
testParameterSet := NewParameterSet("", "myparams", "",
secrets.SourceMap{
Source: secrets.Source{
Strategy: "env",
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestParameterStorage_Validate(t *testing.T) {

t.Run("invalid sources", func(t *testing.T) {
s := ParameterStore{}
testParameterSet := NewParameterSet("", "myparams",
testParameterSet := NewParameterSet("", "myparams", "",
secrets.SourceMap{
Source: secrets.Source{
Strategy: "wrongthing",
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestTestParameterProvider_Load(t *testing.T) {
})

t.Run("successful load, successful unmarshal", func(t *testing.T) {
expected := NewParameterSet("", "mybun",
expected := NewParameterSet("", "mybun", "",
secrets.SourceMap{
Name: "param_env",
Source: secrets.Source{
Expand Down
Loading
Loading