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

Map sensitive to writeOnly when converting to bundle.json #524

Merged
merged 1 commit into from
Aug 19, 2019
Merged
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
16 changes: 16 additions & 0 deletions pkg/cnab/config_adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ func (c *ManifestConverter) generateBundleParameters(defs *definition.Definition
p.Required = true
}

if param.Sensitive {
param.Schema.WriteOnly = toBool(true)
}

if param.Destination != nil {
p.Destination = &bundle.Location{
EnvironmentVariable: param.Destination.EnvironmentVariable,
Expand Down Expand Up @@ -176,6 +180,10 @@ func (c *ManifestConverter) generateBundleOutputs(defs *definition.Definitions)
Path: filepath.Join(config.BundleOutputsDir, output.Name),
}

if output.Sensitive {
output.Schema.WriteOnly = toBool(true)
}

// Only set definition if it doesn't already exist
// (Both Params and Outputs may reference same Definition)
if _, exists := (*defs)[output.Name]; !exists {
Expand Down Expand Up @@ -269,3 +277,11 @@ func (c *ManifestConverter) generateDependencies() *extensions.Dependencies {

return deps
}

func toBool(value bool) *bool {
return &value
}

func toFloat64(v float64) *float64 {
return &v
}
32 changes: 22 additions & 10 deletions pkg/cnab/config_adapter/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ func TestManifestConverter_ToBundle(t *testing.T) {
assert.Nil(t, bun.Outputs, "expected outputs section not to exist in generated bundle")
}

func makefloat64(v float64) *float64 {
return &v
}

func TestManifestConverter_generateBundleParametersSchema(t *testing.T) {
c := config.NewTestConfig(t)
c.TestContext.AddTestFile("testdata/porter-with-parameters.yaml", config.Name)
Expand Down Expand Up @@ -78,8 +74,8 @@ func TestManifestConverter_generateBundleParametersSchema(t *testing.T) {
definition.Schema{
Type: "integer",
Default: 1,
Minimum: makefloat64(0),
Maximum: makefloat64(10),
Minimum: toFloat64(0),
Maximum: toFloat64(10),
},
},
{"anumber",
Expand All @@ -92,8 +88,8 @@ func TestManifestConverter_generateBundleParametersSchema(t *testing.T) {
definition.Schema{
Type: "number",
Default: 0.5,
ExclusiveMinimum: makefloat64(0),
ExclusiveMaximum: makefloat64(1),
ExclusiveMinimum: toFloat64(0),
ExclusiveMaximum: toFloat64(1),
},
},
{
Expand Down Expand Up @@ -121,8 +117,8 @@ func TestManifestConverter_generateBundleParametersSchema(t *testing.T) {
},
definition.Schema{
Type: "string",
MinLength: makefloat64(1),
MaxLength: makefloat64(10),
MinLength: toFloat64(1),
MaxLength: toFloat64(10),
},
},
{
Expand Down Expand Up @@ -154,6 +150,20 @@ func TestManifestConverter_generateBundleParametersSchema(t *testing.T) {
Type: "boolean",
},
},
{
"sensitive",
bundle.Parameter{
Definition: "sensitive",
Destination: &bundle.Location{
EnvironmentVariable: "SENSITIVE",
},
Required: true,
},
definition.Schema{
Type: "string",
WriteOnly: toBool(true),
},
},
}

for _, tc := range testcases {
Expand Down Expand Up @@ -290,6 +300,7 @@ func TestManifestConverter_generateBundleOutputs(t *testing.T) {
Type: "string",
Description: "Description of output1",
},
Sensitive: true,
},
{
Name: "output2",
Expand Down Expand Up @@ -329,6 +340,7 @@ func TestManifestConverter_generateBundleOutputs(t *testing.T) {
"output1": &definition.Schema{
Type: "string",
Description: "Description of output1",
WriteOnly: toBool(true),
},
"output2": &definition.Schema{
Type: "boolean",
Expand Down
3 changes: 3 additions & 0 deletions pkg/cnab/config_adapter/testdata/porter-with-parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ parameters:
type: boolean
applyTo:
- install
- name: sensitive
type: string
sensitive: true

mixins:
- exec
Expand Down