Skip to content
This repository was archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
Add unquoted bool support
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Hubbard committed Dec 19, 2016
1 parent 97c7154 commit 14e2a56
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 4 additions & 2 deletions secretsyml/secretsyml.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ func (s *SecretSpec) IsLiteral() bool {
type SecretsMap map[string]SecretSpec

func (spec *SecretSpec) SetYAML(tag string, value interface{}) bool {
r, _ := regexp.Compile("(var|file|str|int)")
r, _ := regexp.Compile("(var|file|str|int|bool)")
tags := r.FindAllString(tag, -1)
if len(tags) == 0 {
return false
}
for _, t := range tags {
switch t {
case "str", "int":
case "str", "int", "bool":
spec.Tags = append(spec.Tags, Literal)
case "file":
spec.Tags = append(spec.Tags, File)
Expand All @@ -75,6 +75,8 @@ func (spec *SecretSpec) SetYAML(tag string, value interface{}) bool {
spec.Path = s
} else if s, ok := value.(int); ok {
spec.Path = strconv.Itoa(s)
} else if s, ok := value.(bool); ok {
spec.Path = strconv.FormatBool(s)
} else {
return false
}
Expand Down
16 changes: 14 additions & 2 deletions secretsyml/secretsyml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ PRIVATE_KEY_FILE2: !var:file $env/aws/ec2/private_key
SOME_FILE: !file my content
RAILS_ENV: $env
FLOAT: 27.1111
INT: 27`
INT: 27
BOOL: true`
Convey("It should correctly identify the types from tags", func() {
parsed, err := ParseFromString(input, testEnv, map[string]string{"env": "prod"})
So(err, ShouldBeNil)
Expand Down Expand Up @@ -52,6 +53,11 @@ INT: 27`
So(found, ShouldBeTrue)
So(spec.IsLiteral(), ShouldBeTrue)
So(spec.Path, ShouldEqual, "27")

spec, found = parsed["BOOL"]
So(found, ShouldBeTrue)
So(spec.IsLiteral(), ShouldBeTrue)
So(spec.Path, ShouldEqual, "true")
})
})

Expand All @@ -64,7 +70,8 @@ INT: 27`
SOME_FILE: !file my content
RAILS_ENV: $env
FLOAT: 27.1111
INT: 27`
INT: 27
BOOL: true`

Convey("It should correctly identify the types from tags", func() {
parsed, err := ParseFromString(input, testEnv, map[string]string{"env": "prod"})
Expand Down Expand Up @@ -100,6 +107,11 @@ INT: 27`
So(found, ShouldBeTrue)
So(spec.IsLiteral(), ShouldBeTrue)
So(spec.Path, ShouldEqual, "27")

spec, found = parsed["BOOL"]
So(found, ShouldBeTrue)
So(spec.IsLiteral(), ShouldBeTrue)
So(spec.Path, ShouldEqual, "true")
})
})

Expand Down

0 comments on commit 14e2a56

Please sign in to comment.