Example #1
0
    def validate_configuration(self, config):
        """See :meth:`storage.brokers.broker.Broker.validate_configuration`"""

        warnings = []
        if 'bucket_name' not in config or not config['bucket_name']:
            raise InvalidBrokerConfiguration('S3 broker requires "bucket_name" to be populated')

        credentials = None
        if 'credentials' in config and config['credentials']:
            credentials_dict = config['credentials']
            if 'access_key_id' not in credentials_dict or not credentials_dict['access_key_id']:
                raise InvalidBrokerConfiguration('S3 broker requires "access_key_id" to be populated')
            if 'secret_access_key' not in credentials_dict or not credentials_dict['secret_access_key']:
                raise InvalidBrokerConfiguration('S3 broker requires "secret_access_key" to be populated')
            credentials = S3Credentials(credentials_dict['access_key_id'], credentials_dict['secret_access_key'])

        # Check whether the bucket can actually be accessed
        with S3Client(credentials) as client:
            try:
                client.get_bucket(config['bucket_name'])
            except ClientError:
                warnings.append(ValidationWarning('bucket_access',
                                                  'Unable to access bucket. Check the bucket name and credentials.'))

        return warnings
Example #2
0
    def validate_configuration(self, config):
        """See :meth:`storage.brokers.broker.Broker.validate_configuration`
        """

        if 'nfs_path' not in config or not config['nfs_path']:
            raise InvalidBrokerConfiguration(
                'NFS broker requires "nfs_path" to be populated')
        return []
Example #3
0
    def validate_configuration(self, config):
        """See :meth:`storage.brokers.broker.Broker.validate_configuration`
        """

        if 'host_path' not in config or not config['host_path']:
            raise InvalidBrokerConfiguration('Host broker requires "host_path" to be populated')

        # TODO: include checks against obvious 'bad' host mounts such as '/'
        return []
Example #4
0
def get_broker(broker_type):
    """Returns a broker of the given type.

    :param broker_type: The unique identifier of a registered broker.
    :type broker_type: string
    :returns: A broker for storing and retrieving files.
    :rtype: :class:`storage.brokers.broker.Broker`
    """

    if broker_type in _BROKERS:
        return _BROKERS[broker_type]()
    raise InvalidBrokerConfiguration(
        'INVALID_BROKER', '\'%s\' is an invalid broker type' % broker_type)
Example #5
0
    def validate_configuration(self, config):
        """See :meth:`storage.brokers.broker.Broker.validate_configuration`"""

        warnings = []
        if 'bucket_name' not in config or not config['bucket_name']:
            raise InvalidBrokerConfiguration('INVALID_BROKER', 'S3 broker requires "bucket_name" to be populated')
        region_name = config.get('region_name')

        credentials = AWSClient.instantiate_credentials_from_config(config)

        # Check whether the bucket can actually be accessed
        with S3Client(credentials, region_name) as client:
            try:
                client.get_bucket(config['bucket_name'])
            except (ClientError, NoCredentialsError):
                warnings.append(ValidationWarning('bucket_access',
                                                  'Unable to access bucket. Check the bucket name and credentials.'))

        return warnings