Skip to content

Commit

Permalink
remote/config: allow use of environment variables in exporter config
Browse files Browse the repository at this point in the history
This extends the jinja2 templating support in exporter configuration file with
support for using OS environment variables.

Signed-off-by: Esben Haabendal <[email protected]>
[[email protected]: rebased]
Signed-off-by: Rouven Czerwinski <[email protected]>
  • Loading branch information
esben authored and Emantor committed Jan 22, 2021
1 parent 8503839 commit 4e983a2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ New Features in 0.3.0
Labgrid.
- ``labgrid-client write-image`` gained a new argument ``--mode`` to specify
which tool should be used to write the image (either ``dd`` or ``bmaptool``)
- Exporter configuration file ``exporter.yaml`` now allows use of environment
variables.

Breaking changes in 0.3.0
~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
4 changes: 4 additions & 0 deletions doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2211,3 +2211,7 @@ Use ``#`` for line statements (like the for loops in the example) and ``##``
for line comments.
Statements like ``{{ 4000 + idx }}`` are expanded based on variables in the
Jinja2 template.

The template processing also supports use of OS environment variables, using
something like `{{ env['FOOBAR'] }}` to insert the content of environment
variable `FOOBAR`.
3 changes: 2 additions & 1 deletion labgrid/remote/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import attr
import jinja2
import os

from ..util.yaml import load
from ..exceptions import NoConfigFoundError
Expand All @@ -23,7 +24,7 @@ def __attrs_post_init__(self):
raise NoConfigFoundError(
"{} could not be found".format(self.filename)
)
rendered = template.render()
rendered = template.render(env=os.environ)
pprint(('rendered', rendered))
self.data = load(rendered)
pprint(('loaded', self.data))

0 comments on commit 4e983a2

Please sign in to comment.