コード例 #1
0
    def test_import_encrypted_config_loaded_properly(self):

        yaml_string = "\n".join([
            "---",
            "- TEST: Value"
        ])

        result_dict = cl.import_config_to_env_var_defaults(yaml_string)

        # Encrypt Config
        encrypted_string = eh.encrypt_string(ENCRYPTION_KEY, yaml_string)

        result_dict = cl.import_config_to_env_var_defaults(
            encrypted_string,
            encryption_key=ENCRYPTION_KEY)

        assert os.environ['TEST'] == 'Value'
        assert result_dict['TEST'] == 'Value'
コード例 #2
0
    def test_import_config_flattens_list_of_dict_yaml_correctly(self):
        yaml_string = "\n".join([
            '---',
            '- TEST:',
            '    ITEM: ',
            '      - OTHER: Value'])

        result_dict = cl.import_config_to_env_var_defaults(yaml_string)

        # Assert
        assert result_dict['TEST_ITEM_OTHER'] == 'Value'
コード例 #3
0
    def test_import_simple_config_properly(self):

        yaml_string = "\n".join([
            "---",
            "- TEST: Value"
        ])

        result_dict = cl.import_config_to_env_var_defaults(yaml_string)

        # Assert
        assert os.environ['TEST'] == 'Value'
        assert result_dict['TEST'] == 'Value'
コード例 #4
0
    def test_import_config_flattens_dashed_yaml_correctly(self):
        yaml_string = "\n".join([
            '---',
            '- TEST:',
            '  - ITEM: Value1',
            '  - OTHER: Value2'])

        # Act
        result_dict = cl.import_config_to_env_var_defaults(yaml_string)

        # Assert
        assert result_dict['TEST_ITEM'] == 'Value1'
        assert result_dict['TEST_OTHER'] == 'Value2'
コード例 #5
0
    def test_import_config_flattened_list_has_list_or_dict_value(self):
        yaml_string = "\n".join([
            '---',
            '- TEST:',
            '    ITEM: ',
            '      - Value1',
            '      - Value2'])

        # Act
        result_dict = cl.import_config_to_env_var_defaults(yaml_string)

        # Assert
        assert 'TEST_ITEM' not in os.environ
        assert 'TEST_ITEM' in result_dict
コード例 #6
0
    def test_import_config_simple_file_overrides_existing_environ(self):
        # Arrange
        os.environ['TEST'] = 'Doomed Value'
        config_dict = {
            'TEST': 'Original Value'
        }

        yaml_string = "\n".join([
            "---",
            "- TEST: New Value"
        ])

        result_dict = cl.import_config_to_env_var_defaults(yaml_string)

        config_dict.update(result_dict)

        # Assert
        assert os.environ['TEST'] == 'New Value'
        assert config_dict['TEST'] == 'New Value'
コード例 #7
0
def build_app():
    """Build the flask application"""
    app = FlaskOpdash(__name__)

    # Load Local Base Config Defaults from File
    app.config.update(
        import_config_to_env_var_defaults(RemoteConfig().load(app.root_path +
                                                              "/config.yml")))

    # Prepare to load override configs (can be remote or local)
    rc = RemoteConfig(app.config.get("AWS_ACCESS_KEY_ID", None),
                      app.config.get("AWS_SECRET_ACCESS_KEY", None))

    # Get Environment Specific Override Config Settings
    override_config_location = os.environ.get(
        app.config.get('CONFIG_OVERRIDE_ENV_VAR', None), None)

    print "*********************************"
    print "OVERRIDE CONFIG ENV VAR IS:{0}".format(override_config_location)
    print "*********************************"

    # If you have encrypted your local override config
    # (this is highly unlikely unless your name is Matt)
    local_config_encryption_key = os.environ.get(
        os.environ.get('ENCRYPTION_CONFIG_LOCAL_KEY', None), None)

    # Load environment specific override configs, if they exist
    if override_config_location:
        override_config = rc.load(override_config_location)
        app.config.update(
            import_config_to_env_var_defaults(
                override_config, encryption_key=local_config_encryption_key))

    #  Load SAML Settings
    app.config["saml_settings"] = json.loads(
        rc.load(app.config["SAML_CONFIG_PATH"]))

    # Ensure Git Hash (Used as Static File Cache Buster) has a value
    app.config["GIT_HASH"] = app.config.get("GIT_HASH", uuid.uuid4())

    # Set up application cache
    app.cache = Cache(config=app.config)
    app.cache.init_app(app)
    with app.app_context():
        app.cache.clear()

    context = None
    ssl_key = app.config.get('FLASK_SSL_KEY', None)
    ssl_crt = app.config.get('FLASK_SSL_CRT', None)

    if ssl_key and ssl_crt:
        context = (ssl_crt, ssl_key)

    # Register Routes and Blueprints
    register_error_handlers(app)
    app.register_blueprint(proxy.mod)
    app.register_blueprint(unsecure.mod)
    app.register_blueprint(racker.mod)
    app.register_blueprint(customer.mod)
    app.register_blueprint(saml.mod)
    app.register_blueprint(login.mod)

    return app, context