From 7b9c9dbc463c2a61c0727b9fbe15c23af58aaa14 Mon Sep 17 00:00:00 2001 From: Pete Muir Date: Fri, 21 Jun 2019 15:23:31 +0100 Subject: [PATCH] feat: support for generated secrets in schemas (#4347) (#4360) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If `"default":"”` is used on a token or a password then it will default to a generated secret Signed-off-by: Pete Muir --- .../step/create/step_create_values_test.go | 2 +- pkg/surveyutils/jsonschema.go | 99 +- pkg/surveyutils/jsonschema_test.go | 1050 ++++++++--------- .../ingoreMissingValues.test.schema.json | 14 - pkg/vault/fake/client.go | 18 +- 5 files changed, 567 insertions(+), 616 deletions(-) delete mode 100644 pkg/surveyutils/test_data/ingoreMissingValues.test.schema.json diff --git a/pkg/cmd/step/create/step_create_values_test.go b/pkg/cmd/step/create/step_create_values_test.go index d05c5c1035..ead8d539f9 100644 --- a/pkg/cmd/step/create/step_create_values_test.go +++ b/pkg/cmd/step/create/step_create_values_test.go @@ -36,7 +36,7 @@ var timeout = 5 * time.Second func TestCreateValuesFileWithVault(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") pegomock.RegisterMockTestingT(t) - tests.Retry(t, 5, time.Second*10, func(r *tests.R) { + tests.Retry(t, 1, time.Second*10, func(r *tests.R) { testOrgNameUUID, err := uuid.NewV4() assert.NoError(t, err) testOrgName := testOrgNameUUID.String() diff --git a/pkg/surveyutils/jsonschema.go b/pkg/surveyutils/jsonschema.go index 60a69ec352..d4b61c8716 100644 --- a/pkg/surveyutils/jsonschema.go +++ b/pkg/surveyutils/jsonschema.go @@ -8,10 +8,10 @@ import ( "strconv" "strings" - "github.com/jenkins-x/jx/pkg/log" - "github.com/jenkins-x/jx/pkg/secreturl" + "github.com/jenkins-x/jx/pkg/log" + "github.com/jenkins-x/jx/pkg/util/secrets" "github.com/pkg/errors" @@ -20,7 +20,7 @@ import ( "github.com/iancoleman/orderedmap" - "gopkg.in/AlecAivazis/survey.v1" + survey "gopkg.in/AlecAivazis/survey.v1" "gopkg.in/AlecAivazis/survey.v1/terminal" ) @@ -625,6 +625,16 @@ func (o *JSONSchemaOptions) handleBasicProperty(name string, prefixes []string, return o.handleConst(name, validators, t, output) } + // lets use the last vaultPath as the vaultKey. We don't need to use the format + // in the vaultKey or vaultPath + lastIdx := len(prefixes) - 1 + vaultKey := prefixes[lastIdx] + pathPrefixes := prefixes[0:lastIdx] + vaultPath := o.VaultBasePath + vaultDir := strings.Join(pathPrefixes, "-") + if vaultDir != "" { + vaultPath = strings.Join([]string{vaultPath, vaultDir}, "/") + } ask := true defaultValue := "" autoAcceptMessage := "" @@ -663,16 +673,54 @@ func (o *JSONSchemaOptions) handleBasicProperty(name string, prefixes []string, validator := survey.ComposeValidators(validators...) // Ask the question // Custom format support for passwords - storeAsSecret := false - var err error dereferencedFormat := strings.TrimSuffix(util.DereferenceString(t.Format), "-passthrough") if dereferencedFormat == "password" || dereferencedFormat == "token" { - storeAsSecret = true - result, err = handlePasswordProperty(message, help, dereferencedFormat, ask, validator, surveyOpts, defaultValue, + if o.VaultClient != nil { + // the standard existing logic is not used in this case + secret, err := o.VaultClient.Read(vaultPath) + if err == nil { + if value, ok := secret[vaultKey]; ok { + if !o.AskExisting { + ask = false + } + defaultValue = fmt.Sprintf("%v", value) + autoAcceptMessage = "Automatically accepted existing value" + } + } else { + // If there is an error, just continue + log.Logger().Debugf("Error reading %s from vault %v", vaultPath, err) + } + } + + secret, err := handlePasswordProperty(message, help, dereferencedFormat, ask, validator, surveyOpts, defaultValue, autoAcceptMessage, o.Out, t.Type) if err != nil { return errors.WithStack(err) } + if secret != nil { + value, err := util.AsString(secret) + if err != nil { + return err + } + if o.VaultClient != nil { + + secretReference := secreturl.ToURI(vaultPath, vaultKey, o.VaultScheme) + output.Set(name, secretReference) + + // lets upsert the vaultKey + data, _ := o.VaultClient.Read(vaultPath) + if data == nil { + data = map[string]interface{}{} + } + data[vaultKey] = value + _, err = o.VaultClient.Write(vaultPath, data) + if err != nil { + return errors.Wrapf(err, "failed to write to vaultPath %s with data %#v", vaultPath, data) + } + } else { + log.Logger().Warnf("Need to store a secret for %s but no secret store configured", name) + } + } } else if t.Enum != nil { var enumResult string // Support for selects @@ -762,40 +810,7 @@ func (o *JSONSchemaOptions) handleBasicProperty(name string, prefixes []string, } } - if storeAsSecret && result != nil { - value, err := util.AsString(result) - if err != nil { - return err - } - if o.VaultClient != nil { - // lets use the last path as the key. We don't need to use the format - // in the key or path - lastIdx := len(prefixes) - 1 - key := prefixes[lastIdx] - pathPrefixes := prefixes[0:lastIdx] - path := o.VaultBasePath - dir := strings.Join(pathPrefixes, "-") - if dir != "" { - path = strings.Join([]string{path, dir}, "/") - } - secretReference := secreturl.ToURI(path, key, o.VaultScheme) - output.Set(name, secretReference) - - // lets upsert the key - data, _ := o.VaultClient.Read(path) - if data == nil { - data = map[string]interface{}{} - } - data[key] = value - _, err = o.VaultClient.Write(path, data) - if err != nil { - return errors.Wrapf(err, "failed to write to path %s with data %#v", path, data) - } - } else { - log.Logger().Warnf("Need to store a secret for %s but no secret store configured", name) - } - - } else if result != nil { + if result != nil { // Write the value to the output output.Set(name, result) } @@ -830,7 +845,7 @@ func handlePasswordProperty(message string, help string, kind string, ask bool, } } else { answer = defaultValue - msg := fmt.Sprintf("%s %s [%s]\n", message, util.ColorInfo(answer), autoAcceptMessage) + msg := fmt.Sprintf("%s *** [%s]\n", message, autoAcceptMessage) _, err := fmt.Fprint(terminal.NewAnsiStdout(out), msg) if err != nil { return nil, errors.Wrapf(err, "writing %s to console", msg) diff --git a/pkg/surveyutils/jsonschema_test.go b/pkg/surveyutils/jsonschema_test.go index cb8bdda747..75f9e4dcad 100644 --- a/pkg/surveyutils/jsonschema_test.go +++ b/pkg/surveyutils/jsonschema_test.go @@ -13,7 +13,7 @@ import ( "gopkg.in/AlecAivazis/survey.v1/core" - "github.com/Netflix/go-expect" + expect "github.com/Netflix/go-expect" "github.com/ghodss/yaml" "github.com/jenkins-x/jx/pkg/tests" @@ -43,14 +43,12 @@ func init() { func TestObjectType(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - values, _, err := GenerateValuesAsYaml(r, "objectType.test.schema.json", make(map[string]interface{}), false, false, - false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - console.ExpectString("Enter a value for name") - console.SendLine("cheese") - console.ExpectEOF() - }) + values, _, err := GenerateValuesAsYaml(r, "objectType.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + console.ExpectString("Enter a value for name") + console.SendLine("cheese") + console.ExpectEOF() + }, nil) assert.Equal(r, `nestedObject: anotherNestedObject: name: cheese @@ -62,25 +60,22 @@ func TestObjectType(t *testing.T) { func TestDescriptionAndTitle(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - values, _, err := GenerateValuesAsYaml(r, "descriptionAndTitle.test.schema.json", make(map[string]interface{}), - false, - false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test explicit question - console.ExpectString("What is your name?") - console.SendLine("?") - // Test explicit description - console.ExpectString("Enter your name") - console.SendLine("Pete") - // Test no description - console.ExpectString("What is your address?") - console.SendLine("?") - // Test no title - console.ExpectString("Enter a value for country") - console.SendLine("UK") - console.ExpectEOF() - }) + values, _, err := GenerateValuesAsYaml(r, "descriptionAndTitle.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test explicit question + console.ExpectString("What is your name?") + console.SendLine("?") + // Test explicit description + console.ExpectString("Enter your name") + console.SendLine("Pete") + // Test no description + console.ExpectString("What is your address?") + console.SendLine("?") + // Test no title + console.ExpectString("Enter a value for country") + console.SendLine("UK") + console.ExpectEOF() + }, nil) assert.NoError(r, err) assert.Equal(r, `address: '?' country: UK @@ -92,16 +87,13 @@ name: Pete func TestAutoAcceptDefaultValues(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - values, _, err := GenerateValuesAsYaml(r, "autoAcceptDefaultValues.test.schema.json", make(map[string]interface{}), - false, false, - true, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test explicit question - //console.ExpectString("What is your name? John Smith [Automatically accepted default value]") - //console.ExpectEOF() - // TODO Fix the console test - }) + values, _, err := GenerateValuesAsYaml(r, "autoAcceptDefaultValues.test.schema.json", make(map[string]interface{}), false, false, true, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test explicit question + //console.ExpectString("What is your name? John Smith [Automatically accepted default value]") + //console.ExpectEOF() + // TODO Fix the console test + }, nil) assert.Equal(r, `name: John Smith `, values) assert.NoError(r, err) @@ -113,15 +105,12 @@ func TestAcceptExisting(t *testing.T) { tests.Retry(t, 5, time.Second*10, func(r *tests.R) { values, _, err := GenerateValuesAsYaml(r, "acceptExisting.test.schema.json", map[string]interface{}{ "name": "John Smith", - }, - false, false, - false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test explicit question - console.ExpectString("What is your name? John Smith [Automatically accepted existing value]") - console.ExpectEOF() - }) + }, false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test explicit question + console.ExpectString("What is your name? John Smith [Automatically accepted existing value]") + console.ExpectEOF() + }, nil) assert.Equal(r, `name: John Smith `, values) assert.NoError(r, err) @@ -133,16 +122,13 @@ func TestAskExisting(t *testing.T) { tests.Retry(t, 5, time.Second*10, func(r *tests.R) { values, _, err := GenerateValuesAsYaml(r, "askExisting.test.schema.json", map[string]interface{}{ "name": "John Smith", - }, - true, - false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test explicit question - console.ExpectString("What is your name? [? for help] (John Smith)") - console.SendLine("") - console.ExpectEOF() - }) + }, true, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test explicit question + console.ExpectString("What is your name? [? for help] (John Smith)") + console.SendLine("") + console.ExpectEOF() + }, nil) assert.NoError(r, err) assert.Equal(r, `name: John Smith `, values) @@ -152,21 +138,17 @@ func TestAskExisting(t *testing.T) { func TestNoAskAndAutoAcceptDefaultsWithExisting(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - values, _, err := GenerateValuesAsYaml(r, "noAskAndAutoAcceptDefaultsWithExisting.test.schema.json", - map[string]interface{}{ - "name": "John Smith", - "country": "UK", - }, - false, - true, true, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test explicit question - // TODO fix this... - //console.ExpectString("What is your name? John Smith [Automatically accepted existing value]") - //console.ExpectString("Enter a value for country UK [Automatically accepted default value]") - //console.ExpectEOF() - }) + values, _, err := GenerateValuesAsYaml(r, "noAskAndAutoAcceptDefaultsWithExisting.test.schema.json", map[string]interface{}{ + "name": "John Smith", + "country": "UK", + }, false, true, true, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test explicit question + // TODO fix this... + //console.ExpectString("What is your name? John Smith [Automatically accepted existing value]") + //console.ExpectString("Enter a value for country UK [Automatically accepted default value]") + //console.ExpectEOF() + }, nil) assert.NoError(r, err) assert.Equal(r, `country: UK name: John Smith @@ -177,14 +159,10 @@ name: John Smith func TestIgnoreMissingValues(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - values, _, err := GenerateValuesAsYaml(r, "ignoreMissingValues.test.schema.json", make(map[string]interface{}), - false, - true, - false, true, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - console.ExpectEOF() - }) + values, _, err := GenerateValuesAsYaml(r, "ignoreMissingValues.test.schema.json", make(map[string]interface{}), false, true, false, true, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + console.ExpectEOF() + }, nil) assert.NoError(r, err) assert.Equal(r, `{} `, values) @@ -194,14 +172,10 @@ func TestIgnoreMissingValues(t *testing.T) { func TestErrorMissingValues(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - _, _, err := GenerateValuesAsYaml(r, "ignoreMissingValues.test.schema.json", make(map[string]interface{}), - false, - true, - false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - console.ExpectEOF() - }) + _, _, err := GenerateValuesAsYaml(r, "ignoreMissingValues.test.schema.json", make(map[string]interface{}), false, true, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + console.ExpectEOF() + }, nil) assert.Error(t, err) }) } @@ -209,21 +183,19 @@ func TestErrorMissingValues(t *testing.T) { func TestDefaultValues(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - values, _, err := GenerateValuesAsYaml(r, "defaultValues.test.schema.json", make(map[string]interface{}), false, - false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test default value - console.ExpectString("Enter a value for stringValue (UK)") - console.SendLine("") - console.ExpectString("Enter a value for booleanValue (y/N)") - console.SendLine("") - console.ExpectString("Enter a value for numberValue (123.4)") - console.SendLine("") - console.ExpectString("Enter a value for integerValue (123)") - console.SendLine("") - console.ExpectEOF() - }) + values, _, err := GenerateValuesAsYaml(r, "defaultValues.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test default value + console.ExpectString("Enter a value for stringValue (UK)") + console.SendLine("") + console.ExpectString("Enter a value for booleanValue (y/N)") + console.SendLine("") + console.ExpectString("Enter a value for numberValue (123.4)") + console.SendLine("") + console.ExpectString("Enter a value for integerValue (123)") + console.SendLine("") + console.ExpectEOF() + }, nil) assert.NoError(r, err) assert.Equal(r, `booleanValue: false integerValue: 123 @@ -236,17 +208,14 @@ stringValue: UK func TestConstValues(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - values, _, err := GenerateValuesAsYaml(r, "constValues.test.schema.json", make(map[string]interface{}), false, - false, - false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test default value - console.ExpectString("Set stringValue to UK") - console.ExpectString("Set booleanValue to false") - console.ExpectString("Set numberValue to 123.4") - console.ExpectString("Set integerValue to 123") - }) + values, _, err := GenerateValuesAsYaml(r, "constValues.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test default value + console.ExpectString("Set stringValue to UK") + console.ExpectString("Set booleanValue to false") + console.ExpectString("Set numberValue to 123.4") + console.ExpectString("Set integerValue to 123") + }, nil) assert.NoError(r, err) assert.Equal(r, `booleanValue: false integerValue: 123 @@ -259,23 +228,20 @@ stringValue: UK func TestBasicTypesValidation(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - _, _, err := GenerateValuesAsYaml(r, "basicTypesValidation.test.schema.json", make(map[string]interface{}), false, - false, - false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - console.ExpectString("Enter a value for numberValue") - console.SendLine("abc") - console.ExpectString("Sorry, your reply was invalid: unable to convert abc to float64") - console.ExpectString("Enter a value for numberValue") - console.SendLine("123.1") - console.ExpectString("Enter a value for integerValue") - console.SendLine("123.1") - console.ExpectString("Sorry, your reply was invalid: unable to convert 123.1 to int") - console.ExpectString("Enter a value for integerValue") - console.SendLine("123") - console.ExpectEOF() - }) + _, _, err := GenerateValuesAsYaml(r, "basicTypesValidation.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + console.ExpectString("Enter a value for numberValue") + console.SendLine("abc") + console.ExpectString("Sorry, your reply was invalid: unable to convert abc to float64") + console.ExpectString("Enter a value for numberValue") + console.SendLine("123.1") + console.ExpectString("Enter a value for integerValue") + console.SendLine("123.1") + console.ExpectString("Sorry, your reply was invalid: unable to convert 123.1 to int") + console.ExpectString("Enter a value for integerValue") + console.SendLine("123") + console.ExpectEOF() + }, nil) assert.NoError(r, err) }) } @@ -283,21 +249,19 @@ func TestBasicTypesValidation(t *testing.T) { func TestBasicTypes(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - values, _, err := GenerateValuesAsYaml(r, "basicTypes.test.schema.json", make(map[string]interface{}), false, false, - false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test boolean type - console.ExpectString("Enter a value for booleanValue (y/N)") - console.SendLine("Y") - console.ExpectString("Enter a value for numberValue") - console.SendLine("123.4") - console.ExpectString("Enter a value for stringValue") - console.SendLine("hello") - console.ExpectString("Enter a value for integerValue") - console.SendLine("123") - console.ExpectEOF() - }) + values, _, err := GenerateValuesAsYaml(r, "basicTypes.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test boolean type + console.ExpectString("Enter a value for booleanValue (y/N)") + console.SendLine("Y") + console.ExpectString("Enter a value for numberValue") + console.SendLine("123.4") + console.ExpectString("Enter a value for stringValue") + console.SendLine("hello") + console.ExpectString("Enter a value for integerValue") + console.SendLine("123") + console.ExpectEOF() + }, nil) assert.Equal(r, `booleanValue: true integerValue: 123 nullValue: null @@ -311,22 +275,21 @@ stringValue: hello func TestMultipleOf(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - _, _, err := GenerateValuesAsYaml(r, "multipleOf.test.schema.json", make(map[string]interface{}), false, false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test boolean type - console.ExpectString("Enter a value for numberValue") - console.SendLine("11.1") - console.ExpectString("Sorry, your reply was invalid: 11.1 cannot be divided by 10") - console.ExpectString("Enter a value for numberValue") - console.SendLine("10") - console.ExpectString("Enter a value for integerValue") - console.SendLine("12") - console.ExpectString("Sorry, your reply was invalid: 12 cannot be divided by 20") - console.ExpectString("Enter a value for integerValue") - console.SendLine("20") - console.ExpectEOF() - }) + _, _, err := GenerateValuesAsYaml(r, "multipleOf.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test boolean type + console.ExpectString("Enter a value for numberValue") + console.SendLine("11.1") + console.ExpectString("Sorry, your reply was invalid: 11.1 cannot be divided by 10") + console.ExpectString("Enter a value for numberValue") + console.SendLine("10") + console.ExpectString("Enter a value for integerValue") + console.SendLine("12") + console.ExpectString("Sorry, your reply was invalid: 12 cannot be divided by 20") + console.ExpectString("Enter a value for integerValue") + console.SendLine("20") + console.ExpectEOF() + }, nil) assert.NoError(r, err) }) } @@ -334,22 +297,21 @@ func TestMultipleOf(t *testing.T) { func TestMaximum(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - _, _, err := GenerateValuesAsYaml(r, "maximum.test.schema.json", make(map[string]interface{}), false, false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test boolean type - console.ExpectString("Enter a value for numberValue") - console.SendLine("11.1") - console.ExpectString("Sorry, your reply was invalid: 11.1 is not less than or equal to 10.1") - console.ExpectString("Enter a value for numberValue") - console.SendLine("1") - console.ExpectString("Enter a value for integerValue") - console.SendLine("21") - console.ExpectString("Sorry, your reply was invalid: 21 is not less than or equal to 20") - console.ExpectString("Enter a value for integerValue") - console.SendLine("2") - console.ExpectEOF() - }) + _, _, err := GenerateValuesAsYaml(r, "maximum.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test boolean type + console.ExpectString("Enter a value for numberValue") + console.SendLine("11.1") + console.ExpectString("Sorry, your reply was invalid: 11.1 is not less than or equal to 10.1") + console.ExpectString("Enter a value for numberValue") + console.SendLine("1") + console.ExpectString("Enter a value for integerValue") + console.SendLine("21") + console.ExpectString("Sorry, your reply was invalid: 21 is not less than or equal to 20") + console.ExpectString("Enter a value for integerValue") + console.SendLine("2") + console.ExpectEOF() + }, nil) assert.NoError(r, err) }) } @@ -357,23 +319,21 @@ func TestMaximum(t *testing.T) { func TestExclusiveMaximum(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - _, _, err := GenerateValuesAsYaml(r, "exclusiveMaximum.test.schema.json", make(map[string]interface{}), false, false, false, - false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test boolean type - console.ExpectString("Enter a value for numberValue") - console.SendLine("10.1") - console.ExpectString("Sorry, your reply was invalid: 10.1 is not less than 10.1") - console.ExpectString("Enter a value for numberValue") - console.SendLine("1") - console.ExpectString("Enter a value for integerValue") - console.SendLine("20") - console.ExpectString("Sorry, your reply was invalid: 20 is not less than 20") - console.ExpectString("Enter a value for integerValue") - console.SendLine("2") - console.ExpectEOF() - }) + _, _, err := GenerateValuesAsYaml(r, "exclusiveMaximum.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test boolean type + console.ExpectString("Enter a value for numberValue") + console.SendLine("10.1") + console.ExpectString("Sorry, your reply was invalid: 10.1 is not less than 10.1") + console.ExpectString("Enter a value for numberValue") + console.SendLine("1") + console.ExpectString("Enter a value for integerValue") + console.SendLine("20") + console.ExpectString("Sorry, your reply was invalid: 20 is not less than 20") + console.ExpectString("Enter a value for integerValue") + console.SendLine("2") + console.ExpectEOF() + }, nil) assert.NoError(r, err) }) } @@ -381,22 +341,21 @@ func TestExclusiveMaximum(t *testing.T) { func TestMinimum(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - _, _, err := GenerateValuesAsYaml(r, "minimum.test.schema.json", make(map[string]interface{}), false, false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test boolean type - console.ExpectString("Enter a value for numberValue") - console.SendLine("9.1") - console.ExpectString("Sorry, your reply was invalid: 9.1 is not greater than or equal to 10.1") - console.ExpectString("Enter a value for numberValue") - console.SendLine("11") - console.ExpectString("Enter a value for integerValue") - console.SendLine("19") - console.ExpectString("Sorry, your reply was invalid: 19 is not greater than or equal to 20") - console.ExpectString("Enter a value for integerValue") - console.SendLine("21") - console.ExpectEOF() - }) + _, _, err := GenerateValuesAsYaml(r, "minimum.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test boolean type + console.ExpectString("Enter a value for numberValue") + console.SendLine("9.1") + console.ExpectString("Sorry, your reply was invalid: 9.1 is not greater than or equal to 10.1") + console.ExpectString("Enter a value for numberValue") + console.SendLine("11") + console.ExpectString("Enter a value for integerValue") + console.SendLine("19") + console.ExpectString("Sorry, your reply was invalid: 19 is not greater than or equal to 20") + console.ExpectString("Enter a value for integerValue") + console.SendLine("21") + console.ExpectEOF() + }, nil) assert.NoError(r, err) }) } @@ -404,23 +363,21 @@ func TestMinimum(t *testing.T) { func TestExclusiveMinimum(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - _, _, err := GenerateValuesAsYaml(r, "exclusiveMinimum.test.schema.json", make(map[string]interface{}), false, false, false, - false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test boolean type - console.ExpectString("Enter a value for numberValue") - console.SendLine("10.1") - console.ExpectString("Sorry, your reply was invalid: 10.1 is not greater than 10.1") - console.ExpectString("Enter a value for numberValue") - console.SendLine("11") - console.ExpectString("Enter a value for integerValue") - console.SendLine("20") - console.ExpectString("Sorry, your reply was invalid: 20 is not greater than 20") - console.ExpectString("Enter a value for integerValue") - console.SendLine("21") - console.ExpectEOF() - }) + _, _, err := GenerateValuesAsYaml(r, "exclusiveMinimum.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test boolean type + console.ExpectString("Enter a value for numberValue") + console.SendLine("10.1") + console.ExpectString("Sorry, your reply was invalid: 10.1 is not greater than 10.1") + console.ExpectString("Enter a value for numberValue") + console.SendLine("11") + console.ExpectString("Enter a value for integerValue") + console.SendLine("20") + console.ExpectString("Sorry, your reply was invalid: 20 is not greater than 20") + console.ExpectString("Enter a value for integerValue") + console.SendLine("21") + console.ExpectEOF() + }, nil) assert.NoError(r, err) }) } @@ -428,17 +385,16 @@ func TestExclusiveMinimum(t *testing.T) { func TestMaxLength(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - _, _, err := GenerateValuesAsYaml(r, "maxLength.test.schema.json", make(map[string]interface{}), false, false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test boolean type - console.ExpectString("Enter a value for stringValue") - console.SendLine("iamlongerthan10") - console.ExpectString("Sorry, your reply was invalid: value is too long. Max length is 10") - console.ExpectString("Enter a value for stringValue") - console.SendLine("short") - console.ExpectEOF() - }) + _, _, err := GenerateValuesAsYaml(r, "maxLength.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test boolean type + console.ExpectString("Enter a value for stringValue") + console.SendLine("iamlongerthan10") + console.ExpectString("Sorry, your reply was invalid: value is too long. Max length is 10") + console.ExpectString("Enter a value for stringValue") + console.SendLine("short") + console.ExpectEOF() + }, nil) assert.NoError(r, err) }) } @@ -446,17 +402,16 @@ func TestMaxLength(t *testing.T) { func TestMinLength(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - _, _, err := GenerateValuesAsYaml(r, "minLength.test.schema.json", make(map[string]interface{}), false, false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test boolean type - console.ExpectString("Enter a value for stringValue") - console.SendLine("short") - console.ExpectString("Sorry, your reply was invalid: value is too short. Min length is 10") - console.ExpectString("Enter a value for stringValue") - console.SendLine("iamlongerthan10") - console.ExpectEOF() - }) + _, _, err := GenerateValuesAsYaml(r, "minLength.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test boolean type + console.ExpectString("Enter a value for stringValue") + console.SendLine("short") + console.ExpectString("Sorry, your reply was invalid: value is too short. Min length is 10") + console.ExpectString("Enter a value for stringValue") + console.SendLine("iamlongerthan10") + console.ExpectEOF() + }, nil) assert.NoError(r, err) }) } @@ -464,17 +419,16 @@ func TestMinLength(t *testing.T) { func TestPattern(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - _, _, err := GenerateValuesAsYaml(r, "pattern.test.schema.json", make(map[string]interface{}), false, false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test boolean type - console.ExpectString("Enter a value for stringValue") - console.SendLine("HELLO") - console.ExpectString("Sorry, your reply was invalid: HELLO does not match [0-9]") - console.ExpectString("Enter a value for stringValue") - console.SendLine("123") - console.ExpectEOF() - }) + _, _, err := GenerateValuesAsYaml(r, "pattern.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test boolean type + console.ExpectString("Enter a value for stringValue") + console.SendLine("HELLO") + console.ExpectString("Sorry, your reply was invalid: HELLO does not match [0-9]") + console.ExpectString("Enter a value for stringValue") + console.SendLine("123") + console.ExpectEOF() + }, nil) assert.NoError(r, err) }) } @@ -482,17 +436,16 @@ func TestPattern(t *testing.T) { func TestRequired(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - _, _, err := GenerateValuesAsYaml(r, "required.test.schema.json", make(map[string]interface{}), false, false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test boolean type - console.ExpectString("Enter a value for stringValue") - console.SendLine("") - console.ExpectString("Sorry, your reply was invalid: Value is required") - console.ExpectString("Enter a value for stringValue") - console.SendLine("Hello") - console.ExpectEOF() - }) + _, _, err := GenerateValuesAsYaml(r, "required.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test boolean type + console.ExpectString("Enter a value for stringValue") + console.SendLine("") + console.ExpectString("Sorry, your reply was invalid: Value is required") + console.ExpectString("Enter a value for stringValue") + console.SendLine("Hello") + console.ExpectEOF() + }, nil) assert.NoError(r, err) }) } @@ -500,20 +453,19 @@ func TestRequired(t *testing.T) { func TestIfThen(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - values, _, err := GenerateValuesAsYaml(r, "ifThenElse.test.schema.json", make(map[string]interface{}), false, false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - console.ExpectString("Enter a value for enablePersistentStorage") - console.SendLine("Y") - console.ExpectString("Enter a value for databaseConnectionUrl") - console.SendLine("abc") - console.ExpectString("Enter a value for databaseUsername") - console.SendLine("wensleydale") - console.ExpectString("Enter a value for databasePassword") - console.SendLine("cranberries") - console.ExpectString(" ***********") - console.ExpectEOF() - }) + values, _, err := GenerateValuesAsYaml(r, "ifThenElse.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + console.ExpectString("Enter a value for enablePersistentStorage") + console.SendLine("Y") + console.ExpectString("Enter a value for databaseConnectionUrl") + console.SendLine("abc") + console.ExpectString("Enter a value for databaseUsername") + console.SendLine("wensleydale") + console.ExpectString("Enter a value for databasePassword") + console.SendLine("cranberries") + console.ExpectString(" ***********") + console.ExpectEOF() + }, nil) assert.NoError(r, err) assert.Equal(r, fmt.Sprintf(`databaseConnectionUrl: abc databasePassword: vault:%s:databasePassword @@ -526,15 +478,14 @@ enablePersistentStorage: true func TestIfElse(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - values, _, err := GenerateValuesAsYaml(r, "ifThenElse.test.schema.json", make(map[string]interface{}), false, false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - console.ExpectString("Enter a value for enablePersistentStorage") - console.SendLine("N") - console.ExpectString("Enter a value for enableInMemoryDB") - console.SendLine("N") - console.ExpectEOF() - }) + values, _, err := GenerateValuesAsYaml(r, "ifThenElse.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + console.ExpectString("Enter a value for enablePersistentStorage") + console.SendLine("N") + console.ExpectString("Enter a value for enableInMemoryDB") + console.SendLine("N") + console.ExpectEOF() + }, nil) assert.NoError(r, err) assert.Equal(r, `enableInMemoryDB: false enablePersistentStorage: false @@ -545,17 +496,16 @@ enablePersistentStorage: false func TestIfElseNested(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - values, _, err := GenerateValuesAsYaml(r, "ifThenElseNested.test.schema.json", make(map[string]interface{}), false, false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - console.ExpectString("Enter a value for enablePersistentStorage") - console.SendLine("N") - console.ExpectString("Enter a value for enableInMemoryDB") - console.SendLine("Y") - console.ExpectString("Enter a value for nestedString") - console.SendLine("Test") - console.ExpectEOF() - }) + values, _, err := GenerateValuesAsYaml(r, "ifThenElseNested.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + console.ExpectString("Enter a value for enablePersistentStorage") + console.SendLine("N") + console.ExpectString("Enter a value for enableInMemoryDB") + console.SendLine("Y") + console.ExpectString("Enter a value for nestedString") + console.SendLine("Test") + console.ExpectEOF() + }, nil) assert.NoError(r, err) assert.Equal(r, `nestedObject: enableInMemoryDB: true @@ -568,13 +518,12 @@ func TestIfElseNested(t *testing.T) { func TestIfElseWithDefaults(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - values, _, err := GenerateValuesAsYaml(r, "ifThenElse.test.schema.json", make(map[string]interface{}), false, false, true, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - console.ExpectString("Enter a value for enablePersistentStorage") - console.SendLine("N") - console.ExpectEOF() - }) + values, _, err := GenerateValuesAsYaml(r, "ifThenElse.test.schema.json", make(map[string]interface{}), false, false, true, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + console.ExpectString("Enter a value for enablePersistentStorage") + console.SendLine("N") + console.ExpectEOF() + }, nil) assert.NoError(r, err) assert.Equal(r, `enableInMemoryDB: true enablePersistentStorage: false @@ -585,24 +534,23 @@ enablePersistentStorage: false func TestAllOf(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - values, _, err := GenerateValuesAsYaml(r, "AllOfIf.test.schema.json", make(map[string]interface{}), false, false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - console.ExpectString("Enter a value for enablePersistentStorage") - console.SendLine("Y") - console.ExpectString("Enter a value for databaseConnectionUrl") - console.SendLine("abc") - console.ExpectString("Enter a value for databaseUsername") - console.SendLine("wensleydale") - console.ExpectString("Enter a value for databasePassword") - console.SendLine("cranberries") - console.ExpectString(" ***********") - console.ExpectString("Enter a value for enableCheese") - console.SendLine("Y") - console.ExpectString("Enter a value for cheeseType") - console.SendLine("Stilton") - console.ExpectEOF() - }) + values, _, err := GenerateValuesAsYaml(r, "AllOfIf.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + console.ExpectString("Enter a value for enablePersistentStorage") + console.SendLine("Y") + console.ExpectString("Enter a value for databaseConnectionUrl") + console.SendLine("abc") + console.ExpectString("Enter a value for databaseUsername") + console.SendLine("wensleydale") + console.ExpectString("Enter a value for databasePassword") + console.SendLine("cranberries") + console.ExpectString(" ***********") + console.ExpectString("Enter a value for enableCheese") + console.SendLine("Y") + console.ExpectString("Enter a value for cheeseType") + console.SendLine("Stilton") + console.ExpectEOF() + }, nil) assert.NoError(r, err) assert.Equal(r, fmt.Sprintf(`cheeseType: Stilton databaseConnectionUrl: abc @@ -617,24 +565,23 @@ enablePersistentStorage: true func TestAllOfThen(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - values, _, err := GenerateValuesAsYaml(r, "AllOfIf.test.schema.json", make(map[string]interface{}), false, false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - console.ExpectString("Enter a value for enablePersistentStorage") - console.SendLine("Y") - console.ExpectString("Enter a value for databaseConnectionUrl") - console.SendLine("abc") - console.ExpectString("Enter a value for databaseUsername") - console.SendLine("wensleydale") - console.ExpectString("Enter a value for databasePassword") - console.SendLine("cranberries") - console.ExpectString(" ***********") - console.ExpectString("Enter a value for enableCheese") - console.SendLine("N") - console.ExpectString("Enter a value for iDontLikeCheese") - console.SendLine("Y") - console.ExpectEOF() - }) + values, _, err := GenerateValuesAsYaml(r, "AllOfIf.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + console.ExpectString("Enter a value for enablePersistentStorage") + console.SendLine("Y") + console.ExpectString("Enter a value for databaseConnectionUrl") + console.SendLine("abc") + console.ExpectString("Enter a value for databaseUsername") + console.SendLine("wensleydale") + console.ExpectString("Enter a value for databasePassword") + console.SendLine("cranberries") + console.ExpectString(" ***********") + console.ExpectString("Enter a value for enableCheese") + console.SendLine("N") + console.ExpectString("Enter a value for iDontLikeCheese") + console.SendLine("Y") + console.ExpectEOF() + }, nil) assert.NoError(r, err) assert.Equal(r, fmt.Sprintf(`databaseConnectionUrl: abc databasePassword: vault:%s:databasePassword @@ -649,21 +596,20 @@ iDontLikeCheese: true func TestMinProperties(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - _, _, err := GenerateValuesAsYaml(r, "minProperties.test.schema.json", make(map[string]interface{}), false, false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test boolean type - console.ExpectString("Enter a value for stringValue") - console.SendLine("") - console.ExpectString("Enter a value for stringValue1") - console.SendLine("") - console.ExpectString("Sorry, your reply was invalid: nestedObject has less than 1 items, has []") - console.ExpectString("Enter a value for stringValue") - console.SendLine("abc") - console.ExpectString("Enter a value for stringValue1") - console.SendLine("def") - console.ExpectEOF() - }) + _, _, err := GenerateValuesAsYaml(r, "minProperties.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test boolean type + console.ExpectString("Enter a value for stringValue") + console.SendLine("") + console.ExpectString("Enter a value for stringValue1") + console.SendLine("") + console.ExpectString("Sorry, your reply was invalid: nestedObject has less than 1 items, has []") + console.ExpectString("Enter a value for stringValue") + console.SendLine("abc") + console.ExpectString("Enter a value for stringValue1") + console.SendLine("def") + console.ExpectEOF() + }, nil) assert.NoError(r, err) }) } @@ -671,22 +617,21 @@ func TestMinProperties(t *testing.T) { func TestMaxProperties(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - _, _, err := GenerateValuesAsYaml(r, "maxProperties.test.schema.json", make(map[string]interface{}), false, false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test boolean type - console.ExpectString("Enter a value for stringValue") - console.SendLine("abc") - console.ExpectString("Enter a value for stringValue1") - console.SendLine("def") - console.ExpectString("Sorry, your reply was invalid: nestedObject has more than 1 items, " + - "has [stringValue stringValue1]") - console.ExpectString("Enter a value for stringValue") - console.SendLine("abc") - console.ExpectString("Enter a value for stringValue1") - console.SendLine("") - console.ExpectEOF() - }) + _, _, err := GenerateValuesAsYaml(r, "maxProperties.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test boolean type + console.ExpectString("Enter a value for stringValue") + console.SendLine("abc") + console.ExpectString("Enter a value for stringValue1") + console.SendLine("def") + console.ExpectString("Sorry, your reply was invalid: nestedObject has more than 1 items, " + + "has [stringValue stringValue1]") + console.ExpectString("Enter a value for stringValue") + console.SendLine("abc") + console.ExpectString("Enter a value for stringValue1") + console.SendLine("") + console.ExpectEOF() + }, nil) assert.NoError(r, err) }) } @@ -694,18 +639,17 @@ func TestMaxProperties(t *testing.T) { func TestDateTime(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - _, _, err := GenerateValuesAsYaml(r, "dateTime.test.schema.json", make(map[string]interface{}), false, false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test boolean type - console.ExpectString("Enter a value for dateTimeValue") - console.SendLine("abc") - console.ExpectString("Sorry, your reply was invalid: abc is not a RFC 3339 date-time formatted string, " + - "it should be like 2006-01-02T15:04:05Z07:00") - console.ExpectString("Enter a value for dateTimeValue") - console.SendLine("2006-01-02T15:04:05-07:00") - console.ExpectEOF() - }) + _, _, err := GenerateValuesAsYaml(r, "dateTime.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test boolean type + console.ExpectString("Enter a value for dateTimeValue") + console.SendLine("abc") + console.ExpectString("Sorry, your reply was invalid: abc is not a RFC 3339 date-time formatted string, " + + "it should be like 2006-01-02T15:04:05Z07:00") + console.ExpectString("Enter a value for dateTimeValue") + console.SendLine("2006-01-02T15:04:05-07:00") + console.ExpectEOF() + }, nil) assert.NoError(r, err) }) } @@ -713,18 +657,17 @@ func TestDateTime(t *testing.T) { func TestDate(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - _, _, err := GenerateValuesAsYaml(r, "date.test.schema.json", make(map[string]interface{}), false, false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test boolean type - console.ExpectString("Enter a value for dateValue") - console.SendLine("abc") - console.ExpectString("Sorry, your reply was invalid: abc is not a RFC 3339 full-date formatted string, " + - "it should be like 2006-01-02") - console.ExpectString("Enter a value for dateValue") - console.SendLine("2006-01-02") - console.ExpectEOF() - }) + _, _, err := GenerateValuesAsYaml(r, "date.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test boolean type + console.ExpectString("Enter a value for dateValue") + console.SendLine("abc") + console.ExpectString("Sorry, your reply was invalid: abc is not a RFC 3339 full-date formatted string, " + + "it should be like 2006-01-02") + console.ExpectString("Enter a value for dateValue") + console.SendLine("2006-01-02") + console.ExpectEOF() + }, nil) assert.NoError(r, err) }) } @@ -732,18 +675,17 @@ func TestDate(t *testing.T) { func TestTime(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - _, _, err := GenerateValuesAsYaml(r, "time.test.schema.json", make(map[string]interface{}), false, false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test boolean type - console.ExpectString("Enter a value for timeValue") - console.SendLine("abc") - console.ExpectString("Sorry, your reply was invalid: abc is not a RFC 3339 full-time formatted string, " + - "it should be like 15:04:05Z07:00") - console.ExpectString("Enter a value for timeValue") - console.SendLine("15:04:05-07:00") - console.ExpectEOF() - }) + _, _, err := GenerateValuesAsYaml(r, "time.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test boolean type + console.ExpectString("Enter a value for timeValue") + console.SendLine("abc") + console.ExpectString("Sorry, your reply was invalid: abc is not a RFC 3339 full-time formatted string, " + + "it should be like 15:04:05Z07:00") + console.ExpectString("Enter a value for timeValue") + console.SendLine("15:04:05-07:00") + console.ExpectEOF() + }, nil) assert.NoError(r, err) }) } @@ -751,15 +693,13 @@ func TestTime(t *testing.T) { func TestPassword(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - values, vaultClient, err := GenerateValuesAsYaml(r, "password.test.schema.json", make(map[string]interface{}), false, - false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test boolean type - console.ExpectString("Enter a value for passwordValue") - console.SendLine("abc") - console.ExpectEOF() - }) + values, vaultClient, err := GenerateValuesAsYaml(r, "password.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test boolean type + console.ExpectString("Enter a value for passwordValue") + console.SendLine("abc") + console.ExpectEOF() + }, nil) assert.Equal(r, fmt.Sprintf(`passwordValue: vault:%s:passwordValue `, vaultBasePath), values) secrets, err := vaultClient.Read(vaultBasePath) @@ -772,16 +712,13 @@ func TestPassword(t *testing.T) { func TestToken(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - values, vaultClient, err := GenerateValuesAsYaml(r, "token.test.schema.json", make(map[string]interface{}), false, - false, - false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test boolean type - console.ExpectString("Enter a value for tokenValue") - console.SendLine("abc") - console.ExpectEOF() - }) + values, vaultClient, err := GenerateValuesAsYaml(r, "token.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test boolean type + console.ExpectString("Enter a value for tokenValue") + console.SendLine("abc") + console.ExpectEOF() + }, nil) assert.Equal(r, fmt.Sprintf(`tokenValue: vault:%s:tokenValue `, vaultBasePath), values) secrets, err := vaultClient.Read(vaultBasePath) @@ -803,10 +740,9 @@ func TestGeneratedToken(t *testing.T) { console.ExpectString("Enter a value for tokenValue") console.SendLine("") console.ExpectEOF() - }) + }, nil) assert.Equal(r, fmt.Sprintf(`tokenValue: vault:%s:tokenValue `, vaultBasePath), values) - secrets, err := vaultClient.Read(vaultBasePath) assert.NoError(t, err) assert.Len(t, secrets["tokenValue"], 20) @@ -814,22 +750,43 @@ func TestGeneratedToken(t *testing.T) { }) } +func TestExistingToken(t *testing.T) { + tests.SkipForWindows(t, "go-expect does not work on windows") + tests.Retry(t, 1, time.Second*10, func(r *tests.R) { + vaultClient := fake.NewFakeVaultClient() + vaultClient.Write(vaultBasePath, map[string]interface{}{ + "tokenValue": "abc", + }) + values, _, err := GenerateValuesAsYaml(r, "token.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test boolean type + console.ExpectString("Enter a value for tokenValue *** [Automatically accepted existing value]") + console.ExpectEOF() + }, vaultClient) + + assert.Equal(r, fmt.Sprintf(`tokenValue: vault:%s:tokenValue +`, vaultBasePath), values) + secrets, err := vaultClient.Read(vaultBasePath) + assert.NoError(t, err) + assert.Equal(r, "abc", secrets["tokenValue"]) + assert.NoError(r, err) + }) +} + func TestEmail(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - _, _, err := GenerateValuesAsYaml(r, "email.test.schema.json", make(map[string]interface{}), false, false, false, - false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test boolean type - console.ExpectString("Enter a value for emailValue") - console.SendLine("abc") - console.ExpectString("Sorry, your reply was invalid: abc is not a RFC 5322 address, " + - "it should be like Barry Gibb ") - console.ExpectString("Enter a value for emailValue") - console.SendLine("Maurice Gibb ") - console.ExpectEOF() - }) + _, _, err := GenerateValuesAsYaml(r, "email.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test boolean type + console.ExpectString("Enter a value for emailValue") + console.SendLine("abc") + console.ExpectString("Sorry, your reply was invalid: abc is not a RFC 5322 address, " + + "it should be like Barry Gibb ") + console.ExpectString("Enter a value for emailValue") + console.SendLine("Maurice Gibb ") + console.ExpectEOF() + }, nil) assert.NoError(r, err) }) } @@ -837,18 +794,17 @@ func TestEmail(t *testing.T) { func TestIdnEmail(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - _, _, err := GenerateValuesAsYaml(r, "idnemail.test.schema.json", make(map[string]interface{}), false, false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test boolean type - console.ExpectString("Enter a value for emailValue") - console.SendLine("abc") - console.ExpectString("Sorry, your reply was invalid: abc is not a RFC 5322 address, " + - "it should be like Barry Gibb ") - console.ExpectString("Enter a value for emailValue") - console.SendLine("Maurice Gibb ") - console.ExpectEOF() - }) + _, _, err := GenerateValuesAsYaml(r, "idnemail.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test boolean type + console.ExpectString("Enter a value for emailValue") + console.SendLine("abc") + console.ExpectString("Sorry, your reply was invalid: abc is not a RFC 5322 address, " + + "it should be like Barry Gibb ") + console.ExpectString("Enter a value for emailValue") + console.SendLine("Maurice Gibb ") + console.ExpectEOF() + }, nil) assert.NoError(r, err) }) } @@ -856,18 +812,17 @@ func TestIdnEmail(t *testing.T) { func TestHostname(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - _, _, err := GenerateValuesAsYaml(r, "hostname.test.schema.json", make(map[string]interface{}), false, false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test boolean type - console.ExpectString("Enter a value for hostnameValue") - console.SendLine("*****") - console.ExpectString("Sorry, your reply was invalid: ***** is not a RFC 1034 hostname, " + - "it should be like example.com") - console.ExpectString("Enter a value for hostnameValue") - console.SendLine("example.com") - console.ExpectEOF() - }) + _, _, err := GenerateValuesAsYaml(r, "hostname.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test boolean type + console.ExpectString("Enter a value for hostnameValue") + console.SendLine("*****") + console.ExpectString("Sorry, your reply was invalid: ***** is not a RFC 1034 hostname, " + + "it should be like example.com") + console.ExpectString("Enter a value for hostnameValue") + console.SendLine("example.com") + console.ExpectEOF() + }, nil) assert.NoError(r, err) }) } @@ -875,18 +830,17 @@ func TestHostname(t *testing.T) { func TestIdnHostname(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - _, _, err := GenerateValuesAsYaml(r, "idnhostname.test.schema.json", make(map[string]interface{}), false, false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test boolean type - console.ExpectString("Enter a value for hostnameValue") - console.SendLine("*****") - console.ExpectString("Sorry, your reply was invalid: ***** is not a RFC 1034 hostname, " + - "it should be like example.com") - console.ExpectString("Enter a value for hostnameValue") - console.SendLine("example.com") - console.ExpectEOF() - }) + _, _, err := GenerateValuesAsYaml(r, "idnhostname.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test boolean type + console.ExpectString("Enter a value for hostnameValue") + console.SendLine("*****") + console.ExpectString("Sorry, your reply was invalid: ***** is not a RFC 1034 hostname, " + + "it should be like example.com") + console.ExpectString("Enter a value for hostnameValue") + console.SendLine("example.com") + console.ExpectEOF() + }, nil) assert.NoError(r, err) }) } @@ -894,18 +848,17 @@ func TestIdnHostname(t *testing.T) { func TestIpv4(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - _, _, err := GenerateValuesAsYaml(r, "ipv4.test.schema.json", make(map[string]interface{}), false, false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test boolean type - console.ExpectString("Enter a value for ipv4Value") - console.SendLine("abc") - console.ExpectString("Sorry, your reply was invalid: abc is not a RFC 2673 IPv4 Address, " + - "it should be like 127.0.0.1") - console.ExpectString("Enter a value for ipv4Value") - console.SendLine("127.0.0.1") - console.ExpectEOF() - }) + _, _, err := GenerateValuesAsYaml(r, "ipv4.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test boolean type + console.ExpectString("Enter a value for ipv4Value") + console.SendLine("abc") + console.ExpectString("Sorry, your reply was invalid: abc is not a RFC 2673 IPv4 Address, " + + "it should be like 127.0.0.1") + console.ExpectString("Enter a value for ipv4Value") + console.SendLine("127.0.0.1") + console.ExpectEOF() + }, nil) assert.NoError(r, err) }) } @@ -913,18 +866,17 @@ func TestIpv4(t *testing.T) { func TestIpv6(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - _, _, err := GenerateValuesAsYaml(r, "ipv6.test.schema.json", make(map[string]interface{}), false, false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test boolean type - console.ExpectString("Enter a value for ipv6Value") - console.SendLine("abc") - console.ExpectString("Sorry, your reply was invalid: abc is not a RFC 4291 IPv6 address, " + - "it should be like ::1") - console.ExpectString("Enter a value for ipv6Value") - console.SendLine("::1") - console.ExpectEOF() - }) + _, _, err := GenerateValuesAsYaml(r, "ipv6.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test boolean type + console.ExpectString("Enter a value for ipv6Value") + console.SendLine("abc") + console.ExpectString("Sorry, your reply was invalid: abc is not a RFC 4291 IPv6 address, " + + "it should be like ::1") + console.ExpectString("Enter a value for ipv6Value") + console.SendLine("::1") + console.ExpectEOF() + }, nil) assert.NoError(r, err) }) } @@ -932,17 +884,16 @@ func TestIpv6(t *testing.T) { func TestUri(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - _, _, err := GenerateValuesAsYaml(r, "uri.test.schema.json", make(map[string]interface{}), false, false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test boolean type - console.ExpectString("Enter a value for uriValue") - console.SendLine("*****") - console.ExpectString("Sorry, your reply was invalid: ***** is not a RFC 3986 URI") - console.ExpectString("Enter a value for uriValue") - console.SendLine("https://example.com") - console.ExpectEOF() - }) + _, _, err := GenerateValuesAsYaml(r, "uri.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test boolean type + console.ExpectString("Enter a value for uriValue") + console.SendLine("*****") + console.ExpectString("Sorry, your reply was invalid: ***** is not a RFC 3986 URI") + console.ExpectString("Enter a value for uriValue") + console.SendLine("https://example.com") + console.ExpectEOF() + }, nil) assert.NoError(r, err) }) } @@ -950,17 +901,16 @@ func TestUri(t *testing.T) { func TestUriReference(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - _, _, err := GenerateValuesAsYaml(r, "uriReference.test.schema.json", make(map[string]interface{}), false, false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test boolean type - console.ExpectString("Enter a value for uriReferenceValue") - console.SendLine("http$$://foo") - console.ExpectString("Sorry, your reply was invalid: http$$://foo is not a RFC 3986 URI reference") - console.ExpectString("Enter a value for uriReferenceValue") - console.SendLine("../resource.txt") - console.ExpectEOF() - }) + _, _, err := GenerateValuesAsYaml(r, "uriReference.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test boolean type + console.ExpectString("Enter a value for uriReferenceValue") + console.SendLine("http$$://foo") + console.ExpectString("Sorry, your reply was invalid: http$$://foo is not a RFC 3986 URI reference") + console.ExpectString("Enter a value for uriReferenceValue") + console.SendLine("../resource.txt") + console.ExpectEOF() + }, nil) assert.NoError(r, err) }) } @@ -968,31 +918,31 @@ func TestUriReference(t *testing.T) { func TestJSONPointer(t *testing.T) { tests.SkipForWindows(t, "go-expect does not work on windows") tests.Retry(t, 5, time.Second*10, func(r *tests.R) { - _, _, err := GenerateValuesAsYaml(r, "jsonPointer.test.schema.json", make(map[string]interface{}), false, false, false, false, - func(console *tests.ConsoleWrapper, donec chan struct{}) { - defer close(donec) - // Test boolean type - console.ExpectString("Enter a value for jsonPointerValue") - console.SendLine("~") - console.ExpectString("Sorry, your reply was invalid: ~ is not a RFC 6901 JSON pointer") - console.ExpectString("Enter a value for jsonPointerValue") - console.SendLine("/abc") - console.ExpectEOF() - }) + _, _, err := GenerateValuesAsYaml(r, "jsonPointer.test.schema.json", make(map[string]interface{}), false, false, false, false, func(console *tests.ConsoleWrapper, donec chan struct{}) { + defer close(donec) + // Test boolean type + console.ExpectString("Enter a value for jsonPointerValue") + console.SendLine("~") + console.ExpectString("Sorry, your reply was invalid: ~ is not a RFC 6901 JSON pointer") + console.ExpectString("Enter a value for jsonPointerValue") + console.SendLine("/abc") + console.ExpectEOF() + }, nil) assert.NoError(r, err) }) } -func GenerateValuesAsYaml(r *tests.R, schemaName string, existingValues map[string]interface{}, - askExisting bool, noAsk bool, autoAcceptDefaults bool, ignoreMissingValues bool, answerQuestions func( - console *tests. - ConsoleWrapper, donec chan struct{})) (string, vault.Client, error) { +func GenerateValuesAsYaml(r *tests.R, schemaName string, existingValues map[string]interface{}, askExisting bool, noAsk bool, autoAcceptDefaults bool, ignoreMissingValues bool, answerQuestions func( + console *tests.ConsoleWrapper, donec chan struct{}), vaultClient vault.Client) (string, vault.Client, error) { //t.Parallel() console := tests.NewTerminal(r, &timeout) defer console.Cleanup() - vaultClient := fake.NewFakeVaultClient() + if vaultClient == nil { + vaultClient = fake.NewFakeVaultClient() + } + options := surveyutils.JSONSchemaOptions{ Out: console.Out, In: console.In, @@ -1001,7 +951,7 @@ func GenerateValuesAsYaml(r *tests.R, schemaName string, existingValues map[stri AutoAcceptDefaults: autoAcceptDefaults, NoAsk: noAsk, IgnoreMissingValues: ignoreMissingValues, - VaultClient: &vaultClient, + VaultClient: vaultClient, VaultBasePath: vaultBasePath, VaultScheme: "vault", } @@ -1021,5 +971,5 @@ func GenerateValuesAsYaml(r *tests.R, schemaName string, existingValues map[stri consoleOut := expect.StripTrailingEmptyLines(console.CurrentState()) r.Logf(consoleOut) assert.NoError(r, err) - return string(yaml), &vaultClient, runErr + return string(yaml), vaultClient, runErr } diff --git a/pkg/surveyutils/test_data/ingoreMissingValues.test.schema.json b/pkg/surveyutils/test_data/ingoreMissingValues.test.schema.json deleted file mode 100644 index 06e8dee1c7..0000000000 --- a/pkg/surveyutils/test_data/ingoreMissingValues.test.schema.json +++ /dev/null @@ -1,14 +0,0 @@ - -{ - "$id": "https:/jenkins-x.io/tests/descriptionAndTitle.schema.json", - "$schema": "http://json-schema.org/draft-07/schema#", - "description": "test values.yaml", - "type": "object", - "properties": { - "name": { - "type": "string", - "title": "What is your name?", - "description": "Enter your name" - } - } -} \ No newline at end of file diff --git a/pkg/vault/fake/client.go b/pkg/vault/fake/client.go index 2b7d33245a..b8463c71f3 100644 --- a/pkg/vault/fake/client.go +++ b/pkg/vault/fake/client.go @@ -31,14 +31,14 @@ func NewFakeVaultClient() FakeVaultClient { } // Write a secret to vault -func (f *FakeVaultClient) Write(secretName string, data map[string]interface{}) (map[string]interface{}, error) { +func (f FakeVaultClient) Write(secretName string, data map[string]interface{}) (map[string]interface{}, error) { fmt.Printf("fakeClient: storing key at %s data: %#v\n", secretName, data) f.Data[secretName] = data return data, nil } // WriteObject a secret to vault -func (f *FakeVaultClient) WriteObject(secretName string, secret interface{}) (map[string]interface{}, error) { +func (f FakeVaultClient) WriteObject(secretName string, secret interface{}) (map[string]interface{}, error) { payload, err := util.ToMapStringInterfaceFromStruct(secret) if err != nil { return nil, errors.WithStack(err) @@ -47,7 +47,7 @@ func (f *FakeVaultClient) WriteObject(secretName string, secret interface{}) (ma } // WriteYaml a secret to vault -func (f *FakeVaultClient) WriteYaml(secretName string, y string) (map[string]interface{}, error) { +func (f FakeVaultClient) WriteYaml(secretName string, y string) (map[string]interface{}, error) { data := base64.StdEncoding.EncodeToString([]byte(y)) secretMap := map[string]interface{}{ yamlDataKey: data, @@ -56,7 +56,7 @@ func (f *FakeVaultClient) WriteYaml(secretName string, y string) (map[string]int } // List the secrets in vault -func (f *FakeVaultClient) List(path string) ([]string, error) { +func (f FakeVaultClient) List(path string) ([]string, error) { secretNames := make([]string, 0) for _, s := range f.Data[path] { if orig, ok := s.(string); ok { @@ -67,7 +67,7 @@ func (f *FakeVaultClient) List(path string) ([]string, error) { } // Read a secret from vault -func (f *FakeVaultClient) Read(secretName string) (map[string]interface{}, error) { +func (f FakeVaultClient) Read(secretName string) (map[string]interface{}, error) { if answer, ok := f.Data[secretName]; !ok { return nil, errors.Errorf("secret does not exist at key %s", secretName) } else { @@ -76,7 +76,7 @@ func (f *FakeVaultClient) Read(secretName string) (map[string]interface{}, error } // ReadObject a secret from vault -func (f *FakeVaultClient) ReadObject(secretName string, secret interface{}) error { +func (f FakeVaultClient) ReadObject(secretName string, secret interface{}) error { m, err := f.Read(secretName) if err != nil { return errors.Wrapf(err, "reading the secret %q from vault", secretName) @@ -90,7 +90,7 @@ func (f *FakeVaultClient) ReadObject(secretName string, secret interface{}) erro } // ReadYaml a secret from vault -func (f *FakeVaultClient) ReadYaml(secretName string) (string, error) { +func (f FakeVaultClient) ReadYaml(secretName string) (string, error) { secretMap, err := f.Read(secretName) if err != nil { return "", errors.Wrapf(err, "reading secret %q from vault", secretName) @@ -111,7 +111,7 @@ func (f *FakeVaultClient) ReadYaml(secretName string) (string, error) { } // Config shows the vault config -func (f *FakeVaultClient) Config() (vaultURL url.URL, vaultToken string, err error) { +func (f FakeVaultClient) Config() (vaultURL url.URL, vaultToken string, err error) { u, err := url.Parse("https://fake.vault") if err != nil { return *u, "", errors.WithStack(err) @@ -120,6 +120,6 @@ func (f *FakeVaultClient) Config() (vaultURL url.URL, vaultToken string, err err } // ReplaceURIs corrects the URIs -func (f *FakeVaultClient) ReplaceURIs(text string) (string, error) { +func (f FakeVaultClient) ReplaceURIs(text string) (string, error) { return secreturl.ReplaceURIs(text, f, vaultURIRegex, "vault:") }