예제 #1
0
 def test_load_config_fill_with_defaults(self, _):
     self.config_loader = ConfigLoader(use_vault=False)
     self.config = self.config_loader.load_config(
         path='resources/',
         environments='with_defaults',
         fill_with_defaults=True)
     expected = {
         'defaults': {
             'config': {
                 'protocol': 'http',
                 'api': '/v2/apps',
                 'username': '******',
                 'password': '******'
             }
         },
         'config': [{
             'api': '/v2/apps',
             'password': '******',
             'protocol': 'ftp',
             'username': '******'
         }, {
             'api': '/v2/apps',
             'host': 'marathon.tesla.develop.lhotse.ov.otto.de',
             'password': '******',
             'protocol': 'http',
             'username': '******'
         }, {
             'api': '/v2/apps',
             'password': '******',
             'protocol': 'http',
             'username': '******'
         }]
     }
     self.assertDictEqual(expected, self.config)
예제 #2
0
파일: app.py 프로젝트: otto-de/gatekeeper
def create_app(environment, port):
    flask = Flask(__name__)
    flask.config.from_pyfile('config.py')

    config_loader = ConfigLoader(verify=False)
    info = config_loader.load_application_info("./")
    config = config_loader.load_config("resources/", environment)

    view_util.navigation_bar = navigation_bar
    view_util.app_name = info['name']

    status.blueprint.navigation_bar = navigation_bar
    status.blueprint.info = info
    status.blueprint.environment = environment
    status.blueprint.port = port
    status.blueprint.start_time = Delorean.now()

    mongo = MongoConnect(config)
    state.mongo = mongo

    views.blueprint.mongo = mongo
    views.blueprint.config = config['app']
    api.blueprint.mongo = mongo
    api.blueprint.config = config['app']

    flask.register_blueprint(status.blueprint)
    flask.register_blueprint(views.blueprint)
    flask.register_blueprint(api.blueprint)
    return flask
예제 #3
0
 def test_load_config_with_env_variable(self, _):
     self.config_loader = ConfigLoader(use_vault=False)
     self.config = self.config_loader.load_config(path='resources/',
                                                  environments='env')
     self.assertEqual(
         {
             'filename': 'env',
             'test_env': self.env_HOME,
             'empty_test_env': ''
         }, self.config)
예제 #4
0
파일: test_config.py 프로젝트: redvox/Eliza
 def test_load_config_fill_with_defaults(self, _):
     self.config_loader = ConfigLoader(use_vault=False)
     self.config = self.config_loader.load_config(path='resources/', environments='with_defaults',
                                                  fill_with_defaults=True)
     expected = {
         'defaults': {
             'config': {
                 'protocol': 'http',
                 'api': '/v2/apps',
                 'username': '******',
                 'password': '******'}},
         'config': [{'api': '/v2/apps',
                     'password': '******',
                     'protocol': 'ftp',
                     'username': '******'},
                    {'api': '/v2/apps',
                     'host': 'marathon.tesla.develop.lhotse.ov.otto.de',
                     'password': '******',
                     'protocol': 'http',
                     'username': '******'},
                    {'api': '/v2/apps',
                     'password': '******',
                     'protocol': 'http',
                     'username': '******'}]
     }
     self.assertDictEqual(expected, self.config)
예제 #5
0
파일: test_config.py 프로젝트: redvox/Eliza
    def test_load_config_with_vault(self, mock):
        mock.register_uri('GET', "http://www.some-url.de/v1/secret/path",
                          text=json.dumps({'data': {'value': 'some secret'}}))

        self.config_loader = ConfigLoader(use_vault=True, vault_addr="http://www.some-url.de", vault_token="AAAA")
        self.config = self.config_loader.load_config(path='resources/', environments='vault')
        self.assertEqual({'filename': 'vault', 'secret': 'some secret'}, self.config)
예제 #6
0
    def test_load_config_with_vault(self, mock):
        mock.register_uri('GET',
                          "http://www.some-url.de/v1/secret/path",
                          text=json.dumps({'data': {
                              'value': 'some secret'
                          }}))

        self.config_loader = ConfigLoader(use_vault=True,
                                          vault_addr="http://www.some-url.de",
                                          vault_token="AAAA")
        self.config = self.config_loader.load_config(path='resources/',
                                                     environments='vault')
        self.assertEqual({
            'filename': 'vault',
            'secret': 'some secret'
        }, self.config)
