Merge "Move set_temp_url_key logic into resource objects"
This commit is contained in:
commit
4c134a7ff7
|
@ -653,11 +653,8 @@ class Proxy(proxy.Proxy):
|
|||
:param bool secondary:
|
||||
Whether this should set the secondary key. (defaults to False)
|
||||
"""
|
||||
header = 'Temp-URL-Key'
|
||||
if secondary:
|
||||
header += '-2'
|
||||
|
||||
return self.set_account_metadata(**{header: key})
|
||||
account = self._get_resource(_account.Account, None)
|
||||
account.set_temp_url_key(self, key, secondary)
|
||||
|
||||
def set_container_temp_url_key(self, container, key, secondary=False):
|
||||
"""Set the temporary URL key for a container.
|
||||
|
@ -670,11 +667,8 @@ class Proxy(proxy.Proxy):
|
|||
:param bool secondary:
|
||||
Whether this should set the secondary key. (defaults to False)
|
||||
"""
|
||||
header = 'Temp-URL-Key'
|
||||
if secondary:
|
||||
header += '-2'
|
||||
|
||||
return self.set_container_metadata(container, **{header: key})
|
||||
res = self._get_resource(_container.Container, container)
|
||||
res.set_temp_url_key(self, key, secondary)
|
||||
|
||||
def get_temp_url_key(self, container=None):
|
||||
"""Get the best temporary url key for a given container.
|
||||
|
|
|
@ -43,3 +43,19 @@ class Account(_base.BaseResource):
|
|||
|
||||
has_body = False
|
||||
requires_id = False
|
||||
|
||||
def set_temp_url_key(self, proxy, key, secondary=False):
|
||||
"""Set the temporary url key for the account.
|
||||
|
||||
:param proxy: The proxy to use for making this request.
|
||||
:type proxy: :class:`~openstack.proxy.Proxy`
|
||||
:param key:
|
||||
Text of the key to use.
|
||||
:param bool secondary:
|
||||
Whether this should set the secondary key. (defaults to False)
|
||||
"""
|
||||
header = 'Temp-URL-Key'
|
||||
if secondary:
|
||||
header += '-2'
|
||||
|
||||
return self.set_metadata(proxy, {header: key})
|
||||
|
|
|
@ -135,3 +135,22 @@ class Container(_base.BaseResource):
|
|||
|
||||
self._translate_response(response, has_body=False)
|
||||
return self
|
||||
|
||||
def set_temp_url_key(self, proxy, key, secondary=False):
|
||||
"""Set the temporary url key for a container.
|
||||
|
||||
:param proxy: The proxy to use for making this request.
|
||||
:type proxy: :class:`~openstack.proxy.Proxy`
|
||||
:param container:
|
||||
The value can be the name of a container or a
|
||||
:class:`~openstack.object_store.v1.container.Container` instance.
|
||||
:param key:
|
||||
Text of the key to use.
|
||||
:param bool secondary:
|
||||
Whether this should set the second key. (defaults to False)
|
||||
"""
|
||||
header = 'Temp-URL-Key'
|
||||
if secondary:
|
||||
header += '-2'
|
||||
|
||||
return self.set_metadata(proxy, {header: key})
|
||||
|
|
|
@ -31,6 +31,10 @@ ACCOUNT_EXAMPLE = {
|
|||
|
||||
class TestAccount(base.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestAccount, self).setUp()
|
||||
self.endpoint = self.cloud.object_store.get_endpoint() + '/'
|
||||
|
||||
def test_basic(self):
|
||||
sot = account.Account(**ACCOUNT_EXAMPLE)
|
||||
self.assertIsNone(sot.resources_key)
|
||||
|
@ -53,3 +57,37 @@ class TestAccount(base.TestCase):
|
|||
self.assertEqual(int(ACCOUNT_EXAMPLE['x-account-object-count']),
|
||||
sot.account_object_count)
|
||||
self.assertEqual(ACCOUNT_EXAMPLE['x-timestamp'], sot.timestamp)
|
||||
|
||||
def test_set_temp_url_key(self):
|
||||
sot = account.Account()
|
||||
key = 'super-secure-key'
|
||||
|
||||
self.register_uris([
|
||||
dict(method='POST', uri=self.endpoint,
|
||||
status_code=204,
|
||||
validate=dict(
|
||||
headers={
|
||||
'x-account-meta-temp-url-key': key})),
|
||||
dict(method='HEAD', uri=self.endpoint,
|
||||
headers={
|
||||
'x-account-meta-temp-url-key': key}),
|
||||
])
|
||||
sot.set_temp_url_key(self.cloud.object_store, key)
|
||||
self.assert_calls()
|
||||
|
||||
def test_set_account_temp_url_key_second(self):
|
||||
sot = account.Account()
|
||||
key = 'super-secure-key'
|
||||
|
||||
self.register_uris([
|
||||
dict(method='POST', uri=self.endpoint,
|
||||
status_code=204,
|
||||
validate=dict(
|
||||
headers={
|
||||
'x-account-meta-temp-url-key-2': key})),
|
||||
dict(method='HEAD', uri=self.endpoint,
|
||||
headers={
|
||||
'x-account-meta-temp-url-key-2': key}),
|
||||
])
|
||||
sot.set_temp_url_key(self.cloud.object_store, key, secondary=True)
|
||||
self.assert_calls()
|
||||
|
|
|
@ -212,3 +212,37 @@ class TestContainer(base.TestCase):
|
|||
sot = container.Container.new(name=self.container)
|
||||
self._test_no_headers(sot, sot.commit, 'POST')
|
||||
self.assert_no_calls()
|
||||
|
||||
def test_set_temp_url_key(self):
|
||||
sot = container.Container.new(name=self.container)
|
||||
key = self.getUniqueString()
|
||||
|
||||
self.register_uris([
|
||||
dict(method='POST', uri=self.container_endpoint,
|
||||
status_code=204,
|
||||
validate=dict(
|
||||
headers={
|
||||
'x-container-meta-temp-url-key': key})),
|
||||
dict(method='HEAD', uri=self.container_endpoint,
|
||||
headers={
|
||||
'x-container-meta-temp-url-key': key}),
|
||||
])
|
||||
sot.set_temp_url_key(self.cloud.object_store, key)
|
||||
self.assert_calls()
|
||||
|
||||
def test_set_temp_url_key_second(self):
|
||||
sot = container.Container.new(name=self.container)
|
||||
key = self.getUniqueString()
|
||||
|
||||
self.register_uris([
|
||||
dict(method='POST', uri=self.container_endpoint,
|
||||
status_code=204,
|
||||
validate=dict(
|
||||
headers={
|
||||
'x-container-meta-temp-url-key-2': key})),
|
||||
dict(method='HEAD', uri=self.container_endpoint,
|
||||
headers={
|
||||
'x-container-meta-temp-url-key-2': key}),
|
||||
])
|
||||
sot.set_temp_url_key(self.cloud.object_store, key, secondary=True)
|
||||
self.assert_calls()
|
||||
|
|
|
@ -15,7 +15,6 @@ import six
|
|||
import string
|
||||
import tempfile
|
||||
|
||||
from openstack.object_store.v1 import _proxy
|
||||
from openstack.object_store.v1 import account
|
||||
from openstack.object_store.v1 import container
|
||||
from openstack.object_store.v1 import obj
|
||||
|
@ -29,7 +28,11 @@ class TestObjectStoreProxy(test_proxy_base.TestProxyBase):
|
|||
|
||||
def setUp(self):
|
||||
super(TestObjectStoreProxy, self).setUp()
|
||||
self.proxy = _proxy.Proxy(self.session)
|
||||
self.proxy = self.cloud.object_store
|
||||
self.container = self.getUniqueString()
|
||||
self.endpoint = self.cloud.object_store.get_endpoint() + '/'
|
||||
self.container_endpoint = '{endpoint}{container}'.format(
|
||||
endpoint=self.endpoint, container=self.container)
|
||||
|
||||
def test_account_metadata_get(self):
|
||||
self.verify_head(self.proxy.get_account_metadata, account.Account)
|
||||
|
@ -100,12 +103,80 @@ class TestObjectStoreProxy(test_proxy_base.TestProxyBase):
|
|||
method_kwargs=kwargs,
|
||||
expected_kwargs=kwargs)
|
||||
|
||||
def test_set_temp_url_key(self):
|
||||
|
||||
key = 'super-secure-key'
|
||||
|
||||
self.register_uris([
|
||||
dict(method='POST', uri=self.endpoint,
|
||||
status_code=204,
|
||||
validate=dict(
|
||||
headers={
|
||||
'x-account-meta-temp-url-key': key})),
|
||||
dict(method='HEAD', uri=self.endpoint,
|
||||
headers={
|
||||
'x-account-meta-temp-url-key': key}),
|
||||
])
|
||||
self.proxy.set_account_temp_url_key(key)
|
||||
self.assert_calls()
|
||||
|
||||
def test_set_account_temp_url_key_second(self):
|
||||
|
||||
key = 'super-secure-key'
|
||||
|
||||
self.register_uris([
|
||||
dict(method='POST', uri=self.endpoint,
|
||||
status_code=204,
|
||||
validate=dict(
|
||||
headers={
|
||||
'x-account-meta-temp-url-key-2': key})),
|
||||
dict(method='HEAD', uri=self.endpoint,
|
||||
headers={
|
||||
'x-account-meta-temp-url-key-2': key}),
|
||||
])
|
||||
self.proxy.set_account_temp_url_key(key, secondary=True)
|
||||
self.assert_calls()
|
||||
|
||||
def test_set_container_temp_url_key(self):
|
||||
|
||||
key = 'super-secure-key'
|
||||
|
||||
self.register_uris([
|
||||
dict(method='POST', uri=self.container_endpoint,
|
||||
status_code=204,
|
||||
validate=dict(
|
||||
headers={
|
||||
'x-container-meta-temp-url-key': key})),
|
||||
dict(method='HEAD', uri=self.container_endpoint,
|
||||
headers={
|
||||
'x-container-meta-temp-url-key': key}),
|
||||
])
|
||||
self.proxy.set_container_temp_url_key(self.container, key)
|
||||
self.assert_calls()
|
||||
|
||||
def test_set_container_temp_url_key_second(self):
|
||||
|
||||
key = 'super-secure-key'
|
||||
|
||||
self.register_uris([
|
||||
dict(method='POST', uri=self.container_endpoint,
|
||||
status_code=204,
|
||||
validate=dict(
|
||||
headers={
|
||||
'x-container-meta-temp-url-key-2': key})),
|
||||
dict(method='HEAD', uri=self.container_endpoint,
|
||||
headers={
|
||||
'x-container-meta-temp-url-key-2': key}),
|
||||
])
|
||||
self.proxy.set_container_temp_url_key(
|
||||
self.container, key, secondary=True)
|
||||
self.assert_calls()
|
||||
|
||||
|
||||
class Test_containers(TestObjectStoreProxy):
|
||||
|
||||
def setUp(self):
|
||||
super(Test_containers, self).setUp()
|
||||
self.proxy = _proxy.Proxy(self.session)
|
||||
|
||||
self.containers_body = []
|
||||
for i in range(3):
|
||||
|
@ -180,7 +251,6 @@ class Test_objects(TestObjectStoreProxy):
|
|||
|
||||
def setUp(self):
|
||||
super(Test_objects, self).setUp()
|
||||
self.proxy = _proxy.Proxy(self.session)
|
||||
|
||||
self.container_name = six.text_type("my_container")
|
||||
|
||||
|
|
Loading…
Reference in New Issue