Last active
October 12, 2016 18:26
-
-
Save JGrubb/c5b4576aa0451349cd38d45bb9eb4d55 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import os | |
import json | |
import base64 | |
class Config(): | |
special_props = ( | |
'relationships', | |
'application', | |
'routes', | |
'variables' | |
) | |
def __init__(self): | |
if self.is_available(): | |
for item in self.special_props: | |
setattr(self, item, self.unpack(item)) | |
def is_available(self): | |
return os.getenv('PLATFORM_ENVIRONMENT') is not None | |
def unpack(self, item): | |
return json.loads(base64.b64decode(os.getenv('PLATFORM_' + item.upper())).decode('utf-8')) | |
def __getattr__(self, item): | |
try: | |
return os.getenv('PLATFORM_' + item.upper()) | |
except AttributeError: | |
format("No platform variable named %s", item) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage