-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from HDE/master
Release v0.1.5
- Loading branch information
Showing
7 changed files
with
94 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import json | ||
import os | ||
|
||
|
||
def set_environment_variables(json_file_path): | ||
""" | ||
Read and set environment variables from a flat json file. | ||
Bear in mind that env vars set this way and later on read using | ||
`os.getenv` function will be strings since after all env vars are just | ||
that - plain strings. | ||
Json file example: | ||
``` | ||
{ | ||
"FOO": "bar", | ||
"BAZ": true | ||
} | ||
``` | ||
:param json_file_path: path to flat json file | ||
:type json_file_path: str | ||
""" | ||
if json_file_path: | ||
with open(json_file_path) as json_file: | ||
env_vars = json.loads(json_file.read()) | ||
|
||
for env_name, env_value in env_vars.items(): | ||
os.environ[str(env_name)] = str(env_value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"STR_KEY": "foo", | ||
"INT_KEY": 100, | ||
"BOOL_KEY": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import os | ||
|
||
from lambda_local.environment_variables import set_environment_variables | ||
|
||
|
||
def test_set_environment_variables(): | ||
os.getenv('STR_KEY') is None | ||
os.getenv('INT_KEY') is None | ||
os.getenv('BOOL_KEY') is None | ||
|
||
set_environment_variables('tests/environment_variables.json') | ||
|
||
assert os.getenv('STR_KEY') == 'foo' | ||
assert os.getenv('INT_KEY') == '100' | ||
assert os.getenv('BOOL_KEY') == 'False' |