Exemple #1
0
def app_config(app, settings="fence.settings", root_dir=None):
    """
    Set up the config for the Flask app.
    """
    app.config.from_object(settings)
    app.__dict__["logger"] = logger
    if "BASE_URL" not in app.config:
        base_url = app.config["HOSTNAME"]
        if not base_url.startswith("http"):
            base_url = "https://" + base_url
        app.config["BASE_URL"] = base_url
    if "ROOT_URL" not in app.config:
        url = urlparse.urlparse(app.config["BASE_URL"])
        app.config["ROOT_URL"] = "{}://{}".format(url.scheme, url.netloc)

    if root_dir is None:
        root_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
    if app.config.get("AWS_CREDENTIALS"):
        value = app.config["AWS_CREDENTIALS"].values()[0]
        app.boto = BotoManager(value, logger=app.logger)
        app.register_blueprint(fence.blueprints.data.blueprint, url_prefix="/data")

    app.keypairs = keys.load_keypairs(os.path.join(root_dir, "keys"))

    app.jwt_public_keys = {
        app.config["BASE_URL"]: OrderedDict(
            [(str(keypair.kid), str(keypair.public_key)) for keypair in app.keypairs]
        )
    }

    cirrus.config.config.update(**app.config.get("CIRRUS_CFG", {}))
Exemple #2
0
def app_config(app, settings='fence.settings', root_dir=None):
    """
    Set up the config for the Flask app.
    """
    app.config.from_object(settings)
    if 'BASE_URL' not in app.config:
        base_url = app.config['HOSTNAME']
        if not base_url.startswith('http'):
            base_url = 'https://' + base_url
        app.config['BASE_URL'] = base_url
    if 'ROOT_URL' not in app.config:
        url = urlparse.urlparse(app.config['BASE_URL'])
        app.config['ROOT_URL'] = '{}://{}'.format(url.scheme, url.netloc)

    app.keypairs = []
    if root_dir is None:
        root_dir = os.path.dirname(
                os.path.dirname(os.path.realpath(__file__)))
    if 'AWS_CREDENTIALS' in app.config and len(app.config['AWS_CREDENTIALS']) > 0:
        value = app.config['AWS_CREDENTIALS'].values()[0]
        app.boto = BotoManager(value)
        app.register_blueprint(
            fence.blueprints.data.blueprint, url_prefix='/data'
        )
    for kid, (public, private) in app.config['JWT_KEYPAIR_FILES'].iteritems():
        public_filepath = os.path.join(root_dir, public)
        private_filepath = os.path.join(root_dir, private)
        with open(public_filepath, 'r') as f:
            public_key = f.read()
        with open(private_filepath, 'r') as f:
            private_key = f.read()
        app.keypairs.append(keys.Keypair(
            kid=kid, public_key=public_key, private_key=private_key
        ))
    app.jwt_public_keys = {
        app.config['BASE_URL']: OrderedDict([
            (str(keypair.kid), str(keypair.public_key))
            for keypair in app.keypairs
        ])
    }
Exemple #3
0
def _setup_data_endpoint_and_boto(app):
    if "AWS_CREDENTIALS" in config and len(config["AWS_CREDENTIALS"]) > 0:
        value = list(config["AWS_CREDENTIALS"].values())[0]
        app.boto = BotoManager(value, logger=logger)
        app.register_blueprint(fence.blueprints.data.blueprint,
                               url_prefix="/data")