コード例 #1
0
        // Deprovision RDS Instance
        // Input: AddonDeprovisionRequest request
        // Output: OperationResult
        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
            {
                AmazonSQSClient 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.DeleteQueue(new DeleteQueueRequest()
                {
                    QueueUrl = conInfo.queueURL
                });

                do
                {
                    var verificationResponse = client.GetQueueUrl(new GetQueueUrlRequest()
                    {
                        QueueName = conInfo.queueName,
                        QueueOwnerAWSAccountId = developerOptions.AccessKey,
                    });
                    // 5/22/14 fixing amazaon aws deprecration
                    if (verificationResponse.QueueUrl == null)
                    {
                        deprovisionResult.IsSuccess = true;
                        break;
                    }
                    Thread.Sleep(TimeSpan.FromSeconds(10d));
                } while (true);
            }

            catch (QueueDoesNotExistException)
            {
                deprovisionResult.IsSuccess = true;
            }
            catch (QueueDeletedRecentlyException)
            {
                deprovisionResult.IsSuccess = true;
            }
            catch (Exception e)
            {
                deprovisionResult.EndUserMessage = e.Message;
            }

            return(deprovisionResult);
        }
コード例 #2
0
        public static void MapToOptionWithCollection(DeveloperOptions existingOptions, string key, string value)
        {
            if (key.Contains("attributes_"))
            {
                // trim the leading attributes and add the key
                existingOptions.Attributes.Add(key.Replace("attributes_", ""), value);
                return;
            }

            throw new ArgumentException(string.Format("The developer option '{0}' was not expected and is not understood.", key));
        }
コード例 #3
0
        public static void MapToOptionWithCollection(DeveloperOptions existingOptions, string key, string value)
        {
            if (key.Contains("attributes_"))
                {
                    // trim the leading attributes and add the key
                    existingOptions.Attributes.Add(key.Replace("attributes_", ""), value);
                    return;
                }

                throw new ArgumentException(string.Format("The developer option '{0}' was not expected and is not understood.", key));
        }
コード例 #4
0
        private CreateQueueRequest CreateQueueRequest(DeveloperOptions devOptions)
        {
            var request = new CreateQueueRequest()
            {
                // TODO - need to determine where defaults are used, and then not create the constructor where value is null (to use default)
                QueueName  = devOptions.QueueName,
                Attributes = devOptions.Attributes,
            };

            return(request);
        }
コード例 #5
0
        // 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;
            }

            throw new ArgumentException(string.Format("The developer option '{0}' was not expected and is not understood.", key));
        }
コード例 #6
0
        // 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;
            }



            throw new ArgumentException(string.Format("The developer option '{0}' was not expected and is not understood.", key));
        }
コード例 #7
0
        private OperationResult EstablishClient(AddonManifest manifest, DeveloperOptions devOptions, out AmazonSQSClient 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);
                }
            }
            AmazonSQSConfig config = new AmazonSQSConfig()
            {
                RegionEndpoint = RegionEndpoint.USEast1
            };

            client = new AmazonSQSClient(AccessKey, SecretAccessKey, config);
            result = new OperationResult {
                IsSuccess = true
            };
            return(result);
        }
コード例 #8
0
        // 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))
            {
                // splitting all entries into arrays of optionPairs
                var optionPairs = developerOptions.Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var optionPair in optionPairs)
                {
                    // splitting all optionPairs into arrays of key/value denominations
                    var optionPairParts = optionPair.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                    if (optionPairParts.Length == 2)
                    {
                        // check for attributes_
                        if (optionPairParts[0].Trim().ToLowerInvariant().Contains("attributes_"))
                        {
                            MapToOptionWithCollection(options, optionPairParts[0].Trim().ToLowerInvariant(), optionPairParts[1].Trim());
                        }
                        else
                        {
                            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);
        }
コード例 #9
0
        // 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))
            {
                // splitting all entries into arrays of optionPairs
                var optionPairs = developerOptions.Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var optionPair in optionPairs)
                {
                    // splitting all optionPairs into arrays of key/value denominations
                    var optionPairParts = optionPair.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                    if (optionPairParts.Length == 2)
                    {
                        // check for attributes_
                        if (optionPairParts[0].Trim().ToLowerInvariant().Contains("attributes_"))
                        {
                            MapToOptionWithCollection(options, optionPairParts[0].Trim().ToLowerInvariant(), optionPairParts[1].Trim());
                        }
                        else
                        {
                            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;
        }
コード例 #10
0
        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);
        }
コード例 #11
0
 // TODO: We might be able to extend this.
 private bool ValidateDevCreds(DeveloperOptions devOptions)
 {
     return !(string.IsNullOrWhiteSpace(devOptions.AccessKey) || string.IsNullOrWhiteSpace(devOptions.SecretAccessKey));
 }
コード例 #12
0
        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;
        }
コード例 #13
0
        private OperationResult EstablishClient(AddonManifest manifest, DeveloperOptions devOptions, out AmazonSQSClient 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;
                }
            }
            AmazonSQSConfig config = new AmazonSQSConfig() { RegionEndpoint = RegionEndpoint.USEast1 };
            client = new AmazonSQSClient(AccessKey, SecretAccessKey, config);
            result = new OperationResult { IsSuccess = true };
            return result;
        }
コード例 #14
0
 private CreateQueueRequest CreateQueueRequest(DeveloperOptions devOptions)
 {
     var request = new CreateQueueRequest()
     {
         // TODO - need to determine where defaults are used, and then not create the constructor where value is null (to use default)
        QueueName = devOptions.QueueName,
        Attributes = devOptions.Attributes,
     };
     return request;
 }
コード例 #15
0
        // Provision RDS Instance
        // 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
            {
                AmazonSQSClient  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.CreateQueue(CreateQueueRequest(devOptions));
                // fix 5/22/14 resolves amazon aws deprecation
                if (response.QueueUrl != null)
                {
                    //var conInfo = new ConnectionInfo()
                    //{
                    //    DbInstanceIdentifier = devOptions.DbInstanceIndentifier
                    //};
                    //provisionResult.IsSuccess = true;
                    //provisionResult.ConnectionData = conInfo.ToString();
                    //Thread.Sleep(TimeSpan.FromMinutes(6));

                    do
                    {
                        var verificationResponse = client.GetQueueAttributes(new GetQueueAttributesRequest()
                        {
                            QueueUrl = response.QueueUrl
                        });
                        // fix on next few lines 5/22/14 resolve amazon aws deprecation.
                        if (verificationResponse.Attributes != null)
                        {
                            var conInfo = new ConnectionInfo()
                            {
                                queueName = devOptions.QueueName,
                                queueURL  = response.QueueUrl
                            };
                            provisionResult.IsSuccess      = true;
                            provisionResult.ConnectionData = conInfo.ToString();
                            break;
                        }
                        Thread.Sleep(TimeSpan.FromSeconds(10d));
                    } while (true);
                }
            }
            catch (Exception e)
            {
                provisionResult.EndUserMessage = e.Message;
            }

            return(provisionResult);
        }
コード例 #16
0
 // TODO: We might be able to extend this.
 private bool ValidateDevCreds(DeveloperOptions devOptions)
 {
     return(!(string.IsNullOrWhiteSpace(devOptions.AccessKey) || string.IsNullOrWhiteSpace(devOptions.SecretAccessKey)));
 }