Example #1
0
    def storage(self):
        # maybe task has storage link
        storage_link = self.get_storage_link()
        if storage_link:
            return storage_link.storage

        # or try global storage settings (only s3 for now)
        elif get_env('USE_DEFAULT_S3_STORAGE', default=False, is_bool=True):
            # TODO: this is used to access global environment storage settings.
            # We may use more than one and non-default S3 storage (like GCS, Azure)
            from io_storages.s3.models import S3ImportStorage
            return S3ImportStorage()
Example #2
0
 def validate(self, data):
     data = super(S3ImportStorageSerializer, self).validate(data)
     if not data.get('bucket', None):
         return data
     
     storage = S3ImportStorage(**data)
     try:
         storage.validate_connection()
     except ParamValidationError:
         raise ValidationError('Wrong credentials for S3 {bucket_name}'.format(bucket_name=storage.bucket))
     except ClientError as e:
         if '403' == e.response.get('Error').get('Code'):
             raise ValidationError('Cannot connect to S3 {bucket_name} with specified AWS credentials'.format(
                 bucket_name=storage.bucket))
         if '404' in e.response.get('Error').get('Code'):
             raise ValidationError('Cannot find bucket {bucket_name} in S3'.format(
                 bucket_name=storage.bucket))
     return data