Skip to content

Commit

Permalink
Adding a ResolverNOOP (#122)
Browse files Browse the repository at this point in the history
This resolver will return the key wrapped in the field reference syntax.
This allow you to hide sensitive information present in the environment
or by other resolvers.
  • Loading branch information
ph authored Oct 26, 2018
1 parent e81c02a commit 6a5daf7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]

### Added
- Added a NOOP resolver that will return the key wrapped in the field reference syntax. #xxx

### Changed

Expand Down
13 changes: 13 additions & 0 deletions opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ func doResolveEnv(o *options) {
})
}

// ResolveNOOP option add a resolver that will not search the value but instead will return the
// provided key wrap with the field reference syntax. This is useful if you don't to expose values
// from envionment variable or other resolvers.
//
// Example: "mysecret" => ${mysecret}"
var ResolveNOOP Option = doResolveNOOP

func doResolveNOOP(o *options) {
o.resolvers = append(o.resolvers, func(name string) (string, error) {
return "${" + name + "}", nil
})
}

var (
// ReplacesValues option configures all merging and unpacking operations to
// replace old dictionaries and arrays while merging. Value merging can be
Expand Down
20 changes: 20 additions & 0 deletions ucfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,23 @@ func TestMultipleDirectReference(t *testing.T) {
}
})
}

func TestResolveNOOP(t *testing.T) {
opts := []Option{
PathSep("."),
ResolveNOOP,
}

cfg := map[string]interface{}{
"a.top": "top-level",
"f.l.reference": "${a.key}",
}

c, err := NewFrom(cfg, opts...)
assert.NoError(t, err)

v, err := c.String("f.l.reference", -1, opts...)
if assert.NoError(t, err) {
assert.Equal(t, "${a.key}", v)
}
}

0 comments on commit 6a5daf7

Please sign in to comment.