remco icon indicating copy to clipboard operation
remco copied to clipboard

`gets` template function not working with `default_backends.env`

Open japtain-cack opened this issue 3 years ago • 4 comments

export RUST_CFG_FOO=foo
export RUST_CFG_BAR=bar
{% for kv in gets("/rust/cfg/*") %}
{{ kv.Key }} {{ kv.Value }}
{% endfor %}

Result is an empty file.

Here is exactly what I'm trying to do in Jinja2 (using envtpl as a workaround):

{%- for key,value in environment('RUST_CFG_') %}
{%- set key_list = key.lower().split('_') %}
{%- if key_list[-1].isnumeric() %}
{%- set _ = key_list.pop(-1) %}
{%- endif %}
{{ key_list|join('.') }} {{ value }}
{%- endfor %}

https://heavyhorst.github.io/remco/template/template-functions/

Also, there seem to be very little documentation around the default_backends.env. I need to build a config file from an arbitrary number of env vars, using {{key}} {{value}}. At first glance, the docs say this is supported with gets(). I would assume the data retrieved to be agnostic of the backends, so I would expect to be able to use gets("/rust/cfg/*") regardless of the backend. If this is not the case, maybe this can be called out in the documentation?

japtain-cack avatar Jul 25 '22 18:07 japtain-cack

Could you give me the complete config? The data is agnostic to the backend so this should work.

HeavyHorst avatar Jul 29 '22 12:07 HeavyHorst

Thank you for confirming this is possible. I thought I might be loosing my mind. I don't have the original file anymore. However, that was the complete contents in the second code block, under the exports. I decided to use envtpl for now, because I know Jinja and Python the best, but I would like to solve this in remco and consolidate everything if possible.

Repo: https://gitlab.com/japtain_cack/rust-server

Remco components: https://gitlab.com/japtain_cack/rust-server/-/tree/master/remco

This file has the behavior I'm attempting to replicate in remco: https://gitlab.com/japtain_cack/rust-server/-/blob/master/envtpl/server.cfg.tpl

japtain-cack avatar Jul 30 '22 21:07 japtain-cack

Hmm, its working here:

$ find /etc/remco/
/etc/remco/
/etc/remco/resources.d
/etc/remco/resources.d/start.sh.toml
/etc/remco/templates
/etc/remco/templates/start.sh
/etc/remco/config

config:

#config.toml

retries = 0
include_dir = "/etc/remco/resources.d"

[default_backends]
[default_backends.env]
    onetime = true
    keys = ["/rust"]

/etc/remco/resources.d/start.sh.toml

[[template]]
  src = "/etc/remco/templates/start.sh"
  dst = "/home/rkaufmann/start.sh"
  make_directories = true
  mode = "0555"

/etc/remco/templates/start.sh

{% for kv in gets("/rust/cfg/*") %}
{{ kv.Key }} {{ kv.Value }}
{% endfor %}
rkaufmann@pop-os:~/Code/remco/bin$ ./remco
2022-08-02T09:04:15.548+0200 [INFO]  loading resource configuration: path=/etc/remco/resources.d/start.sh.toml prefix=./remco[766605]
2022-08-02T09:04:15.549+0200 [INFO]  target config out of sync: config=/home/rkaufmann/start.sh prefix=./remco[766605] resource=start.sh.toml
2022-08-02T09:04:15.549+0200 [INFO]  target config has been updated: config=/home/rkaufmann/start.sh prefix=./remco[766605] resource=start.sh.toml

Result: cat ~/start.sh /rust/cfg/bar bar /rust/cfg/foo foo

HeavyHorst avatar Aug 02 '22 07:08 HeavyHorst

Ahh, the file in question no longer exists as I was trying to get this working, let me cut a branch, recreate the remco template and I'll re-post the file. Never had an issue with the start.sh template. I think the file was called server.cfg.

japtain-cack avatar Aug 02 '22 20:08 japtain-cack