def test_nested_default(self): self.assertEqual(envitro.int('TEST_NOPE_INT', envitro.str('TEST_NOPE_STR', '123')), 123) self.assertEqual(envitro.str('TEST_NOPE_STR', envitro.int('TEST_NOPE_INT', 123)), '123') self.assertEqual(envitro.bool('TEST_NOPE_BOOL', envitro.int('TEST_NOPE_INT', 123)), True) self.assertEqual(envitro.bool('TEST_NOPE_BOOL', envitro.int('TEST_NOPE_INT', 0)), False) self.assertEqual(envitro.bool('TEST_NOPE_BOOL', envitro.int('TEST_NOPE_INT', 123)), True) self.assertEqual(envitro.bool('TEST_NOPE_BOOL', envitro.str('TEST_NOPE_STR', 'false')), False) self.assertEqual(envitro.bool('TEST_NOPE_BOOL', envitro.str('TEST_NOPE_STR', '')), False)
def test_none_int(self): if 'DOES_NOT_EXIST_INT' in os.environ: del os.environ['DOES_NOT_EXIST_INT'] self.assertEqual(envitro.int('DOES_NOT_EXIST_INT', allow_none=True), None)
def assert_get_set_int(self, value, expected_value): os.environ['TEST_INT'] = value self.assertEqual(envitro.int('TEST_INT'), expected_value)
# -*- coding: utf-8 -*- import envitro import pyrax # pyrax connection pyrax.set_setting("identity_type", "rackspace") pyrax.set_setting("region", envitro.str("RAX_REGION", "DFW")) pyrax.set_credentials(envitro.str("RAX_ACCOUNT"), envitro.str("RAX_API")) cdb = pyrax.cloud_databases BACKUP_NAME = envitro.str("BACKUP_NAME", "rax-db-backup") MAX_BACKUPS = envitro.int("MAX_BACKUPS", 30) instances = cdb.list() for instance in instances: # create the backup instance.create_backup(BACKUP_NAME) # get the backups and delete the extra ones if there are too many backups = instance.list_backups() backups_filtered = filter(lambda backup: backup.name == BACKUP_NAME, backups) if len(backups_filtered) > MAX_BACKUPS: for backup in backups_filtered[MAX_BACKUPS:]: backup.delete()
# -*- coding: utf-8 -*- import envitro import etcd ETCD_HOST = envitro.str('ETCD_HOST', '172.17.42.1') # coreos default ETCD_PORT = envitro.int('ETCD_PORT', 2379) ETCD_KEY_REDIS = envitro.str('ETCD_KEY_REDIS', '/services/redis') REDIS_HOST = envitro.str('REDIS_HOST', allow_none=True) REDIS_PORT = envitro.int('REDIS_PORT', allow_none=True) # if the redis host and port were not explicitly set, try and infer them from etcd if not (REDIS_HOST and REDIS_PORT): try: client = etcd.Client(host=ETCD_HOST, port=ETCD_PORT, read_timeout=5) vals = client.read(ETCD_KEY_REDIS).children.next().value.rsplit(':', 1) REDIS_HOST = vals[0] REDIS_PORT = int(vals[1]) except: print('No ETCD connection. Using localhost defaults.') REDIS_HOST = '127.0.0.1' REDIS_PORT = 6379 ##### Redis ##### REDIS_DB = envitro.int('REDIS_DB', 0)
# -*- coding: utf-8 -*- from __future__ import absolute_import import envitro import pymysql pymysql.install_as_MySQLdb() DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': envitro.str('DATABASE_NAME', 'snapabledb'), 'USER': envitro.str('DATABASE_USER', 'snapableusr'), 'PASSWORD': envitro.str('DATABASE_PASSWORD', 'snapable12345'), 'HOST': envitro.str('DATABASE_HOST', '127.0.0.1'), 'PORT': envitro.int('DATABASE_PORT', 3306), } }
# -*- coding: utf-8 -*- import envitro EMAIL_BACKEND = 'api.utils.email.SnapEmailBackend' EMAIL_HOST = envitro.str('EMAIL_HOST', 'smtp.mailgun.org') EMAIL_PORT = envitro.int('EMAIL_PORT', 587) EMAIL_USE_TLS = envitro.bool('EMAIL_USE_TLS', True) EMAIL_HOST_USER = envitro.str('EMAIL_HOST_USER') EMAIL_HOST_PASSWORD = envitro.str('EMAIL_HOST_PASSWORD') ##### sendwithus ##### SENDWITHUS_KEY = envitro.str('SENDWITHUS_KEY') # no email