Created
March 29, 2018 19:53
-
-
Save cantoniazzi/1a2511303fdf3e30f1eb544ac6b0607e to your computer and use it in GitHub Desktop.
A python gist example to settings with environments. You must create a file called settings.cfg at the root of your project and put their keys in this file. It will not be committed to the repository.
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
settings.cfg |
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
[s3-dev] | |
s3_key: --- | |
secret_key: --- | |
[s3-hlg] | |
s3_key: --- | |
secret_key: --- | |
[s3-prod] | |
s3_key: --- | |
secret_key: --- |
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 configparser | |
class Settings(): | |
def __init__(self): | |
self.environment = os.environ['ENVIRONMENT'] # dev / hlh / prod | |
self.BASE_DIR = os.path.abspath(os.path.dirname(__file__)) | |
self.__config = configparser.ConfigParser() | |
self.__config.read(os.path.join(self.BASE_DIR, 'settings.cfg')) | |
def s3_credentials(self): | |
return { | |
's3_key': self.__config.get('s3-{}'.format(self.environment), 'key'), | |
'secret_key': self.__config.get('s3-{}'.format(self.environment), 'secret_key') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment