shubhamdipt / passbolt-python-api

An Api for passbolt in python
MIT License
12 stars 15 forks source link

use configparser interpolation to pass in environment variables #3

Closed natejenkins closed 2 years ago

natejenkins commented 4 years ago

This PR adds a keyword argument env_vars to the PassboltAPI initializer that will be passed to configparser.ConfigParser and used to interpolate any variables provided in env_vars. Does not break any existing API use.

If you pass in an environment variable, for example a variable FOO:

import os
PassboltAPI(config_path='config.ini', env_vars=os.environ)

you can use that variable inside the config.ini file via:

bar=%(FOO)s

If the variable is present both in the env_vars dictionary and the config.ini file then the config.ini value takes precedence.

What you cannot do is use the same name for a variable you are defining and one that you are passing in, such as:

FOO=%(FOO)s

That will result in a recursion error.