-
Notifications
You must be signed in to change notification settings - Fork 167
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 #128 from mhahn/file-prefix-kms
Support storing the kms encrypted value in a file
- Loading branch information
Showing
3 changed files
with
56 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import os | ||
|
||
|
||
def get_config_directory(): | ||
"""Return the directory the config file is located in. | ||
This enables us to use relative paths in config values. | ||
""" | ||
# avoid circular import | ||
from ...commands.stacker import Stacker | ||
command = Stacker() | ||
namespace = command.parse_args() | ||
return os.path.dirname(namespace.config.name) | ||
|
||
|
||
def read_value_from_path(value): | ||
"""Enables translators to read values from files. | ||
The value can be referred to with the `file://` prefix. ie: | ||
conf_key: !kms file://kms_value.txt | ||
""" | ||
if value.startswith('file://'): | ||
path = value.split('file://', 1)[1] | ||
config_directory = get_config_directory() | ||
relative_path = os.path.join(config_directory, path) | ||
with open(relative_path) as read_file: | ||
value = read_file.read() | ||
return 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