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

Allow passing a prefix format along with prefix path #161

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 4 additions & 1 deletion cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,10 +774,13 @@ Options:
-pid-file=<path>
Path on disk to write the PID of the process

-prefix=<prefix>
-prefix=<prefix path>[@<prefix format>]
A prefix to watch, multiple prefixes are merged from left to right, with
the right-most result taking precedence, including any values specified
with -secret
Optionally, a prefix format can be passed along with the path. The
delimiter in use is "@". By default, an empty format defaults on "{{ key }}",
each prefix can have its own format.

-pristine
Only use values retrieved from prefixes and secrets, do not inherit the
Expand Down
3 changes: 2 additions & 1 deletion cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ func TestCLI_ParseFlags(t *testing.T) {
"prefix_multi",
[]string{
"-prefix", "foo/bar",
"-prefix", "zip/zap",
"-prefix", "zip/zap@zap_{{key}}",
},
&Config{
Prefixes: &PrefixConfigs{
Expand All @@ -529,6 +529,7 @@ func TestCLI_ParseFlags(t *testing.T) {
},
&PrefixConfig{
Path: config.String("zip/zap"),
Format: config.String("zap_{{key}}"),
},
},
},
Expand Down
22 changes: 18 additions & 4 deletions config_prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,24 @@ type PrefixConfig struct {
}

func ParsePrefixConfig(s string) (*PrefixConfig, error) {
s = strings.TrimPrefix(s, "/")
return &PrefixConfig{
Path: config.String(s),
}, nil
switch parts := strings.Split(s, "@"); len(parts) {
case 1:
path := strings.TrimPrefix(parts[0], "/")

return &PrefixConfig{
Path: config.String(path),
}, nil
case 2:
path := strings.TrimPrefix(parts[0], "/")
format := parts[1]

return &PrefixConfig{
Path: config.String(path),
Format: config.String(format),
}, nil
default:
return nil, fmt.Errorf("Wrong number of delimiters found when parsing prefix (%d, expected 1 at most)", len(parts))
}
}

func DefaultPrefixConfig() *PrefixConfig {
Expand Down