// Method takes in a string and parses it into a DeveloperOptions class. public static DeveloperOptions Parse(string developerOptions) { DeveloperOptions options = new DeveloperOptions(); if (!string.IsNullOrWhiteSpace(developerOptions)) { var optionPairs = developerOptions.Split(new []{'&'}, StringSplitOptions.RemoveEmptyEntries); foreach (var optionPair in optionPairs) { var optionPairParts = optionPair.Split(new[]{'='}, StringSplitOptions.RemoveEmptyEntries); if (optionPairParts.Length == 2) { MapToOption(options, optionPairParts[0].Trim().ToLowerInvariant(), optionPairParts[1].Trim()); } else { throw new ArgumentException( string.Format( "Unable to parse developer options which should be in the form of 'option=value&nextOption=nextValue'. The option '{0}' was not properly constructed", optionPair)); } } } return options; }
// Method takes in a string and parses it into a DeveloperOptions class. public static DeveloperOptions Parse(string developerOptions) { DeveloperOptions options = new DeveloperOptions(); if (!string.IsNullOrWhiteSpace(developerOptions)) { var optionPairs = developerOptions.Split(new [] { '&' }, StringSplitOptions.RemoveEmptyEntries); foreach (var optionPair in optionPairs) { var optionPairParts = optionPair.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries); if (optionPairParts.Length == 2) { MapToOption(options, optionPairParts[0].Trim().ToLowerInvariant(), optionPairParts[1].Trim()); } else { throw new ArgumentException( string.Format( "Unable to parse developer options which should be in the form of 'option=value&nextOption=nextValue'. The option '{0}' was not properly constructed", optionPair)); } } } return(options); }
public override OperationResult Deprovision(AddonDeprovisionRequest request) { string connectionData = request.ConnectionData; // changing to overloaded constructor - 5/22/14 var deprovisionResult = new ProvisionAddOnResult(connectionData); AddonManifest manifest = request.Manifest; string devOptions = request.DeveloperOptions; try { AmazonSimpleNotificationServiceClient client; var conInfo = ConnectionInfo.Parse(connectionData); var developerOptions = DeveloperOptions.Parse(devOptions); var establishClientResult = EstablishClient(manifest, developerOptions, out client); if (!establishClientResult.IsSuccess) { deprovisionResult.EndUserMessage = establishClientResult.EndUserMessage; return(deprovisionResult); } var response = client.DeleteTopic(new DeleteTopicRequest() { TopicArn = conInfo.TopicArn }); if (response.HttpStatusCode != null) { do { // ok, to verify deletion, we need to list all of the topics and search for the one we just deleted. // if it's still there, its probably in queue to be deleted, we'll sleep the thread and give it a minute. // once its gone, we'll return true. // if after an intolerable amount of time the queue is still there, throw an error. var verificationResponse = client.ListTopics(new ListTopicsRequest()); // if there are no topics, ok! if (verificationResponse.Topics.Count == 0) { deprovisionResult.IsSuccess = true; break; } // if there are existing topics, search for the one we just deleted. if (verificationResponse.Topics.Find(m => m.TopicArn.Equals(conInfo.TopicArn)) == null) { deprovisionResult.IsSuccess = true; break; } // otherwise, the topic still exists and we need to wait a little longer. Thread.Sleep(TimeSpan.FromSeconds(10d)); } while (true); } } catch (Exception e) { deprovisionResult.EndUserMessage += "An error occurred during deletion. Your SNS queue may be deleted, but we were unable to verify. Please check your AWS Console."; deprovisionResult.EndUserMessage += e.Message; } return(deprovisionResult); }
private CreateTopicRequest CreateTopicRequest(DeveloperOptions devOptions) { var request = new CreateTopicRequest() { // TODO - need to determine where defaults are used, and then not create the constructor where value is null (to use default) Name = devOptions.TopicName // These are required values. }; return(request); }
private CreatePlatformEndpointRequest CreatePlatformEndpointRequest(DeveloperOptions devOptions) { var request = new CreatePlatformEndpointRequest() { PlatformApplicationArn = devOptions.PlatformApplicationArn, CustomUserData = devOptions.CustomUserData, Token = devOptions.Token, Attributes = devOptions.EndpointAttributes }; return(request); }
private CreatePlatformApplicationRequest CreatePlatformApplicaitonRequest(DeveloperOptions devOptions) { var request = new CreatePlatformApplicationRequest() { // TODO - need to determine where defaults are used, and then not create the constructor where value is null (to use default) Name = devOptions.PlatformApplicationName, Attributes = devOptions.PlatformAttributes, Platform = devOptions.MessagingPlatform // These are required values. }; return(request); }
// Interior method takes in instance of DeveloperOptions (aptly named existingOptions) and maps them to the proper value. In essence, a setter method. private static void MapToOption(DeveloperOptions existingOptions, string key, string value) { if ("accesskey".Equals(key)) { existingOptions.AccessKey = value; return; } if ("secretkey".Equals(key)) { existingOptions.SecretAccessKey = value; return; } if ("topicname".Equals(key)) { existingOptions.TopicName = value; return; } if ("platformapplicationname".Equals(key)) { existingOptions.PlatformApplicationName = value; return; } if ("platformapplicationarn".Equals(key)) { existingOptions.PlatformApplicationArn = value; return; } if ("existingoptions".Equals(key)) { existingOptions.Token = value; return; } if ("customuserdata".Equals(key)) { existingOptions.CustomUserData = value; return; } throw new ArgumentException(string.Format("The developer option '{0}' was not expected and is not understood.", key)); }
private OperationResult EstablishClient(AddonManifest manifest, DeveloperOptions devOptions, out AmazonSimpleNotificationServiceClient client) { OperationResult result; bool requireCreds; var manifestprops = manifest.GetProperties().ToDictionary(x => x.Key, x => x.Value); var AccessKey = manifestprops["AWSClientKey"]; var SecretAccessKey = manifestprops["AWSSecretKey"]; var _RegionEndpoint = manifestprops["AWSRegionEndpoint"]; var prop = manifest.Properties.First( p => p.Key.Equals("requireDevCredentials", StringComparison.InvariantCultureIgnoreCase)); if (bool.TryParse(prop.Value, out requireCreds) && requireCreds) { if (!ValidateDevCreds(devOptions)) { client = null; result = new OperationResult() { IsSuccess = false, EndUserMessage = "The add on requires that developer credentials are specified but none were provided." }; return(result); } //accessKey = devOptions.AccessKey; //secretAccessKey = devOptions.SecretAccessKey; } AmazonSimpleNotificationServiceConfig config = new AmazonSimpleNotificationServiceConfig() { RegionEndpoint = RegionEndpoint.USEast1 }; client = new AmazonSimpleNotificationServiceClient(AccessKey, SecretAccessKey, config); result = new OperationResult { IsSuccess = true }; return(result); }
private OperationResult ParseDevOptions(string developerOptions, out DeveloperOptions devOptions) { devOptions = null; var result = new OperationResult() { IsSuccess = false }; var progress = ""; try { progress += "Parsing developer options...\n"; devOptions = DeveloperOptions.Parse(developerOptions); } catch (ArgumentException e) { result.EndUserMessage = e.Message; return(result); } result.IsSuccess = true; result.EndUserMessage = progress; return(result); }
// TODO: We might be able to extend this. private bool ValidateDevCreds(DeveloperOptions devOptions) { return !(string.IsNullOrWhiteSpace(devOptions.AccessKey) || string.IsNullOrWhiteSpace(devOptions.SecretAccessKey)); }
private OperationResult ParseDevOptions(string developerOptions, out DeveloperOptions devOptions) { devOptions = null; var result = new OperationResult() { IsSuccess = false }; var progress = ""; try { progress += "Parsing developer options...\n"; devOptions = DeveloperOptions.Parse(developerOptions); } catch (ArgumentException e) { result.EndUserMessage = e.Message; return result; } result.IsSuccess = true; result.EndUserMessage = progress; return result; }
private OperationResult EstablishClient(AddonManifest manifest, DeveloperOptions devOptions, out AmazonSimpleNotificationServiceClient client) { OperationResult result; bool requireCreds; var manifestprops = manifest.GetProperties().ToDictionary(x => x.Key, x => x.Value); var AccessKey = manifestprops["AWSClientKey"]; var SecretAccessKey = manifestprops["AWSSecretKey"]; var _RegionEndpoint = manifestprops["AWSRegionEndpoint"]; var prop = manifest.Properties.First( p => p.Key.Equals("requireDevCredentials", StringComparison.InvariantCultureIgnoreCase)); if (bool.TryParse(prop.Value, out requireCreds) && requireCreds) { if (!ValidateDevCreds(devOptions)) { client = null; result = new OperationResult() { IsSuccess = false, EndUserMessage = "The add on requires that developer credentials are specified but none were provided." }; return result; } //accessKey = devOptions.AccessKey; //secretAccessKey = devOptions.SecretAccessKey; } AmazonSimpleNotificationServiceConfig config = new AmazonSimpleNotificationServiceConfig() { RegionEndpoint = RegionEndpoint.USEast1 }; client = new AmazonSimpleNotificationServiceClient(AccessKey, SecretAccessKey, config); result = new OperationResult { IsSuccess = true }; return result; }
private CreateTopicRequest CreateTopicRequest(DeveloperOptions devOptions) { var request = new CreateTopicRequest() { // TODO - need to determine where defaults are used, and then not create the constructor where value is null (to use default) Name = devOptions.TopicName // These are required values. }; return request; }
private CreatePlatformEndpointRequest CreatePlatformEndpointRequest(DeveloperOptions devOptions) { var request = new CreatePlatformEndpointRequest() { PlatformApplicationArn = devOptions.PlatformApplicationArn, CustomUserData = devOptions.CustomUserData, Token = devOptions.Token, Attributes = devOptions.EndpointAttributes }; return request; }
private CreatePlatformApplicationRequest CreatePlatformApplicaitonRequest(DeveloperOptions devOptions) { var request = new CreatePlatformApplicationRequest() { // TODO - need to determine where defaults are used, and then not create the constructor where value is null (to use default) Name = devOptions.PlatformApplicationName, Attributes = devOptions.PlatformAttributes, Platform = devOptions.MessagingPlatform // These are required values. }; return request; }
// Provision SNS Topic // Input: AddonDeprovisionRequest request // Output: ProvisionAddOnResult public override ProvisionAddOnResult Provision(AddonProvisionRequest request) { // i think this is a bug. but I'm going to throw an empty string to it to clear the warning. var provisionResult = new ProvisionAddOnResult(""); AddonManifest manifest = request.Manifest; string developerOptions = request.DeveloperOptions; try { AmazonSimpleNotificationServiceClient client; DeveloperOptions devOptions; var parseOptionsResult = ParseDevOptions(developerOptions, out devOptions); if (!parseOptionsResult.IsSuccess) { provisionResult.EndUserMessage = parseOptionsResult.EndUserMessage; return(provisionResult); } var establishClientResult = EstablishClient(manifest, DeveloperOptions.Parse(developerOptions), out client); if (!establishClientResult.IsSuccess) { provisionResult.EndUserMessage = establishClientResult.EndUserMessage; return(provisionResult); } var response = client.CreateTopic(CreateTopicRequest(devOptions)); do { var verificationResponse = client.GetTopicAttributes(new GetTopicAttributesRequest() { TopicArn = response.TopicArn }); // ok so the attributes works as follows: // attributes[0] - topicarn // attributes[1] - owner // attributes[2] - policy // attributes[3] - displayname // attributes[4] - subscriptionspending // attributes[5] - subscriptionsconfirmed // attributes[6] - subscriptionsdeleted // attributes[7] - deliverypolicy // attributes[8] - effectivedeliverypolicy if (verificationResponse.Attributes["TopicArn"].Equals(response.TopicArn)) { var conInfo = new ConnectionInfo() { TopicArn = verificationResponse.Attributes["TopicArn"], QueueName = verificationResponse.Attributes["DisplayName"] }; provisionResult.IsSuccess = true; provisionResult.ConnectionData = conInfo.ToString(); break; } Thread.Sleep(TimeSpan.FromSeconds(10d)); } while (true); } catch (Exception e) { provisionResult.EndUserMessage = e.Message; } return(provisionResult); }
// Interior method takes in instance of DeveloperOptions (aptly named existingOptions) and maps them to the proper value. In essence, a setter method. private static void MapToOption(DeveloperOptions existingOptions, string key, string value) { if ("accesskey".Equals(key)) { existingOptions.AccessKey = value; return; } if ("secretkey".Equals(key)) { existingOptions.SecretAccessKey = value; return; } if("topicname".Equals(key)) { existingOptions.TopicName = value; return; } if ("platformapplicationname".Equals(key)) { existingOptions.PlatformApplicationName = value; return; } if ("platformapplicationarn".Equals(key)) { existingOptions.PlatformApplicationArn = value; return; } if ("existingoptions".Equals(key)) { existingOptions.Token = value; return; } if ("customuserdata".Equals(key)) { existingOptions.CustomUserData = value; return; } throw new ArgumentException(string.Format("The developer option '{0}' was not expected and is not understood.", key)); }
// TODO: We might be able to extend this. private bool ValidateDevCreds(DeveloperOptions devOptions) { return(!(string.IsNullOrWhiteSpace(devOptions.AccessKey) || string.IsNullOrWhiteSpace(devOptions.SecretAccessKey))); }