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

confd fails to read non-string keys when using file backend #640

Closed
marwatk opened this issue Dec 11, 2017 · 2 comments
Closed

confd fails to read non-string keys when using file backend #640

marwatk opened this issue Dec 11, 2017 · 2 comments
Labels
Milestone

Comments

@marwatk
Copy link

marwatk commented Dec 11, 2017

The yaml file backend only has cases for string, array and map in the switch that loads values. As a result anything not matching those types will fail to load. I think the expected behavior would be to coerce everything else to string.

Example:

#!/bin/bash

DIR=`mktemp -d`
pushd $DIR
mkdir conf.d
mkdir templates

cat << EOF > conf.d/test.toml
[template]
keys = [
    "/foo/stringVal",
    "/foo/intVal",
]
src = "test.txt.tmpl"
dest = "test.txt"
EOF

cat << EOF > templates/test.txt.tmpl
string: {{getv "/foo/stringVal"}}
int: {{getv "/foo/intVal"}}
EOF

cat << EOF > test.yml
foo:
  stringVal: string
  intVal: 1234
EOF

confd -onetime -log-level debug -confdir . -backend file -file test.yml

cat test.txt
popd
rm -rf $DIR

Output:

2017-12-11T15:50:32-07:00  confd[31669]: INFO Backend set to file
2017-12-11T15:50:32-07:00  confd[31669]: INFO Starting confd
2017-12-11T15:50:32-07:00  confd[31669]: INFO Backend source(s) set to test.yml
2017-12-11T15:50:32-07:00  confd[31669]: DEBUG Loading template resources from confdir .
2017-12-11T15:50:32-07:00  confd[31669]: DEBUG Found template: conf.d/test.toml
2017-12-11T15:50:32-07:00  confd[31669]: DEBUG Loading template resource from conf.d/test.toml
2017-12-11T15:50:32-07:00  confd[31669]: DEBUG Retrieving keys from store
2017-12-11T15:50:32-07:00  confd[31669]: DEBUG Key prefix set to /
2017-12-11T15:50:32-07:00  confd[31669]: DEBUG Key Map: map[string]string{"/foo/stringVal":"string"}
2017-12-11T15:50:32-07:00  confd[31669]: DEBUG Got the following map from store: map[/foo/stringVal:string]
2017-12-11T15:50:32-07:00  confd[31669]: DEBUG Using source template templates/test.txt.tmpl
2017-12-11T15:50:32-07:00  confd[31669]: DEBUG Compiling source template templates/test.txt.tmpl
2017-12-11T15:50:32-07:00  confd[31669]: ERROR template: test.txt.tmpl:2:7: executing "test.txt.tmpl" at <getv "/foo/intVal">: error calling getv: key does not exist: /foo/intVal
2017-12-11T15:50:32-07:00  confd[31669]: FATAL template: test.txt.tmpl:2:7: executing "test.txt.tmpl" at <getv "/foo/intVal">: error calling getv: key does not exist: /foo/intVal
@okushchenko
Copy link
Collaborator

@marwatk sounds like a good idea, please, take a shot at opening PR with a fix.

@lucastheisen
Copy link
Contributor

@okushchenko , i submitted a pull request here...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants