From 4010451e18103dc181600a0f7385c1dbe5d7a8b5 Mon Sep 17 00:00:00 2001 From: "Ryan S. Brown" Date: Sat, 21 Nov 2015 07:36:46 -0500 Subject: [PATCH] Support creating signed url's in client This change adds a function to create signed URLs, but does not create a domain object or add them to the CLI. Change-Id: I14d3c6aa6d7a5c8c5bf732e86cf9a24ca1342fad --- zaqarclient/queues/v2/api.py | 27 ++++++++++++++++++++ zaqarclient/queues/v2/core.py | 48 +++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/zaqarclient/queues/v2/api.py b/zaqarclient/queues/v2/api.py index cabeef30..806a18ae 100644 --- a/zaqarclient/queues/v2/api.py +++ b/zaqarclient/queues/v2/api.py @@ -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'} + }, + } +}) diff --git a/zaqarclient/queues/v2/core.py b/zaqarclient/queues/v2/core.py index 0ee7c1e5..bb566f36 100644 --- a/zaqarclient/queues/v2/core.py +++ b/zaqarclient/queues/v2/core.py @@ -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