예제 #7
0
def create_app(port, environment, working_dir, greedy_mode):
    flask = Flask(__name__)
    flask.config.from_pyfile('config.py')

    flask.jinja_env.filters['ceil'] = view_util.ceil

    config_loader = ConfigLoader(verify=False)
    config.info = config_loader.load_application_info("./")
    config.config = config_loader.load_config("resources/",
                                              environment,
                                              fill_with_defaults=True)
    config.rdb = redislite.Redis(working_dir + 'redis.db')
    config.rdb.flushall()
    config.rdb.flushdb()

    start_tasks(config.config, greedy_mode)

    register_status_page(flask, config.rdb, config.info, environment, port)

    flask.register_blueprint(views.blueprint)
    flask.register_blueprint(styleguide.blueprint)

    return flask
예제 #8
0
파일: test_config.py 프로젝트: redvox/Eliza
 def test_load_config_with_vault_disabled(self, _):
     self.config_loader = ConfigLoader(use_vault=False)
     self.config = self.config_loader.load_config(path='resources/', environments='vault')
     self.assertEqual({'filename': 'vault', 'secret': ''}, self.config)
예제 #9
0
파일: test_config.py 프로젝트: redvox/Eliza
 def test_load_config_with_env_variable(self, _):
     self.config_loader = ConfigLoader(use_vault=False)
     self.config = self.config_loader.load_config(path='resources/', environments='env')
     self.assertEqual({'filename': 'env', 'test_env': self.env_HOME, 'empty_test_env': ''}, self.config)
예제 #10
0
파일: test_config.py 프로젝트: redvox/Eliza
 def test_load_multiple_configs_with_empty_files(self, _):
     self.config_loader = ConfigLoader(use_vault=False)
     self.config = self.config_loader.load_config(path='resources/', environments=['develop', 'empty', 'live'])
     self.assertEqual({'filename': 'live'}, self.config)
예제 #11
0
파일: test_config.py 프로젝트: redvox/Eliza
 def test_load_config(self, _):
     self.config_loader = ConfigLoader(use_vault=False)
     self.config = self.config_loader.load_config(path='resources/', environments='develop')
     self.assertEqual({'filename': 'develop'}, self.config)
