/// <inheritdoc/> public SetTopicAttributesResponse SetAttributes(SetTopicAttributesRequest request) { return(AggregateExceptionExtract.Extract(() => { return SetAttributesAsync(request).Result; })); }
internal SetTopicAttributesResponse SetTopicAttributes(SetTopicAttributesRequest request) { var marshaller = new SetTopicAttributesRequestMarshaller(); var unmarshaller = SetTopicAttributesResponseUnmarshaller.Instance; return(Invoke <SetTopicAttributesRequest, SetTopicAttributesResponse>(request, marshaller, unmarshaller)); }
/// <summary> /// Initiates the asynchronous execution of the SetTopicAttributes operation. /// <seealso cref="Amazon.SimpleNotificationService.IAmazonSimpleNotificationService"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the SetTopicAttributes operation.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns>The task object representing the asynchronous operation.</returns> public Task <SetTopicAttributesResponse> SetTopicAttributesAsync(SetTopicAttributesRequest request, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new SetTopicAttributesRequestMarshaller(); var unmarshaller = SetTopicAttributesResponseUnmarshaller.Instance; return(Invoke <IRequest, SetTopicAttributesRequest, SetTopicAttributesResponse>(request, marshaller, unmarshaller, signer, cancellationToken)); }
private async Task EnsureServerSideEncryptionIsUpdatedAsync(ServerSideEncryption config) { if (ServerSideEncryptionNeedsUpdating(config)) { var request = new SetTopicAttributesRequest { TopicArn = Arn, AttributeName = JustSayingConstants.AttributeEncryptionKeyId, AttributeValue = config?.KmsMasterKeyId ?? string.Empty }; var response = await Client.SetTopicAttributesAsync(request).ConfigureAwait(false); if (response.HttpStatusCode == HttpStatusCode.OK) { ServerSideEncryption = string.IsNullOrEmpty(config?.KmsMasterKeyId) ? null : config; } else { _log.LogWarning( "Request to set topic attribute '{TopicAttributeName}' to '{TopicAttributeValue}' failed with status code '{HttpStatusCode}'.", request.AttributeName, request.AttributeValue, response.HttpStatusCode); } } }
public async Task <SetTopicAttributesResponse> SetAttributesAsync(TopicAttributes attributes) { var request = new SetTopicAttributesRequest { Attributes = attributes }; return(await SetAttributesAsync(request).ConfigureAwait(false)); }
/// <inheritdoc/> public SetTopicAttributesResponse SetAttributes(TopicAttributes attributes) { var request = new SetTopicAttributesRequest { Attributes = attributes }; return(SetAttributes(request)); }
public async Task <SetTopicAttributesResponse> SetAttributesAsync(SetTopicAttributesRequest request) { request.TopicName = this.TopicName; var marshaller = new SetTopicAttributesRequestMarshaller(); var unmarshaller = SetTopicAttributesResponseUnmarshaller.Instance; return(await _serviceClient.InvokeAsync <SetTopicAttributesRequest, SetTopicAttributesResponse>(request, marshaller, unmarshaller).ConfigureAwait(false)); }
/// <inheritdoc/> public SetTopicAttributesResponse SetAttributes(SetTopicAttributesRequest request) { request.TopicName = this.TopicName; var marshaller = new SetTopicAttributesRequestMarshaller(); var unmarshaller = SetTopicAttributesResponseUnmarshaller.Instance; return(_serviceClient.Invoke <SetTopicAttributesRequest, SetTopicAttributesResponse>(request, marshaller, unmarshaller)); }
/// <inheritdoc/> public IAsyncResult BeginSetAttributes(SetTopicAttributesRequest request, AsyncCallback callback, object state) { request.TopicName = this.TopicName; var marshaller = new SetTopicAttributesRequestMarshaller(); var unmarshaller = SetTopicAttributesResponseUnmarshaller.Instance; return(_serviceClient.BeginInvoke <SetTopicAttributesRequest>(request, marshaller, unmarshaller, callback, state)); }
public void CRUDTopics() { // list all topics var allTopics = GetAllTopics(); var currentTopicCount = allTopics.Count; // create new topic var name = "dotnetsdk" + DateTime.Now.Ticks; var createTopicRequest = new CreateTopicRequest { Name = name }; var createTopicResult = Client.CreateTopic(createTopicRequest); var topicArn = createTopicResult.TopicArn; try { // verify there is a new topic allTopics = GetAllTopics(); Assert.AreNotEqual(currentTopicCount, allTopics.Count); // set topic attribute var setTopicAttributesRequest = new SetTopicAttributesRequest { TopicArn = topicArn, AttributeName = "DisplayName", AttributeValue = "Test topic" }; Client.SetTopicAttributes(setTopicAttributesRequest); // verify topic attributes var getTopicAttributesRequest = new GetTopicAttributesRequest { TopicArn = topicArn }; var topicAttributes = Client.GetTopicAttributes(getTopicAttributesRequest).Attributes; Assert.AreEqual(setTopicAttributesRequest.AttributeValue, topicAttributes[setTopicAttributesRequest.AttributeName]); } finally { // delete new topic var deleteTopicRequest = new DeleteTopicRequest { TopicArn = topicArn }; Client.DeleteTopic(deleteTopicRequest); // verify the topic was deleted allTopics = GetAllTopics(); Assert.AreEqual(currentTopicCount, allTopics.Count); } }
internal SetTopicAttributesResponse SetTopicAttributes(SetTopicAttributesRequest request) { var task = SetTopicAttributesAsync(request); try { return(task.Result); } catch (AggregateException e) { ExceptionDispatchInfo.Capture(e.InnerException).Throw(); return(null); } }
private async Task SaveAsync(string sourceArn, IAmazonSimpleNotificationService client) { ActionIdentifier[] actions = { SNSActionIdentifiers.Subscribe }; var snsPolicy = new Policy() .WithStatements(GetDefaultStatement(sourceArn)) .WithStatements(new Statement(Statement.StatementEffect.Allow) .WithPrincipals(_accountIds.Select(a => new Principal(a)).ToArray()) .WithResources(new Resource(sourceArn)) .WithActionIdentifiers(actions)); var attributeValue = snsPolicy.ToJson(); var setQueueAttributesRequest = new SetTopicAttributesRequest(sourceArn, "Policy", attributeValue); await client.SetTopicAttributesAsync(setQueueAttributesRequest).ConfigureAwait(false); }
internal static async Task SaveAsync(SnsPolicyDetails policyDetails, IAmazonSimpleNotificationService client) { var sourceAccountId = ExtractSourceAccountId(policyDetails.SourceArn); var policyJson = $@"{{ ""Version"" : ""2012-10-17"", ""Statement"" : [ {{ ""Sid"" : ""{Guid.NewGuid().ToString().Replace("-", "")}"", ""Effect"" : ""Allow"", ""Principal"" : {{ ""AWS"" : ""*"" }}, ""Action"" : [ ""sns:GetTopicAttributes"", ""sns:SetTopicAttributes"", ""sns:AddPermission"", ""sns:RemovePermission"", ""sns:DeleteTopic"", ""sns:Subscribe"", ""sns:Publish"" ], ""Resource"" : ""{policyDetails.SourceArn}"", ""Condition"" : {{ ""StringEquals"" : {{ ""AWS:SourceOwner"" : ""{sourceAccountId}"" }} }} }}, {{ ""Sid"" : ""{Guid.NewGuid().ToString().Replace("-", "")}"", ""Effect"" : ""Allow"", ""Principal"" : {{ ""AWS"" : {JsonSerializer.Serialize(policyDetails.AccountIds)} }}, ""Action"" : ""sns:Subscribe"", ""Resource"" : ""{policyDetails.SourceArn}"" }} ] }}"; var setQueueAttributesRequest = new SetTopicAttributesRequest(policyDetails.SourceArn, "Policy", policyJson); await client.SetTopicAttributesAsync(setQueueAttributesRequest).ConfigureAwait(false); }
/** * Convert SetTopicAttributesRequest to name value pairs */ private static IDictionary<string, string> ConvertSetTopicAttributes(SetTopicAttributesRequest request) { IDictionary<string, string> parameters = new Dictionary<string, string>(); parameters["Action"] = "SetTopicAttributes"; if (request.IsSetTopicArn()) { parameters["TopicArn"] = request.TopicArn; } if (request.IsSetAttributeName()) { parameters["AttributeName"] = request.AttributeName; } if (request.IsSetAttributeValue()) { parameters["AttributeValue"] = request.AttributeValue; } return parameters; }
private static IDictionary <string, string> ConvertSetTopicAttributes(SetTopicAttributesRequest request) { IDictionary <string, string> dictionary = new Dictionary <string, string>(); dictionary["Action"] = "SetTopicAttributes"; if (request.IsSetTopicArn()) { dictionary["TopicArn"] = request.TopicArn; } if (request.IsSetAttributeName()) { dictionary["AttributeName"] = request.AttributeName; } if (request.IsSetAttributeValue()) { dictionary["AttributeValue"] = request.AttributeValue; } return(dictionary); }
public async Task CRUDTopics() { // list all topics var allTopics = await GetAllTopics(); // create new topic var name = UtilityMethods.GenerateName("CrudTopics"); var createTopicRequest = new CreateTopicRequest { Name = name }; var createTopicResult = await Client.CreateTopicAsync(createTopicRequest); var topicArn = createTopicResult.TopicArn; _topicArns.Add(topicArn); // verify there is a new topic allTopics = await GetAllTopics(); Assert.True(allTopics.Exists(t => t.TopicArn.Contains(name))); // set topic attribute var setTopicAttributesRequest = new SetTopicAttributesRequest { TopicArn = topicArn, AttributeName = "DisplayName", AttributeValue = "Test topic" }; await Client.SetTopicAttributesAsync(setTopicAttributesRequest); // verify topic attributes var getTopicAttributesRequest = new GetTopicAttributesRequest { TopicArn = topicArn }; var topicAttributes = (await Client.GetTopicAttributesAsync(getTopicAttributesRequest)).Attributes; Assert.Equal(setTopicAttributesRequest.AttributeValue, topicAttributes[setTopicAttributesRequest.AttributeName]); }
public Task <string> CreateTopicAsync(string topicName, IDictionary <string, string>?attributes = null) { if (string.IsNullOrWhiteSpace(topicName)) { throw new ArgumentException($"A non-null/empty '{topicName}' is required.", nameof(topicName)); } return(createTopicAsync()); async Task <string> createTopicAsync() { var response = await _sns.CreateTopicAsync(topicName); if (response.HttpStatusCode != HttpStatusCode.OK) { throw new InvalidOperationException($"Topic creation failed for topic '{topicName}'."); } if (attributes != null && attributes.Any()) { foreach (var attribute in attributes) { var request = new SetTopicAttributesRequest { AttributeName = attribute.Key, AttributeValue = attribute.Value, TopicArn = response.TopicArn }; var setTopicResponse = await _sns.SetTopicAttributesAsync(request); if (setTopicResponse.HttpStatusCode != HttpStatusCode.OK) { throw new InvalidOperationException($"Unable to set attributes for topic '{topicName}'"); } } } return(response.TopicArn); } }
public SetTopicAttributesResponse SetTopicAttributes(SetTopicAttributesRequest request) { throw new System.NotImplementedException(); }
/// <summary> /// Set Topic Attributes /// </summary> /// <param name="request">Set Topic Attributes request</param> /// <returns>Set Topic Attributes Response from the service</returns> /// <remarks> /// The SetTopicAttributes action allows a topic owner to set an attribute of the topic to a new value. /// </remarks> public SetTopicAttributesResponse SetTopicAttributes(SetTopicAttributesRequest request) { return(Invoke <SetTopicAttributesResponse>(ConvertSetTopicAttributes(request))); }
public static void SNSCreateSubscribePublish() { #region SNSCreateSubscribePublish var snsClient = new AmazonSimpleNotificationServiceClient(); var topicRequest = new CreateTopicRequest { Name = "CodingTestResults" }; var topicResponse = snsClient.CreateTopic(topicRequest); var topicAttrRequest = new SetTopicAttributesRequest { TopicArn = topicResponse.TopicArn, AttributeName = "DisplayName", AttributeValue = "Coding Test Results" }; snsClient.SetTopicAttributes(topicAttrRequest); snsClient.Subscribe(new SubscribeRequest { Endpoint = "*****@*****.**", Protocol = "email", TopicArn = topicResponse.TopicArn }); // Wait for up to 2 minutes for the user to confirm the subscription. DateTime latest = DateTime.Now + TimeSpan.FromMinutes(2); while (DateTime.Now < latest) { var subsRequest = new ListSubscriptionsByTopicRequest { TopicArn = topicResponse.TopicArn }; var subs = snsClient.ListSubscriptionsByTopic(subsRequest).Subscriptions; var sub = subs[0]; if (!string.Equals(sub.SubscriptionArn, "PendingConfirmation", StringComparison.Ordinal)) { break; } // Wait 15 seconds before trying again. System.Threading.Thread.Sleep(TimeSpan.FromSeconds(15)); } snsClient.Publish(new PublishRequest { Subject = "Coding Test Results for " + DateTime.Today.ToShortDateString(), Message = "All of today's coding tests passed.", TopicArn = topicResponse.TopicArn }); #endregion }
public void SetTopicAttributesAsync(SetTopicAttributesRequest request, AmazonServiceCallback <SetTopicAttributesRequest, SetTopicAttributesResponse> callback, AsyncOptions options = null) { throw new System.NotImplementedException(); }
public async Task <IActionResult> SNS() { var results = new List <string>(); var topicRequest = new CreateTopicRequest { Name = "borislav-topic-1" }; var topicResponse = await _snsClient.CreateTopicAsync(topicRequest); results.Add($"Topic '{topicRequest.Name}' created with status {topicResponse.HttpStatusCode}"); var topicAttrRequest = new SetTopicAttributesRequest { TopicArn = topicResponse.TopicArn, AttributeName = "DisplayName", AttributeValue = "Coding Test Results" }; await _snsClient.SetTopicAttributesAsync(topicAttrRequest); var subscribeRequest = new SubscribeRequest { Endpoint = "*****@*****.**", Protocol = "email", TopicArn = topicResponse.TopicArn }; SubscribeResponse subscribeResponse = await _snsClient.SubscribeAsync(subscribeRequest); results.Add($"Invitation sent by email with status {subscribeResponse.HttpStatusCode}"); results.Add("Wait for up to 2 min for the user to confirm the subscription"); // Wait for up to 2 minutes for the user to confirm the subscription. DateTime latest = DateTime.Now + TimeSpan.FromMinutes(2); while (DateTime.Now < latest) { var subsRequest = new ListSubscriptionsByTopicRequest { TopicArn = topicResponse.TopicArn }; var subs = _snsClient.ListSubscriptionsByTopicAsync(subsRequest).Result.Subscriptions; if (!string.Equals(subs[0].SubscriptionArn, "PendingConfirmation", StringComparison.Ordinal)) { break; } // Wait 15 seconds before trying again. System.Threading.Thread.Sleep(TimeSpan.FromSeconds(15)); } var publishRequest = new PublishRequest { Subject = "Coding Test Results for " + DateTime.Today.ToShortDateString(), Message = "All of today's coding tests passed", TopicArn = topicResponse.TopicArn }; PublishResponse publishResponse = await _snsClient.PublishAsync(publishRequest); results.Add($"Message '{publishRequest.Message}' published with status {topicResponse.HttpStatusCode}"); ViewBag.Results = new List <string>(); ViewBag.Results.AddRange(results); return(View()); }
public Task <SetTopicAttributesResponse> SetTopicAttributesAsync(SetTopicAttributesRequest request, CancellationToken cancellationToken = default(CancellationToken)) { throw new System.NotImplementedException(); }
public Task <SetTopicAttributesResponse> SetTopicAttributesAsync(SetTopicAttributesRequest request, CancellationToken cancellationToken = new CancellationToken()) { throw new NotImplementedException(); }