/* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * http://aws.amazon.com/apache2.0 * * or in the "license" file accompanying this file. This file 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. */ using System.Collections.Generic; using System.Threading.Tasks; using System.Globalization; using Amazon.Runtime; using Amazon.Runtime.SharedInterfaces; using Amazon.SQS.Model; using Amazon.Auth.AccessControlPolicy; using Amazon.Auth.AccessControlPolicy.ActionIdentifiers; namespace Amazon.SQS { public partial class AmazonSQSClient : AmazonServiceClient, IAmazonSQS { async Task> ICoreAmazonSQS.GetAttributesAsync(string queueUrl) { var response = await this.GetQueueAttributesAsync(new GetQueueAttributesRequest { AttributeNames = new List() { "All" }, QueueUrl = queueUrl }).ConfigureAwait(false); return response.Attributes; } Task ICoreAmazonSQS.SetAttributesAsync(string queueUrl, Dictionary attributes) { return this.SetQueueAttributesAsync(new SetQueueAttributesRequest() { QueueUrl = queueUrl, Attributes = attributes }); } /// /// This is a utility method which updates the policy of a queue to allow the /// S3 bucket to publish events to it. /// /// The queue that will have its policy updated. /// The bucket that will be given access to send messages from. /// The ARN for the SQS queue. This can be used when setting up the S3 bucket notification. public async Task AuthorizeS3ToSendMessageAsync(string queueUrl, string bucket) { var getAttributeResponse = await this.GetQueueAttributesAsync(new GetQueueAttributesRequest { QueueUrl = queueUrl, AttributeNames = new List { "All" } }).ConfigureAwait(false); Policy policy; Statement statement; GetNewPolicyAndStatement(getAttributeResponse, bucket, out policy, out statement); if (!policy.CheckIfStatementExists(statement)) { policy.Statements.Add(statement); var policyString = policy.ToJson(); await this.SetQueueAttributesAsync(new SetQueueAttributesRequest { QueueUrl = queueUrl, Attributes = new Dictionary { {"Policy", policyString} } }).ConfigureAwait(false); } return getAttributeResponse.QueueARN; } } }