예제 #12
0
파일: test_config.py 프로젝트: redvox/Eliza
class TestConfig(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.maxDiff = None
        cls.env_HOME = os.environ.get("HOME", "Test Error. Could not read env variable 'HOME'")

    def setUp(self):
        if 'test_env_variable' in os.environ:
            del os.environ['test_env_variable']

    def test_load_config(self, _):
        self.config_loader = ConfigLoader(use_vault=False)
        self.config = self.config_loader.load_config(path='resources/', environments='develop')
        self.assertEqual({'filename': 'develop'}, self.config)

    def test_load_multiple_configs(self, _):
        self.config_loader = ConfigLoader(use_vault=False)
        self.config = self.config_loader.load_config(path='resources/', environments=['develop', 'live'])
        self.assertEqual({'filename': 'live'}, self.config)

    def test_load_multiple_configs_with_empty_files(self, _):
        self.config_loader = ConfigLoader(use_vault=False)
        self.config = self.config_loader.load_config(path='resources/', environments=['develop', 'empty', 'live'])
        self.assertEqual({'filename': 'live'}, self.config)

    def test_load_config_with_env_variable(self, _):
        self.config_loader = ConfigLoader(use_vault=False)
        self.config = self.config_loader.load_config(path='resources/', environments='env')
        self.assertEqual({'filename': 'env', 'test_env': self.env_HOME, 'empty_test_env': ''}, self.config)

    def test_load_config_with_vault(self, mock):
        mock.register_uri('GET', "http://www.some-url.de/v1/secret/path",
                          text=json.dumps({'data': {'value': 'some secret'}}))

        self.config_loader = ConfigLoader(use_vault=True, vault_addr="http://www.some-url.de", vault_token="AAAA")
        self.config = self.config_loader.load_config(path='resources/', environments='vault')
        self.assertEqual({'filename': 'vault', 'secret': 'some secret'}, self.config)

    def test_load_config_with_vault_disabled(self, _):
        self.config_loader = ConfigLoader(use_vault=False)
        self.config = self.config_loader.load_config(path='resources/', environments='vault')
        self.assertEqual({'filename': 'vault', 'secret': ''}, self.config)

    def test_load_config_fill_with_defaults(self, _):
        self.config_loader = ConfigLoader(use_vault=False)
        self.config = self.config_loader.load_config(path='resources/', environments='with_defaults',
                                                     fill_with_defaults=True)
        expected = {
            'defaults': {
                'config': {
                    'protocol': 'http',
                    'api': '/v2/apps',
                    'username': '******',
                    'password': '******'}},
            'config': [{'api': '/v2/apps',
                        'password': '******',
                        'protocol': 'ftp',
                        'username': '******'},
                       {'api': '/v2/apps',
                        'host': 'marathon.tesla.develop.lhotse.ov.otto.de',
                        'password': '******',
                        'protocol': 'http',
                        'username': '******'},
                       {'api': '/v2/apps',
                        'password': '******',
                        'protocol': 'http',
                        'username': '******'}]
        }
        self.assertDictEqual(expected, self.config)
예제 #13
0
 def test_load_config_with_vault_disabled(self, _):
     self.config_loader = ConfigLoader(use_vault=False)
     self.config = self.config_loader.load_config(path='resources/',
                                                  environments='vault')
     self.assertEqual({'filename': 'vault', 'secret': ''}, self.config)
예제 #14
0
 def test_load_multiple_configs_with_empty_files(self, _):
     self.config_loader = ConfigLoader(use_vault=False)
     self.config = self.config_loader.load_config(
         path='resources/', environments=['develop', 'empty', 'live'])
     self.assertEqual({'filename': 'live'}, self.config)
예제 #15
0
 def test_load_config(self, _):
     self.config_loader = ConfigLoader(use_vault=False)
     self.config = self.config_loader.load_config(path='resources/',
                                                  environments='develop')
     self.assertEqual({'filename': 'develop'}, self.config)
예제 #16
0
class TestConfig(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.maxDiff = None
        cls.env_HOME = os.environ.get(
            "HOME", "Test Error. Could not read env variable 'HOME'")

    def setUp(self):
        if 'test_env_variable' in os.environ:
            del os.environ['test_env_variable']

    def test_load_config(self, _):
        self.config_loader = ConfigLoader(use_vault=False)
        self.config = self.config_loader.load_config(path='resources/',
                                                     environments='develop')
        self.assertEqual({'filename': 'develop'}, self.config)

    def test_load_multiple_configs(self, _):
        self.config_loader = ConfigLoader(use_vault=False)
        self.config = self.config_loader.load_config(
            path='resources/', environments=['develop', 'live'])
        self.assertEqual({'filename': 'live'}, self.config)

    def test_load_multiple_configs_with_empty_files(self, _):
        self.config_loader = ConfigLoader(use_vault=False)
        self.config = self.config_loader.load_config(
            path='resources/', environments=['develop', 'empty', 'live'])
        self.assertEqual({'filename': 'live'}, self.config)

    def test_load_config_with_env_variable(self, _):
        self.config_loader = ConfigLoader(use_vault=False)
        self.config = self.config_loader.load_config(path='resources/',
                                                     environments='env')
        self.assertEqual(
            {
                'filename': 'env',
                'test_env': self.env_HOME,
                'empty_test_env': ''
            }, self.config)

    def test_load_config_with_vault(self, mock):
        mock.register_uri('GET',
                          "http://www.some-url.de/v1/secret/path",
                          text=json.dumps({'data': {
                              'value': 'some secret'
                          }}))

        self.config_loader = ConfigLoader(use_vault=True,
                                          vault_addr="http://www.some-url.de",
                                          vault_token="AAAA")
        self.config = self.config_loader.load_config(path='resources/',
                                                     environments='vault')
        self.assertEqual({
            'filename': 'vault',
            'secret': 'some secret'
        }, self.config)

    def test_load_config_with_vault_disabled(self, _):
        self.config_loader = ConfigLoader(use_vault=False)
        self.config = self.config_loader.load_config(path='resources/',
                                                     environments='vault')
        self.assertEqual({'filename': 'vault', 'secret': ''}, self.config)

    def test_load_config_fill_with_defaults(self, _):
        self.config_loader = ConfigLoader(use_vault=False)
        self.config = self.config_loader.load_config(
            path='resources/',
            environments='with_defaults',
            fill_with_defaults=True)
        expected = {
            'defaults': {
                'config': {
                    'protocol': 'http',
                    'api': '/v2/apps',
                    'username': '******',
                    'password': '******'
                }
            },
            'config': [{
                'api': '/v2/apps',
                'password': '******',
                'protocol': 'ftp',
                'username': '******'
            }, {
                'api': '/v2/apps',
                'host': 'marathon.tesla.develop.lhotse.ov.otto.de',
                'password': '******',
                'protocol': 'http',
                'username': '******'
            }, {
                'api': '/v2/apps',
                'password': '******',
                'protocol': 'http',
                'username': '******'
            }]
        }
        self.assertDictEqual(expected, self.config)