def validate_configuration(self, configuration): """See :meth:`ingest.strike.monitors.monitor.Monitor.validate_configuration` """ warnings = [] if 'sqs_name' not in configuration: raise InvalidMonitorConfiguration( 'sqs_name is required for s3 monitor') if not isinstance(configuration['sqs_name'], basestring): raise InvalidMonitorConfiguration('sqs_name must be a string') if not configuration['sqs_name']: raise InvalidMonitorConfiguration( 'sqs_name must be a non-empty string') # If credentials exist, validate them. credentials = AWSClient.instantiate_credentials_from_config( configuration) region_name = configuration.get('region_name') # Check whether the bucket can actually be accessed with SQSClient(credentials, region_name) as client: try: client.get_queue_by_name(configuration['sqs_name']) except ClientError: warnings.append( ValidationWarning( 'sqs_access', 'Unable to access SQS. Check the name, region and credentials.' )) return warnings
def validate_configuration(self, configuration): """See :meth:`ingest.strike.monitors.monitor.Monitor.validate_configuration` """ warnings = [] if 'sqs_name' not in configuration: raise InvalidMonitorConfiguration('sqs_name is required for s3 monitor') if not isinstance(configuration['sqs_name'], basestring): raise InvalidMonitorConfiguration('sqs_name must be a string') if not configuration['sqs_name']: raise InvalidMonitorConfiguration('sqs_name must be a non-empty string') # If credentials exist, validate them. credentials = AWSClient.instantiate_credentials_from_config(configuration) region_name = configuration.get('region_name') # Check whether the bucket can actually be accessed with SQSClient(credentials, region_name) as client: try: client.get_queue_by_name(configuration['sqs_name']) except ClientError: warnings.append(ValidationWarning('sqs_access', 'Unable to access SQS. Check the name, region and credentials.')) return warnings
def load_configuration(self, configuration): """See :meth:`ingest.strike.monitors.monitor.Monitor.load_configuration` """ self._sqs_name = configuration['sqs_name'] self._region_name = configuration.get('region_name') # TODO Change credentials to use an encrypted store key reference self._credentials = AWSClient.instantiate_credentials_from_config(configuration)
def test_instantiate_credentials_from_config_empty_secret_key(self): """Tests instantiating AWS Credentials from a configuration with an empty secret key.""" config = { 'credentials': { 'access_key_id': 'ACCESSKEY', 'secret_access_key': ' ' } } self.assertIsNone( AWSClient.instantiate_credentials_from_config(config))
def test_instantiate_credentials_from_config(self): """Tests instantiating AWS Credentials from a valid configuration.""" config = { 'credentials': { 'access_key_id': 'ACCESSKEY', 'secret_access_key': 'SECRETKEY' } } credential = AWSClient.instantiate_credentials_from_config(config) self.assertEqual(credential.access_key_id, 'ACCESSKEY') self.assertEqual(credential.secret_access_key, 'SECRETKEY')
def load_configuration(self, config): """See :meth:`storage.brokers.broker.Broker.load_configuration`""" self._bucket_name = config['bucket_name'] self._region_name = config.get('region_name') # TODO Change credentials to use an encrypted store key reference self._credentials = AWSClient.instantiate_credentials_from_config(config) if 'host_path' in config: volume = BrokerVolume(None, config['host_path']) volume.host = True self._volume = volume
def load_configuration(self, config): """See :meth:`storage.brokers.broker.Broker.load_configuration`""" self._bucket_name = config['bucket_name'] self._region_name = config.get('region_name') # TODO Change credentials to use an encrypted store key reference self._credentials = AWSClient.instantiate_credentials_from_config(config) # Ensure empty or white-space filled host_paths do not cause mounts to be applied if 'host_path' in config and len(config['host_path'].strip()): volume = BrokerVolume(None, config['host_path']) volume.host = True self._volume = volume
def load_configuration(self, config): """See :meth:`storage.brokers.broker.Broker.load_configuration`""" self._bucket_name = config['bucket_name'] self._region_name = config.get('region_name') # TODO Change credentials to use an encrypted store key reference self._credentials = AWSClient.instantiate_credentials_from_config( config) if 'host_path' in config: volume = BrokerVolume(None, config['host_path']) volume.host = True self._volume = volume
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
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') 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: warnings.append(ValidationWarning('bucket_access', 'Unable to access bucket. Check the bucket name and credentials.')) return warnings
def test_instantiate_credentials_from_config_missing_secret_key(self): """Tests instantiating AWS Credentials from a configuration missing secret key.""" config = {'credentials': {'access_key_id': 'ACCESSKEY'}} with self.assertRaises(InvalidAWSCredentials): AWSClient.instantiate_credentials_from_config(config)
def test_instantiate_credentials_from_config_missing_access_key(self): """Tests instantiating AWS Credentials from a configuration missing access key.""" config = { 'credentials': { 'secret_access_key': 'SECRETKEY' }} with self.assertRaises(InvalidAWSCredentials): AWSClient.instantiate_credentials_from_config(config)
def test_instantiate_credentials_from_config_empty_secret_key(self): """Tests instantiating AWS Credentials from a configuration with an empty secret key.""" config = { 'credentials': { 'access_key_id': 'ACCESSKEY', 'secret_access_key': ' ' }} self.assertIsNone(AWSClient.instantiate_credentials_from_config(config))
def test_instantiate_credentials_from_config_missing_secret_key(self): """Tests instantiating AWS Credentials from a configuration missing secret key.""" config = { 'credentials': { 'access_key_id': 'ACCESSKEY' }} with self.assertRaises(InvalidAWSCredentials): AWSClient.instantiate_credentials_from_config(config)
def test_instantiate_credentials_from_config_missing_access_key(self): """Tests instantiating AWS Credentials from a configuration missing access key.""" config = {'credentials': {'secret_access_key': 'SECRETKEY'}} with self.assertRaises(InvalidAWSCredentials): AWSClient.instantiate_credentials_from_config(config)
def test_instantiate_credentials_from_config(self): """Tests instantiating AWS Credentials from a valid configuration.""" config = { 'credentials': { 'access_key_id': 'ACCESSKEY', 'secret_access_key': 'SECRETKEY'}} credential = AWSClient.instantiate_credentials_from_config(config) self.assertEqual(credential.access_key_id, 'ACCESSKEY') self.assertEqual(credential.secret_access_key, 'SECRETKEY')