2015-06-11 22:30:18 +00:00
|
|
|
package storage
|
|
|
|
|
2018-05-21 19:05:11 +00:00
|
|
|
// Copyright 2017 Microsoft Corporation
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2015-06-11 22:30:18 +00:00
|
|
|
import (
|
|
|
|
"encoding/xml"
|
|
|
|
"fmt"
|
2018-05-21 19:05:11 +00:00
|
|
|
"io"
|
2015-06-11 22:30:18 +00:00
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
"strconv"
|
2018-05-21 19:05:11 +00:00
|
|
|
"time"
|
2016-02-08 22:29:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// casing is per Golang's http.Header canonicalizing the header names.
|
2018-05-21 19:05:11 +00:00
|
|
|
approximateMessagesCountHeader = "X-Ms-Approximate-Messages-Count"
|
2015-06-11 22:30:18 +00:00
|
|
|
)
|
|
|
|
|
2018-05-21 19:05:11 +00:00
|
|
|
// QueueAccessPolicy represents each access policy in the queue ACL.
|
|
|
|
type QueueAccessPolicy struct {
|
|
|
|
ID string
|
|
|
|
StartTime time.Time
|
|
|
|
ExpiryTime time.Time
|
|
|
|
CanRead bool
|
|
|
|
CanAdd bool
|
|
|
|
CanUpdate bool
|
|
|
|
CanProcess bool
|
|
|
|
}
|
2015-06-11 22:30:18 +00:00
|
|
|
|
2018-05-21 19:05:11 +00:00
|
|
|
// QueuePermissions represents the queue ACLs.
|
|
|
|
type QueuePermissions struct {
|
|
|
|
AccessPolicies []QueueAccessPolicy
|
2015-06-11 22:30:18 +00:00
|
|
|
}
|
|
|
|
|
2018-05-21 19:05:11 +00:00
|
|
|
// SetQueuePermissionOptions includes options for a set queue permissions operation
|
|
|
|
type SetQueuePermissionOptions struct {
|
|
|
|
Timeout uint
|
|
|
|
RequestID string `header:"x-ms-client-request-id"`
|
2015-06-11 22:30:18 +00:00
|
|
|
}
|
|
|
|
|
2018-05-21 19:05:11 +00:00
|
|
|
// Queue represents an Azure queue.
|
|
|
|
type Queue struct {
|
|
|
|
qsc *QueueServiceClient
|
|
|
|
Name string
|
|
|
|
Metadata map[string]string
|
|
|
|
AproxMessageCount uint64
|
2015-06-11 22:30:18 +00:00
|
|
|
}
|
|
|
|
|
2018-05-21 19:05:11 +00:00
|
|
|
func (q *Queue) buildPath() string {
|
|
|
|
return fmt.Sprintf("/%s", q.Name)
|
2015-06-11 22:30:18 +00:00
|
|
|
}
|
|
|
|
|
2018-05-21 19:05:11 +00:00
|
|
|
func (q *Queue) buildPathMessages() string {
|
|
|
|
return fmt.Sprintf("%s/messages", q.buildPath())
|
2015-06-11 22:30:18 +00:00
|
|
|
}
|
|
|
|
|
2018-05-21 19:05:11 +00:00
|
|
|
// QueueServiceOptions includes options for some queue service operations
|
|
|
|
type QueueServiceOptions struct {
|
|
|
|
Timeout uint
|
|
|
|
RequestID string `header:"x-ms-client-request-id"`
|
2015-06-11 22:30:18 +00:00
|
|
|
}
|
|
|
|
|
2018-05-21 19:05:11 +00:00
|
|
|
// Create operation creates a queue under the given account.
|
|
|
|
//
|
|
|
|
// See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/Create-Queue4
|
|
|
|
func (q *Queue) Create(options *QueueServiceOptions) error {
|
|
|
|
params := url.Values{}
|
|
|
|
headers := q.qsc.client.getStandardHeaders()
|
|
|
|
headers = q.qsc.client.addMetadataToHeaders(headers, q.Metadata)
|
|
|
|
|
|
|
|
if options != nil {
|
|
|
|
params = addTimeout(params, options.Timeout)
|
|
|
|
headers = mergeHeaders(headers, headersFromStruct(*options))
|
2015-06-11 22:30:18 +00:00
|
|
|
}
|
2018-05-21 19:05:11 +00:00
|
|
|
uri := q.qsc.client.getEndpoint(queueServiceName, q.buildPath(), params)
|
2015-06-11 22:30:18 +00:00
|
|
|
|
2018-05-21 19:05:11 +00:00
|
|
|
resp, err := q.qsc.client.exec(http.MethodPut, uri, headers, nil, q.qsc.auth)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer drainRespBody(resp)
|
|
|
|
return checkRespCode(resp, []int{http.StatusCreated})
|
2016-12-13 05:12:39 +00:00
|
|
|
}
|
|
|
|
|
2018-05-21 19:05:11 +00:00
|
|
|
// Delete operation permanently deletes the specified queue.
|
|
|
|
//
|
|
|
|
// See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/Delete-Queue3
|
|
|
|
func (q *Queue) Delete(options *QueueServiceOptions) error {
|
|
|
|
params := url.Values{}
|
|
|
|
headers := q.qsc.client.getStandardHeaders()
|
|
|
|
|
|
|
|
if options != nil {
|
|
|
|
params = addTimeout(params, options.Timeout)
|
|
|
|
headers = mergeHeaders(headers, headersFromStruct(*options))
|
2016-12-13 05:12:39 +00:00
|
|
|
}
|
2018-05-21 19:05:11 +00:00
|
|
|
uri := q.qsc.client.getEndpoint(queueServiceName, q.buildPath(), params)
|
|
|
|
resp, err := q.qsc.client.exec(http.MethodDelete, uri, headers, nil, q.qsc.auth)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2016-12-13 05:12:39 +00:00
|
|
|
}
|
2018-05-21 19:05:11 +00:00
|
|
|
defer drainRespBody(resp)
|
|
|
|
return checkRespCode(resp, []int{http.StatusNoContent})
|
2015-06-11 22:30:18 +00:00
|
|
|
}
|
|
|
|
|
2018-05-21 19:05:11 +00:00
|
|
|
// Exists returns true if a queue with given name exists.
|
|
|
|
func (q *Queue) Exists() (bool, error) {
|
|
|
|
uri := q.qsc.client.getEndpoint(queueServiceName, q.buildPath(), url.Values{"comp": {"metadata"}})
|
|
|
|
resp, err := q.qsc.client.exec(http.MethodGet, uri, q.qsc.client.getStandardHeaders(), nil, q.qsc.auth)
|
|
|
|
if resp != nil {
|
|
|
|
defer drainRespBody(resp)
|
|
|
|
if resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusNotFound {
|
|
|
|
return resp.StatusCode == http.StatusOK, nil
|
|
|
|
}
|
|
|
|
err = getErrorFromResponse(resp)
|
|
|
|
}
|
|
|
|
return false, err
|
2016-02-08 22:29:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetMetadata operation sets user-defined metadata on the specified queue.
|
|
|
|
// Metadata is associated with the queue as name-value pairs.
|
|
|
|
//
|
2018-05-21 19:05:11 +00:00
|
|
|
// See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/Set-Queue-Metadata
|
|
|
|
func (q *Queue) SetMetadata(options *QueueServiceOptions) error {
|
|
|
|
params := url.Values{"comp": {"metadata"}}
|
|
|
|
headers := q.qsc.client.getStandardHeaders()
|
|
|
|
headers = q.qsc.client.addMetadataToHeaders(headers, q.Metadata)
|
|
|
|
|
|
|
|
if options != nil {
|
|
|
|
params = addTimeout(params, options.Timeout)
|
|
|
|
headers = mergeHeaders(headers, headersFromStruct(*options))
|
2016-02-08 22:29:21 +00:00
|
|
|
}
|
2018-05-21 19:05:11 +00:00
|
|
|
uri := q.qsc.client.getEndpoint(queueServiceName, q.buildPath(), params)
|
2016-02-08 22:29:21 +00:00
|
|
|
|
2018-05-21 19:05:11 +00:00
|
|
|
resp, err := q.qsc.client.exec(http.MethodPut, uri, headers, nil, q.qsc.auth)
|
2016-02-08 22:29:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-05-21 19:05:11 +00:00
|
|
|
defer drainRespBody(resp)
|
|
|
|
return checkRespCode(resp, []int{http.StatusNoContent})
|
2016-02-08 22:29:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetMetadata operation retrieves user-defined metadata and queue
|
|
|
|
// properties on the specified queue. Metadata is associated with
|
|
|
|
// the queue as name-values pairs.
|
|
|
|
//
|
2018-05-21 19:05:11 +00:00
|
|
|
// See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/Set-Queue-Metadata
|
2016-02-08 22:29:21 +00:00
|
|
|
//
|
|
|
|
// Because the way Golang's http client (and http.Header in particular)
|
|
|
|
// canonicalize header names, the returned metadata names would always
|
|
|
|
// be all lower case.
|
2018-05-21 19:05:11 +00:00
|
|
|
func (q *Queue) GetMetadata(options *QueueServiceOptions) error {
|
|
|
|
params := url.Values{"comp": {"metadata"}}
|
|
|
|
headers := q.qsc.client.getStandardHeaders()
|
|
|
|
|
|
|
|
if options != nil {
|
|
|
|
params = addTimeout(params, options.Timeout)
|
|
|
|
headers = mergeHeaders(headers, headersFromStruct(*options))
|
2016-02-08 22:29:21 +00:00
|
|
|
}
|
2018-05-21 19:05:11 +00:00
|
|
|
uri := q.qsc.client.getEndpoint(queueServiceName, q.buildPath(), url.Values{"comp": {"metadata"}})
|
2016-02-08 22:29:21 +00:00
|
|
|
|
2018-05-21 19:05:11 +00:00
|
|
|
resp, err := q.qsc.client.exec(http.MethodGet, uri, headers, nil, q.qsc.auth)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer drainRespBody(resp)
|
2016-02-08 22:29:21 +00:00
|
|
|
|
2018-05-21 19:05:11 +00:00
|
|
|
if err := checkRespCode(resp, []int{http.StatusOK}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-02-08 22:29:21 +00:00
|
|
|
|
2018-05-21 19:05:11 +00:00
|
|
|
aproxMessagesStr := resp.Header.Get(http.CanonicalHeaderKey(approximateMessagesCountHeader))
|
|
|
|
if aproxMessagesStr != "" {
|
|
|
|
aproxMessages, err := strconv.ParseUint(aproxMessagesStr, 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2016-02-08 22:29:21 +00:00
|
|
|
}
|
2018-05-21 19:05:11 +00:00
|
|
|
q.AproxMessageCount = aproxMessages
|
2016-02-08 22:29:21 +00:00
|
|
|
}
|
|
|
|
|
2018-05-21 19:05:11 +00:00
|
|
|
q.Metadata = getMetadataFromHeaders(resp.Header)
|
|
|
|
return nil
|
2016-02-08 22:29:21 +00:00
|
|
|
}
|
|
|
|
|
2018-05-21 19:05:11 +00:00
|
|
|
// GetMessageReference returns a message object with the specified text.
|
|
|
|
func (q *Queue) GetMessageReference(text string) *Message {
|
|
|
|
return &Message{
|
|
|
|
Queue: q,
|
|
|
|
Text: text,
|
2015-06-11 22:30:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-21 19:05:11 +00:00
|
|
|
// GetMessagesOptions is the set of options can be specified for Get
|
|
|
|
// Messsages operation. A zero struct does not use any preferences for the
|
|
|
|
// request.
|
|
|
|
type GetMessagesOptions struct {
|
|
|
|
Timeout uint
|
|
|
|
NumOfMessages int
|
|
|
|
VisibilityTimeout int
|
|
|
|
RequestID string `header:"x-ms-client-request-id"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type messages struct {
|
|
|
|
XMLName xml.Name `xml:"QueueMessagesList"`
|
|
|
|
Messages []Message `xml:"QueueMessage"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetMessages operation retrieves one or more messages from the front of the
|
|
|
|
// queue.
|
2015-06-11 22:30:18 +00:00
|
|
|
//
|
2018-05-21 19:05:11 +00:00
|
|
|
// See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/Get-Messages
|
|
|
|
func (q *Queue) GetMessages(options *GetMessagesOptions) ([]Message, error) {
|
|
|
|
query := url.Values{}
|
|
|
|
headers := q.qsc.client.getStandardHeaders()
|
|
|
|
|
|
|
|
if options != nil {
|
|
|
|
if options.NumOfMessages != 0 {
|
|
|
|
query.Set("numofmessages", strconv.Itoa(options.NumOfMessages))
|
|
|
|
}
|
|
|
|
if options.VisibilityTimeout != 0 {
|
|
|
|
query.Set("visibilitytimeout", strconv.Itoa(options.VisibilityTimeout))
|
|
|
|
}
|
|
|
|
query = addTimeout(query, options.Timeout)
|
|
|
|
headers = mergeHeaders(headers, headersFromStruct(*options))
|
|
|
|
}
|
|
|
|
uri := q.qsc.client.getEndpoint(queueServiceName, q.buildPathMessages(), query)
|
|
|
|
|
|
|
|
resp, err := q.qsc.client.exec(http.MethodGet, uri, headers, nil, q.qsc.auth)
|
2015-06-11 22:30:18 +00:00
|
|
|
if err != nil {
|
2018-05-21 19:05:11 +00:00
|
|
|
return []Message{}, err
|
2015-06-11 22:30:18 +00:00
|
|
|
}
|
2018-05-21 19:05:11 +00:00
|
|
|
defer resp.Body.Close()
|
2015-06-11 22:30:18 +00:00
|
|
|
|
2018-05-21 19:05:11 +00:00
|
|
|
var out messages
|
|
|
|
err = xmlUnmarshal(resp.Body, &out)
|
|
|
|
if err != nil {
|
|
|
|
return []Message{}, err
|
|
|
|
}
|
|
|
|
for i := range out.Messages {
|
|
|
|
out.Messages[i].Queue = q
|
2015-06-11 22:30:18 +00:00
|
|
|
}
|
2018-05-21 19:05:11 +00:00
|
|
|
return out.Messages, err
|
|
|
|
}
|
2015-06-11 22:30:18 +00:00
|
|
|
|
2018-05-21 19:05:11 +00:00
|
|
|
// PeekMessagesOptions is the set of options can be specified for Peek
|
|
|
|
// Messsage operation. A zero struct does not use any preferences for the
|
|
|
|
// request.
|
|
|
|
type PeekMessagesOptions struct {
|
|
|
|
Timeout uint
|
|
|
|
NumOfMessages int
|
|
|
|
RequestID string `header:"x-ms-client-request-id"`
|
2015-06-11 22:30:18 +00:00
|
|
|
}
|
|
|
|
|
2018-05-21 19:05:11 +00:00
|
|
|
// PeekMessages retrieves one or more messages from the front of the queue, but
|
|
|
|
// does not alter the visibility of the message.
|
2015-06-11 22:30:18 +00:00
|
|
|
//
|
2018-05-21 19:05:11 +00:00
|
|
|
// See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/Peek-Messages
|
|
|
|
func (q *Queue) PeekMessages(options *PeekMessagesOptions) ([]Message, error) {
|
|
|
|
query := url.Values{"peekonly": {"true"}} // Required for peek operation
|
|
|
|
headers := q.qsc.client.getStandardHeaders()
|
|
|
|
|
|
|
|
if options != nil {
|
|
|
|
if options.NumOfMessages != 0 {
|
|
|
|
query.Set("numofmessages", strconv.Itoa(options.NumOfMessages))
|
|
|
|
}
|
|
|
|
query = addTimeout(query, options.Timeout)
|
|
|
|
headers = mergeHeaders(headers, headersFromStruct(*options))
|
|
|
|
}
|
|
|
|
uri := q.qsc.client.getEndpoint(queueServiceName, q.buildPathMessages(), query)
|
|
|
|
|
|
|
|
resp, err := q.qsc.client.exec(http.MethodGet, uri, headers, nil, q.qsc.auth)
|
2015-06-11 22:30:18 +00:00
|
|
|
if err != nil {
|
2018-05-21 19:05:11 +00:00
|
|
|
return []Message{}, err
|
2015-06-11 22:30:18 +00:00
|
|
|
}
|
2018-05-21 19:05:11 +00:00
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var out messages
|
|
|
|
err = xmlUnmarshal(resp.Body, &out)
|
2015-06-11 22:30:18 +00:00
|
|
|
if err != nil {
|
2018-05-21 19:05:11 +00:00
|
|
|
return []Message{}, err
|
|
|
|
}
|
|
|
|
for i := range out.Messages {
|
|
|
|
out.Messages[i].Queue = q
|
2015-06-11 22:30:18 +00:00
|
|
|
}
|
2018-05-21 19:05:11 +00:00
|
|
|
return out.Messages, err
|
2015-06-11 22:30:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ClearMessages operation deletes all messages from the specified queue.
|
|
|
|
//
|
2018-05-21 19:05:11 +00:00
|
|
|
// See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/Clear-Messages
|
|
|
|
func (q *Queue) ClearMessages(options *QueueServiceOptions) error {
|
|
|
|
params := url.Values{}
|
|
|
|
headers := q.qsc.client.getStandardHeaders()
|
|
|
|
|
|
|
|
if options != nil {
|
|
|
|
params = addTimeout(params, options.Timeout)
|
|
|
|
headers = mergeHeaders(headers, headersFromStruct(*options))
|
|
|
|
}
|
|
|
|
uri := q.qsc.client.getEndpoint(queueServiceName, q.buildPathMessages(), params)
|
|
|
|
|
|
|
|
resp, err := q.qsc.client.exec(http.MethodDelete, uri, headers, nil, q.qsc.auth)
|
2015-06-11 22:30:18 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-05-21 19:05:11 +00:00
|
|
|
defer drainRespBody(resp)
|
|
|
|
return checkRespCode(resp, []int{http.StatusNoContent})
|
2015-06-11 22:30:18 +00:00
|
|
|
}
|
|
|
|
|
2018-05-21 19:05:11 +00:00
|
|
|
// SetPermissions sets up queue permissions
|
|
|
|
// See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/set-queue-acl
|
|
|
|
func (q *Queue) SetPermissions(permissions QueuePermissions, options *SetQueuePermissionOptions) error {
|
|
|
|
body, length, err := generateQueueACLpayload(permissions.AccessPolicies)
|
2015-06-11 22:30:18 +00:00
|
|
|
if err != nil {
|
2018-05-21 19:05:11 +00:00
|
|
|
return err
|
2015-06-11 22:30:18 +00:00
|
|
|
}
|
|
|
|
|
2018-05-21 19:05:11 +00:00
|
|
|
params := url.Values{
|
|
|
|
"comp": {"acl"},
|
2015-06-11 22:30:18 +00:00
|
|
|
}
|
2018-05-21 19:05:11 +00:00
|
|
|
headers := q.qsc.client.getStandardHeaders()
|
|
|
|
headers["Content-Length"] = strconv.Itoa(length)
|
2015-06-11 22:30:18 +00:00
|
|
|
|
2018-05-21 19:05:11 +00:00
|
|
|
if options != nil {
|
|
|
|
params = addTimeout(params, options.Timeout)
|
|
|
|
headers = mergeHeaders(headers, headersFromStruct(*options))
|
|
|
|
}
|
|
|
|
uri := q.qsc.client.getEndpoint(queueServiceName, q.buildPath(), params)
|
|
|
|
resp, err := q.qsc.client.exec(http.MethodPut, uri, headers, body, q.qsc.auth)
|
2015-06-11 22:30:18 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-05-21 19:05:11 +00:00
|
|
|
defer drainRespBody(resp)
|
|
|
|
return checkRespCode(resp, []int{http.StatusNoContent})
|
2015-06-11 22:30:18 +00:00
|
|
|
}
|
2016-12-13 05:12:39 +00:00
|
|
|
|
2018-05-21 19:05:11 +00:00
|
|
|
func generateQueueACLpayload(policies []QueueAccessPolicy) (io.Reader, int, error) {
|
|
|
|
sil := SignedIdentifiers{
|
|
|
|
SignedIdentifiers: []SignedIdentifier{},
|
|
|
|
}
|
|
|
|
for _, qapd := range policies {
|
|
|
|
permission := qapd.generateQueuePermissions()
|
|
|
|
signedIdentifier := convertAccessPolicyToXMLStructs(qapd.ID, qapd.StartTime, qapd.ExpiryTime, permission)
|
|
|
|
sil.SignedIdentifiers = append(sil.SignedIdentifiers, signedIdentifier)
|
|
|
|
}
|
|
|
|
return xmlMarshal(sil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (qapd *QueueAccessPolicy) generateQueuePermissions() (permissions string) {
|
|
|
|
// generate the permissions string (raup).
|
|
|
|
// still want the end user API to have bool flags.
|
|
|
|
permissions = ""
|
|
|
|
|
|
|
|
if qapd.CanRead {
|
|
|
|
permissions += "r"
|
|
|
|
}
|
|
|
|
|
|
|
|
if qapd.CanAdd {
|
|
|
|
permissions += "a"
|
|
|
|
}
|
|
|
|
|
|
|
|
if qapd.CanUpdate {
|
|
|
|
permissions += "u"
|
|
|
|
}
|
|
|
|
|
|
|
|
if qapd.CanProcess {
|
|
|
|
permissions += "p"
|
|
|
|
}
|
|
|
|
|
|
|
|
return permissions
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetQueuePermissionOptions includes options for a get queue permissions operation
|
|
|
|
type GetQueuePermissionOptions struct {
|
|
|
|
Timeout uint
|
|
|
|
RequestID string `header:"x-ms-client-request-id"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetPermissions gets the queue permissions as per https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/get-queue-acl
|
|
|
|
// If timeout is 0 then it will not be passed to Azure
|
|
|
|
func (q *Queue) GetPermissions(options *GetQueuePermissionOptions) (*QueuePermissions, error) {
|
|
|
|
params := url.Values{
|
|
|
|
"comp": {"acl"},
|
|
|
|
}
|
|
|
|
headers := q.qsc.client.getStandardHeaders()
|
|
|
|
|
|
|
|
if options != nil {
|
|
|
|
params = addTimeout(params, options.Timeout)
|
|
|
|
headers = mergeHeaders(headers, headersFromStruct(*options))
|
|
|
|
}
|
|
|
|
uri := q.qsc.client.getEndpoint(queueServiceName, q.buildPath(), params)
|
|
|
|
resp, err := q.qsc.client.exec(http.MethodGet, uri, headers, nil, q.qsc.auth)
|
2016-12-13 05:12:39 +00:00
|
|
|
if err != nil {
|
2018-05-21 19:05:11 +00:00
|
|
|
return nil, err
|
2016-12-13 05:12:39 +00:00
|
|
|
}
|
2018-05-21 19:05:11 +00:00
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var ap AccessPolicy
|
|
|
|
err = xmlUnmarshal(resp.Body, &ap.SignedIdentifiersList)
|
2016-12-13 05:12:39 +00:00
|
|
|
if err != nil {
|
2018-05-21 19:05:11 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return buildQueueAccessPolicy(ap, &resp.Header), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func buildQueueAccessPolicy(ap AccessPolicy, headers *http.Header) *QueuePermissions {
|
|
|
|
permissions := QueuePermissions{
|
|
|
|
AccessPolicies: []QueueAccessPolicy{},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, policy := range ap.SignedIdentifiersList.SignedIdentifiers {
|
|
|
|
qapd := QueueAccessPolicy{
|
|
|
|
ID: policy.ID,
|
|
|
|
StartTime: policy.AccessPolicy.StartTime,
|
|
|
|
ExpiryTime: policy.AccessPolicy.ExpiryTime,
|
|
|
|
}
|
|
|
|
qapd.CanRead = updatePermissions(policy.AccessPolicy.Permission, "r")
|
|
|
|
qapd.CanAdd = updatePermissions(policy.AccessPolicy.Permission, "a")
|
|
|
|
qapd.CanUpdate = updatePermissions(policy.AccessPolicy.Permission, "u")
|
|
|
|
qapd.CanProcess = updatePermissions(policy.AccessPolicy.Permission, "p")
|
|
|
|
|
|
|
|
permissions.AccessPolicies = append(permissions.AccessPolicies, qapd)
|
2016-12-13 05:12:39 +00:00
|
|
|
}
|
2018-05-21 19:05:11 +00:00
|
|
|
return &permissions
|
2016-12-13 05:12:39 +00:00
|
|
|
}
|