-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow override of settings from global configuration (#147)
- Loading branch information
1 parent
4ab34ca
commit a622263
Showing
7 changed files
with
192 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -239,3 +239,4 @@ | |
AND = 'AND' | ||
OR = 'OR' | ||
CONDITIONAL_OPERATORS = [AND, OR] | ||
|
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,40 @@ | ||
import imp | ||
import logging | ||
import os | ||
from os import getenv | ||
|
||
from botocore.vendored import requests | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
default_settings_dict = { | ||
'request_timeout_seconds': 60, | ||
'max_retry_attempts': 3, | ||
'base_backoff_ms': 25, | ||
'region': 'us-east-1', | ||
'session_cls': requests.Session | ||
} | ||
|
||
OVERRIDE_SETTINGS_PATH = getenv('PYNAMODB_CONFIG', '/etc/pynamodb/global_default_settings.py') | ||
|
||
override_settings = {} | ||
if os.path.isfile(OVERRIDE_SETTINGS_PATH): | ||
override_settings = imp.load_source(OVERRIDE_SETTINGS_PATH, OVERRIDE_SETTINGS_PATH) | ||
log.info('Override settings for pynamo available {0}'.format(OVERRIDE_SETTINGS_PATH)) | ||
else: | ||
log.info('Override settings for pynamo not available {0}'.format(OVERRIDE_SETTINGS_PATH)) | ||
log.info('Using Default settings value') | ||
|
||
|
||
def get_settings_value(key): | ||
""" | ||
Fetches the value from the override file. | ||
If the value is not present, then tries to fetch the values from constants.py | ||
""" | ||
if hasattr(override_settings, key): | ||
return getattr(override_settings, key) | ||
|
||
if key in default_settings_dict: | ||
return default_settings_dict[key] | ||
|
||
return None |
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
Oops, something went wrong.