Merge "Support creating signed url's in client"

This commit is contained in:
Jenkins
2015-11-27 03:59:41 +00:00
committed by Gerrit Code Review
2 changed files with 75 additions and 0 deletions

View File

@@ -1,6 +1,33 @@
# Copyright (c) 2015 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from zaqarclient.queues.v1 import api
class V2(api.V1_1):
label = 'v2'
schema = api.V1_1.schema.copy()
V2.schema.update({
'signed_url_create': {
'ref': 'queues/{queue_name}/share',
'method': 'POST',
'required': ['queue_name'],
'properties': {
'queue_name': {'type': 'string'}
},
}
})

View File

@@ -27,6 +27,11 @@ Functions present in this module assume that:
request.
"""
import datetime
import json
from oslo_utils import timeutils
from zaqarclient.queues.v1 import core
queue_create = core.queue_create
@@ -41,3 +46,46 @@ message_list = core.message_list
message_post = core.message_post
message_delete = core.message_delete
message_delete_many = core.message_delete_many
def signed_url_create(transport, request, queue_name, paths=None,
ttl_seconds=None, project_id=None, methods=None):
"""Creates a signed URL given a queue name
:param transport: Transport instance to use
:type transport: `transport.base.Transport`
:param request: Request instance ready to be sent.
:type request: `transport.request.Request`
:param queue_name: name of Queue for the URL to access
:type name: `six.text_type`
:param paths: Allowed actions. Options: messages, subscriptions, claims
:type name: list
:param ttl_seconds: Seconds the URL will be valid for, default 86400
:type name: int
:param project_id: defaults to None
:type name: `six.text_type`
:param methods: HTTP methods to allow, defaults to ["GET"]
:type name: `list`
"""
request.operation = 'signed_url_create'
request.params['queue_name'] = queue_name
body = {}
if ttl_seconds is not None:
expiry = (timeutils.utcnow() + datetime.timedelta(seconds=ttl_seconds))
body['expires'] = expiry.isoformat()
if project_id is not None:
body['project_id'] = project_id
if paths is not None:
body['paths'] = paths
if methods is not None:
body['methods'] = methods
request.content = json.dumps(body)
resp = transport.send(request)
return resp.deserialized_content