You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by qu...@apache.org on 2017/10/16 06:28:33 UTC
[4/5] libcloud git commit: Define contants and test for error states.
Define contants and test for error states.
Signed-off-by: Quentin Pradet <qu...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/6d01dda5
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/6d01dda5
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/6d01dda5
Branch: refs/heads/trunk
Commit: 6d01dda509b0df827252f3106f8bfb7e933c3ad7
Parents: 24584e6
Author: Andrew Starr-Bochicchio <a....@gmail.com>
Authored: Sun Oct 15 13:05:22 2017 -0400
Committer: Quentin Pradet <qu...@apache.org>
Committed: Mon Oct 16 10:24:58 2017 +0400
----------------------------------------------------------------------
libcloud/storage/drivers/digitalocean_spaces.py | 18 +++++++++---------
libcloud/test/storage/test_digitalocean_spaces.py | 14 ++++++++++++++
2 files changed, 23 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/6d01dda5/libcloud/storage/drivers/digitalocean_spaces.py
----------------------------------------------------------------------
diff --git a/libcloud/storage/drivers/digitalocean_spaces.py b/libcloud/storage/drivers/digitalocean_spaces.py
index 1808b4d..9f6768c 100644
--- a/libcloud/storage/drivers/digitalocean_spaces.py
+++ b/libcloud/storage/drivers/digitalocean_spaces.py
@@ -14,22 +14,23 @@
# limitations under the License.
from libcloud.common.types import LibcloudError
-from libcloud.common.aws import SignedAWSConnection, DEFAULT_SIGNATURE_VERSION
+from libcloud.common.aws import SignedAWSConnection
from libcloud.storage.drivers.s3 import BaseS3Connection, S3Connection
-from libcloud.storage.drivers.s3 import S3StorageDriver, API_VERSION
+from libcloud.storage.drivers.s3 import S3StorageDriver
__all__ = [
'DigitalOceanSpacesStorageDriver'
]
DO_SPACES_HOSTS_BY_REGION = {'nyc3': 'nyc3.digitaloceanspaces.com'}
-
DO_SPACES_DEFAULT_REGION = 'nyc3'
+DEFAULT_SIGNATURE_VERSION = '2'
+S3_API_VERSION = '2006-03-01'
class DOSpacesConnectionAWS4(SignedAWSConnection, BaseS3Connection):
service_name = 's3'
- version = API_VERSION
+ version = S3_API_VERSION
def __init__(self, user_id, key, secure=True, host=None, port=None,
url=None, timeout=None, proxy_url=None, token=None,
@@ -42,7 +43,7 @@ class DOSpacesConnectionAWS4(SignedAWSConnection, BaseS3Connection):
proxy_url, token,
retry_delay,
backoff,
- 4) # force aws4
+ signature_version=4)
class DOSpacesConnectionAWS2(S3Connection):
@@ -79,14 +80,13 @@ class DigitalOceanSpacesStorageDriver(S3StorageDriver):
self.signature_version = str(kwargs.pop('signature_version',
DEFAULT_SIGNATURE_VERSION))
- if self.signature_version not in ['2', '4']:
- raise ValueError('Invalid signature_version: %s' %
- (self.signature_version))
-
if self.signature_version == '2':
self.connectionCls = DOSpacesConnectionAWS2
elif self.signature_version == '4':
self.connectionCls = DOSpacesConnectionAWS4
+ else:
+ raise ValueError('Invalid signature_version: %s' %
+ (self.signature_version))
self.connectionCls.host = host
super(DigitalOceanSpacesStorageDriver,
http://git-wip-us.apache.org/repos/asf/libcloud/blob/6d01dda5/libcloud/test/storage/test_digitalocean_spaces.py
----------------------------------------------------------------------
diff --git a/libcloud/test/storage/test_digitalocean_spaces.py b/libcloud/test/storage/test_digitalocean_spaces.py
index 47f4779..7c32deb 100644
--- a/libcloud/test/storage/test_digitalocean_spaces.py
+++ b/libcloud/test/storage/test_digitalocean_spaces.py
@@ -16,6 +16,8 @@
import sys
import unittest
+from libcloud.common.types import LibcloudError
+
from libcloud.storage.base import Container, Object
from libcloud.storage.drivers.digitalocean_spaces import (
DigitalOceanSpacesStorageDriver,
@@ -67,6 +69,18 @@ class DigitalOceanSpacesTests(LibcloudTestCase):
with self.assertRaises(NotImplementedError):
self.object.get_cdn_url()
+ def test_invalid_signature_version(self):
+ with self.assertRaises(ValueError):
+ self.driver_type(*self.driver_args,
+ signature_version='3',
+ host=self.default_host)
+
+ def test_invalid_region(self):
+ with self.assertRaises(LibcloudError):
+ self.driver_type(*self.driver_args,
+ region='atlantis',
+ host=self.default_host)
+
class DigitalOceanSpacesTests_v4(DigitalOceanSpacesTests):
driver_type = DigitalOceanSpacesStorageDriver