Skip to content

Instantly share code, notes, and snippets.

@JGrubb
Last active October 12, 2016 18:26
Show Gist options
  • Save JGrubb/c5b4576aa0451349cd38d45bb9eb4d55 to your computer and use it in GitHub Desktop.
Save JGrubb/c5b4576aa0451349cd38d45bb9eb4d55 to your computer and use it in GitHub Desktop.
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)
@JGrubb
Copy link
Author

JGrubb commented Oct 12, 2016

Usage

from platformsh import Config

pc = Config()

if pc.is_available():
    relationships = pc.relationships
    env = getattr(pc, 'environment')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment