Skip to content

Commit

Permalink
put #rquired on required lines
Browse files Browse the repository at this point in the history
- also first pass at type templating

[#155568214]

Signed-off-by: Josh Zarrabi <jzarrabi@pivotal.io>
  • Loading branch information
rizwanreza authored and joshzarrabi committed Mar 30, 2018
1 parent ed60b8f commit d4ac625
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion acceptance/config_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/onsi/gomega/gexec"
)

var _ = Describe("config-template command", func() {
var _ = FDescribe("config-template command", func() {
var (
product *os.File
)
Expand Down
2 changes: 1 addition & 1 deletion acceptance/fixtures/metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ form_types:
property_blueprints:
- name: with_default
configurable: true
optional: true
optional: false
type: string
default: "some-default"
- name: without_default
Expand Down
32 changes: 29 additions & 3 deletions commands/config_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package commands

import (
"fmt"
"strings"

"github.com/pivotal-cf/jhanda"
"github.com/pivotal-cf/kiln/proofing"
Expand Down Expand Up @@ -68,8 +69,17 @@ func (ct ConfigTemplate) Execute(args []string) error {
productProperties := map[string]interface{}{}
for _, pb := range template.AllPropertyBlueprints() {
if pb.Configurable {
productProperties[pb.Property] = map[string]interface{}{
"value": pb.Default,
if pb.Type == "simple_credentials" {
productProperties[pb.Property] = map[string]map[string]string{
"value": map[string]string{
"identity": "",
"password": "",
},
}
} else {
productProperties[pb.Property] = map[string]interface{}{
"value": pb.Default,
}
}
}
}
Expand All @@ -83,7 +93,23 @@ func (ct ConfigTemplate) Execute(args []string) error {
return fmt.Errorf("could not marshal config template: %s", err) // NOTE: this cannot happen
}

ct.logger.Println(string(output))
ct.logger.Println(concatenateRequiredProperties(output, template))

return nil
}

func concatenateRequiredProperties(output []byte, template proofing.ProductTemplate) string {
lines := strings.Split(string(output), "\n")
for i, line := range lines {
for _, pb := range template.AllPropertyBlueprints() {
propertyName := strings.TrimSpace(strings.Split(line, ":")[0])
if pb.Property == propertyName {
if pb.Required {
lines[i+1] = lines[i+1] + " # required"
}
}
}
}

return strings.Join(lines, "\n")
}
81 changes: 80 additions & 1 deletion commands/config_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package commands_test

import (
"errors"
"strings"

"github.com/pivotal-cf/jhanda"
"github.com/pivotal-cf/om/commands"
Expand All @@ -28,7 +29,7 @@ property_blueprints:
- name: some-name
type: boolean
default: true
optional: false
optional: true
configurable: true
`),
}, nil)
Expand All @@ -53,6 +54,84 @@ product-properties:
.properties.some-name:
value: true`)))
})

Context("when a property is optional", func() {
It("does not write '# required' next to the property", func() {
err := command.Execute([]string{
"--product", "/path/to/a/product.pivotal",
})
Expect(err).NotTo(HaveOccurred())

output := logger.PrintlnArgsForCall(0)

lines := strings.Split(output[0].(string), "\n")
valueOutput := strings.TrimSpace(lines[2])
Expect(valueOutput).To(Equal("value: true"))
})
})

Context("when a property is not optional", func() {
It("writes '# required' next to the property", func() {
metadataExtractor.ExtractMetadataReturns(extractor.Metadata{
Raw: []byte(`---
property_blueprints:
- name: some-name
type: boolean
default: true
optional: false
configurable: true
`),
}, nil)

command = commands.NewConfigTemplate(logger, metadataExtractor)

err := command.Execute([]string{
"--product", "/path/to/a/product.pivotal",
})
Expect(err).NotTo(HaveOccurred())

output := logger.PrintlnArgsForCall(0)

lines := strings.Split(output[0].(string), "\n")
valueOutput := strings.TrimSpace(lines[2])
Expect(valueOutput).To(Equal("value: true # required"))
})
})

Context("when the property is a simple credential", func() {
FIt("prints out an identity and password field", func() {
metadataExtractor.ExtractMetadataReturns(extractor.Metadata{
Raw: []byte(`---
property_blueprints:
- name: some-name
type: simple_credentials
optional: true
configurable: true
`),
}, nil)

command = commands.NewConfigTemplate(logger, metadataExtractor)

err := command.Execute([]string{
"--product", "/path/to/a/product.pivotal",
})
Expect(err).NotTo(HaveOccurred())

Expect(metadataExtractor.ExtractMetadataCallCount()).To(Equal(1))
Expect(metadataExtractor.ExtractMetadataArgsForCall(0)).To(Equal("/path/to/a/product.pivotal"))

Expect(logger.PrintlnCallCount()).To(Equal(1))
output := logger.PrintlnArgsForCall(0)
Expect(output).To(ContainElement(MatchYAML(`---
product-properties:
.properties.some-name:
value:
identity:
password:
`)))

})
})
})

Describe("Usage", func() {
Expand Down
55 changes: 55 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
product-properties:
.properties.networking_poe_ssl_certs:
value:
- name: hi
certificate:
cert_pem: |
-----BEGIN CERTIFICATE-----
MIIDcjCCAlqgAwIBAgIVAORfaKrrVOcTwsc0PYpwyaqMCAkdMA0GCSqGSIb3DQEB
CwUAMB8xCzAJBgNVBAYTAlVTMRAwDgYDVQQKDAdQaXZvdGFsMB4XDTE4MDMyODIz
NDI0NVoXDTIwMDMyODIzNDI0NVowNzELMAkGA1UEBhMCVVMxEDAOBgNVBAoMB1Bp
dm90YWwxFjAUBgNVBAMMDSouZXhhbXBsZS5jb20wggEiMA0GCSqGSIb3DQEBAQUA
A4IBDwAwggEKAoIBAQCq4skfS1X5CcjvPcopu6+pcnKgCRDPTuzMJf9diVVy5XiQ
Kf3MS6R+ajcr4ObNIqSQRcxvwKKE1MGRDs1lBMjqR+ZXc1F2649aUPFykUjgMqaY
yKgZgO2csT3xLv+wEYXzQof5rrSyz1NbjthniMyr7nI0ahxc4KY6I7ZekErRswbT
ovkE6WrELM/CbWK/GpIz6NGvsgarqjIxSDWVFSAmXhGaicYtHTCfRP2CkBsG6lHO
9g4clPjWSA274y4/na6zOYn9bknHooFuReftQYbWAnT8jCVGcVVNjsiNnsniWHjV
LHYlbYTPw9l6vo664vDe78onRpTAI4G4r2vjHyQRAgMBAAGjgYwwgYkwHQYDVR0O
BBYEFIQE+MQqfp6/goC8DfspWWC59wr2MB8GA1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EOzBgoLZIHRQ3d23X3L6XU7h1WkOrEkw8AU=
-----END RSA PRIVATE KEY-----

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d4ac625

Please sign in to comment.