def test_with_region(self, mock_set_region): region = "BEN" connection.Connection(region=region, username="******", api_key="test") mock_set_region.assert_called_with(profile.Profile.ALL, region)
def store(self, fileitem, location=None): """Store the file into Rackspace server. Arguments: fileitem {cgi.Storage} -- Storage object. Keyword Arguments: location {string} -- The location on disk you would like to store the file. (default: {None}) Raises: DriverLibraryNotFound -- Raises when the rackspace library is not installed. Returns: string -- Returns the file name just saved. """ try: from rackspace import connection except ImportError: raise DriverLibraryNotFound( "Could not find the required 'rackspace' library. 'pip install rackspace' to fix this." ) conn = connection.Connection( username=self.config.DRIVERS['rackspace']['username'], api_key=self.config.DRIVERS['rackspace']['secret'], region=self.config.DRIVERS['rackspace']['region']) filename = random_string(25) + fileitem.filename self.validate_extension(filename) conn.object_store.upload_object( container=self.config.DRIVERS['rackspace']['container'], name=filename, data=fileitem.file.read()) return filename
def connect(): """ Connect to rackspace using connection object :return: connection object """ return connection.Connection(username=api_user, api_key=api_key, region=api_region)
def test_auth_with_Token(self, mock_token): tenant = "everett" token = "123" connection.Connection(region="the moon", tenant_id=tenant, token=token) mock_token.assert_called_with(tenant_id=tenant, token=token)
def test_auth_with_Password(self, mock_password): user = "******" password = "******" connection.Connection(region="the moon", username=user, password=password) mock_password.assert_called_with(username=user, password=password)
def test_auth_with_APIKey(self, mock_apikey): user = "******" api_key = "123" connection.Connection(region="the moon", username=user, api_key=api_key) mock_apikey.assert_called_with(username=user, api_key=api_key)
def test_with_region(self, mock_open=lambda: None): prof = mock.Mock() region = "BEN" connection.Connection(region=region, profile=prof, username="******", api_key="test") prof.set_region.assert_called_with(prof.ALL, region)
def __init__(self, key: str, secret: str = None, region: str = 'IAD', **kwargs: Dict) -> None: region = region.upper() if region not in self.regions: raise CloudStorageError(region_not_found % region) super().__init__(key=key, secret=secret, region=region) self._conn = connection.Connection(username=key, api_key=secret, region=region)
def __init__(self, key: str, secret: str = None, region: str = "IAD", **kwargs: Dict) -> None: region = region.upper() if region not in self.regions: raise CloudStorageError(messages.REGION_NOT_FOUND % region) super().__init__(key=key, secret=secret, region=region, **kwargs) self._conn = connection.Connection(username=key, api_key=secret, region=region)
'metadata', 'name', 'name_attribute', 'new', 'object_count', 'patch_update', 'pop', 'popitem', 'read_ACL', 'resource_key', 'resource_name', 'resources_key', 'service', 'set_headers', 'set_metadata', 'setdefault', 'sync_key', 'sync_to', 'timestamp', 'to_dict', 'update', 'update_attrs', 'update_by_id', 'values', 'versions_location', 'write_ACL'] obj [ 'accept_ranges', 'allow_create', 'allow_delete', 'allow_head', 'allow_list', 'allow_retrieve', 'allow_update', 'base_path', 'bytes', 'clear', 'container', 'content_disposition', 'content_encoding', 'content_length', 'content_type', 'convert_ids', 'copy_from', 'create', 'create_by_id', 'data', 'delete', 'delete_after', 'delete_at', 'delete_by_id', 'delete_metadata', 'etag', 'existing', 'expires_at', 'find', 'from_id', 'from_name', 'get', 'get_by_id', 'get_data_by_id', 'get_headers', 'get_id', 'get_resource_name', 'hash', 'head', 'head_by_id', 'head_data_by_id', 'id', 'id_attribute', 'if_match', 'if_modified_since', 'if_none_match', 'if_unmodified_since', 'is_content_type_detected', 'is_dirty', 'is_newest', 'is_static_large_object', 'items', 'iteritems', 'iterkeys', 'itervalues', 'keys', 'last_modified_at', 'list', 'location', 'metadata', 'multipart_manifest', 'name', 'name_attribute', 'new', 'object_manifest', 'patch_update', 'pop', 'popitem', 'range', 'resource_key', 'resource_name', 'resources_key', 'service', 'set_headers', 'set_metadata', 'setdefault', 'signature', 'timestamp', 'to_dict', 'transfer_encoding', 'update', 'update_attrs', 'update_by_id', 'values'] """ conn = connection.Connection( username=settings.RACKSPACE_CLOUD_FILES["username"], api_key=settings.RACKSPACE_CLOUD_FILES["key"], region=settings.RACKSPACE_CLOUD_FILES["region"] ) @deconstructible class RackspaceStorage(FileSystemStorage): def __init__(self, *args, **kwargs): if not settings.USE_RACKSPACE: return None default_container = kwargs.get( "container", settings.RACKSPACE_CLOUD_FILES["default_container"]) self.purpose = kwargs.pop("purpose") self.container = conn.object_store.get_container_metadata( default_container)
def test_no_region(self): with self.assertRaises(ValueError): connection.Connection()
[ 'accept_ranges', 'allow_create', 'allow_delete', 'allow_head', 'allow_list', 'allow_retrieve', 'allow_update', 'base_path', 'bytes', 'clear', 'container', 'content_disposition', 'content_encoding', 'content_length', 'content_type', 'convert_ids', 'copy_from', 'create', 'create_by_id', 'data', 'delete', 'delete_after', 'delete_at', 'delete_by_id', 'delete_metadata', 'etag', 'existing', 'expires_at', 'find', 'from_id', 'from_name', 'get', 'get_by_id', 'get_data_by_id', 'get_headers', 'get_id', 'get_resource_name', 'hash', 'head', 'head_by_id', 'head_data_by_id', 'id', 'id_attribute', 'if_match', 'if_modified_since', 'if_none_match', 'if_unmodified_since', 'is_content_type_detected', 'is_dirty', 'is_newest', 'is_static_large_object', 'items', 'iteritems', 'iterkeys', 'itervalues', 'keys', 'last_modified_at', 'list', 'location', 'metadata', 'multipart_manifest', 'name', 'name_attribute', 'new', 'object_manifest', 'patch_update', 'pop', 'popitem', 'range', 'resource_key', 'resource_name', 'resources_key', 'service', 'set_headers', 'set_metadata', 'setdefault', 'signature', 'timestamp', 'to_dict', 'transfer_encoding', 'update', 'update_attrs', 'update_by_id', 'values'] """ RACKSPACE_CONFIG = getattr(settings, "RACKSPACE_CLOUD_FILES", {}) USE_RACKSPACE = getattr(settings, "USE_RACKSPACE", False) username = RACKSPACE_CONFIG.get("username") api_key = RACKSPACE_CONFIG.get("key") region = RACKSPACE_CONFIG.get("region") default_container_config = RACKSPACE_CONFIG.get("default_container") try: conn = connection.Connection(username=username, api_key=api_key, region=region) except: conn = None @deconstructible class RackspaceStorage(FileSystemStorage): def __init__(self, *args, **kwargs): if not USE_RACKSPACE: return None # exception if migration file has already use rackspace try: default_container = kwargs.get("container", default_container_config)
def __init__(self): """Setup clients for Rackspace and AWS.""" self.rackspace = connection.Connection(username=config.RACKSPACE_USER, api_key=config.RACKSPACE_API, region=config.RACKSPACE_REGION) self.aws = boto3.resource('s3')