diff --git a/swh/objstorage/__init__.py b/swh/objstorage/__init__.py --- a/swh/objstorage/__init__.py +++ b/swh/objstorage/__init__.py @@ -40,6 +40,17 @@ except ImportError as e: _STORAGE_CLASSES_MISSING['rados'] = e.args[0] +try: + from swh.objstorage.cloud.objstorage_cloud import ( + AwsCloudObjStorage, + OpenStackCloudObjStorage, + ) + _STORAGE_CLASSES['s3'] = AwsCloudObjStorage + _STORAGE_CLASSES['swift'] = OpenStackCloudObjStorage +except ImportError as e: + _STORAGE_CLASSES_MISSING['s3'] = e.args[0] + _STORAGE_CLASSES_MISSING['swift'] = e.args[0] + def get_objstorage(cls, args): """ Create an ObjStorage using the given implementation class. diff --git a/swh/objstorage/cloud/objstorage_cloud.py b/swh/objstorage/cloud/objstorage_cloud.py --- a/swh/objstorage/cloud/objstorage_cloud.py +++ b/swh/objstorage/cloud/objstorage_cloud.py @@ -22,19 +22,24 @@ https://libcloud.readthedocs.io/en/latest/storage/api.html). """ - def __init__(self, api_key, api_secret_key, container_name, **kwargs): + def __init__(self, container_name, **kwargs): super().__init__(**kwargs) - self.driver = self._get_driver(api_key, api_secret_key) + self.driver = self._get_driver(**kwargs) self.container_name = container_name self.container = self.driver.get_container( container_name=container_name) - def _get_driver(self, api_key, api_secret_key): + def _get_driver(self, **kwargs): """Initialize a driver to communicate with the cloud - Args: - api_key: key to connect to the API. - api_secret_key: secret key for authentication. + Kwargs: arguments passed to the StorageDriver class, typically + key: key to connect to the API. + secret: secret key for authentication. + secure: (bool) support HTTPS + host: (str) + port: (int) + api_version: (str) + region: (str) Returns: a Libcloud driver to a cloud storage. @@ -42,8 +47,9 @@ """ # Get the driver class from its description. cls = providers.get_driver(self._get_provider()) + cls.namespace = None # Initialize the driver. - return cls(api_key, api_secret_key) + return cls(**kwargs) @abc.abstractmethod def _get_provider(self):