HeavyHorst / remco

remco is a lightweight configuration management tool
https://heavyhorst.github.io/remco/
MIT License
328 stars 36 forks source link

key does not exists for file backend when value is int or boolean #33

Closed sp185432 closed 5 years ago

sp185432 commented 5 years ago

key does not exists for file backend when value is int or boolean

[0000] INFO remco[6]: set file path backend=file filepath=/opt/better_chef_rundeck/bcr.json [0000] ERROR remco[6]: createStageFileAndSync failed: create stage file failed: template execution failed: [Error (where: execution) in /etc/remco/templates/run.sh | Line 5 Col 96 near 'getv'] key does not exist: /bcr/port resource=run.sh.toml [0000] ERROR remco[6]: not all templates could be rendered, trying again after 18 seconds resource=run.sh.toml

Using {{getenv("/bcr/port")}} for value replacement.

My json file bcr.json: { "bcr": { "port": 3000 } }

sp185432 commented 5 years ago

Sorry, using {{getv("/bcr/port")}}, not {{getenv("/bcr/port")}}

HeavyHorst commented 5 years ago

Keys and values need to be strings in all backends.

sp185432 commented 5 years ago

Is there any way to pull boolean or integer values to config from backend?

HeavyHorst commented 5 years ago

Do you need them as ints and bools or would it be ok to transform the values to strings?

sp185432 commented 5 years ago

Its ok to be transformed as strings in this requirement.

Also any suggestions if we need to use these as ints and bools?

HeavyHorst commented 5 years ago

I think i can try to adjust the file backend so that files like

{
    "bcr": {
        "port": 3000
    }
}

are parseable. Each value would be transformed to its string representation.

We could then, if neccessary, tranform these values back with a filter function (toInt, toBool or something like that).

What do you tink?

sp185432 commented 5 years ago

Yes, this will be perfectly fine :-)

andreykaipov commented 5 years ago

I experienced this too. After looking at it, I think it's because the nodeWalk function for the file backend has no cases for the other types.

Compare easykv's nodeWalk with confd's:

https://github.com/HeavyHorst/easykv/blob/v1.2.4/file/client.go#L92-L114 https://github.com/kelseyhightower/confd/blob/v0.16.0/backends/file/client.go#L83-L106

confd transforms the value to its string representation so the interface can stay consistent across backends, but it'd be up to the end user to transform them back (if necessary since the values will be rendered as strings in a template anyway).

HeavyHorst commented 5 years ago

I just pushed https://github.com/HeavyHorst/easykv/commit/4d4fac1cf46d099faca5eb5c7ea368830a58b4b0 to easyKV. I will update remco in the next few days.

sp185432 commented 5 years ago

Thanks @HeavyHorst

HeavyHorst commented 5 years ago

Remco uses the newest easykv release now. Other types should work now (if you build from master).

sp185432 commented 5 years ago

Its working thanks.

HeavyHorst commented 5 years ago

Great!

hatifnatt commented 4 years ago

Is it possible to add info about this fix to v0.12.0-beta.2 release notes? I started with 'stable' 0.11.1 version and spend about an hour investigating this issue. Already prepared test setup to create new issue but finally found this one.

HeavyHorst commented 4 years ago

I added infos to the release notes.