Beispiel #1
0
def _init_adapter(config: Dict) -> TransferAdapter:
    """Call adapter factory to create a transfer adapter instance
    """
    factory: Callable[..., TransferAdapter] = get_callable(config['factory'])
    adapter: TransferAdapter = factory(**config.get('options', {}))
    if isinstance(adapter, PreAuthorizingTransferAdapter):
        adapter.set_auth_module(authentication)
    return adapter
Beispiel #2
0
def _create_authenticator(spec: Union[str, Dict[str, Any]]) -> Authenticator:
    """Instantiate an authenticator from configuration spec

    Configuration spec can be a string referencing a callable (e.g. mypackage.mymodule:callable)
    in which case the callable will be returned as is; Or, a dict with 'factory' and 'options'
    keys, in which case the factory callable is called with 'options' passed in as argument, and
    the resulting callable is returned.
    """
    log = logging.getLogger(__name__)

    if isinstance(spec, str):
        log.debug("Creating authenticator: %s", spec)
        return get_callable(spec, __name__)

    log.debug("Creating authenticator using factory: %s", spec['factory'])
    factory = get_callable(spec['factory'], __name__)  # type: Callable[..., Authenticator]
    options = spec.get('options', {})
    return factory(**options)
Beispiel #3
0
def factory(storage_class,
            storage_options,
            action_lifetime: int = DEFAULT_ACTION_LIFETIME,
            max_part_size: int = DEFAULT_PART_SIZE):
    """Factory for multipart transfer adapter with storage
    """
    try:
        storage = get_callable(storage_class, __name__)
    except (AttributeError, ImportError):
        raise ValueError(f"Unable to load storage module: {storage_class}")
    return MultipartTransferAdapter(storage(**storage_options),
                                    action_lifetime,
                                    max_part_size=max_part_size)
Beispiel #4
0
def _load_middleware(flask_app: Flask) -> None:
    """Load WSGI middleware classes from configuration
    """
    log = logging.getLogger(__name__)
    wsgi_app = flask_app.wsgi_app
    middleware_config = flask_app.config['MIDDLEWARE']

    for spec in middleware_config:
        klass = get_callable(spec['class'])
        args = spec.get('args', [])
        kwargs = spec.get('kwargs', {})
        wsgi_app = klass(wsgi_app, *args, **kwargs)
        log.debug("Loaded middleware: %s(*%s, **%s)", klass, args, kwargs)

    flask_app.wsgi_app = wsgi_app  # type: ignore
Beispiel #5
0
def factory(storage_class, storage_options, action_lifetime):
    """Factory for basic transfer adapter with local storage
    """
    storage = get_callable(storage_class, __name__)
    return BasicStreamingTransferAdapter(storage(**storage_options), action_lifetime)
Beispiel #6
0
def factory(storage_class, storage_options, action_lifetime):
    """Factory for basic transfer adapter with external storage
    """
    storage = get_callable(storage_class, __name__)
    return BasicExternalBackendTransferAdapter(storage(**storage_options),
                                               action_lifetime)