// 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 ("accountid".Equals(key)) { existingOptions.AccountId = value; return; } if ("vaultname".Equals(key)) { existingOptions.VaultName = value; return; } if("regionendpoint".Equals(key)) { existingOptions.RegionEndpoint = value; } throw new ArgumentException(string.Format("The developer option '{0}' was not expected and is not understood.", key)); }
// 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 ("accountid".Equals(key)) { existingOptions.AccountId = value; return; } if ("vaultname".Equals(key)) { existingOptions.VaultName = value; return; } if ("regionendpoint".Equals(key)) { existingOptions.RegionEndpoint = value; } throw new ArgumentException(string.Format("The developer option '{0}' was not expected and is not understood.", key)); }
// Amazon RDS Options required for // 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; }
private OperationResult ParseDevOptions(string developerOptions, AddonManifest manifest, out DeveloperOptions devOptions) { devOptions = null; var result = new OperationResult() { IsSuccess = false }; var progress = ""; try { progress += "Parsing developer options...\n"; devOptions = DeveloperOptions.Parse(developerOptions); // we're probably going to need these lines a few times Dictionary <string, string> manifestProperties = manifest.GetProperties().ToDictionary(x => x.Key, x => x.Value); devOptions.AccessKey = manifestProperties["AWSClientKey"]; devOptions.SecretAccessKey = manifestProperties["AWSSecretKey"]; devOptions.AccountId = manifestProperties["AWSAccountID"]; //devOptions.RegionEndpoint = manifestProperties["RegionEndpoint"]; } catch (ArgumentException e) { result.EndUserMessage = e.Message; return(result); } result.IsSuccess = true; result.EndUserMessage = progress; return(result); }
// Amazon RDS Options required for // 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); }
// 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 { AmazonGlacierClient 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 getArchivesInVault = client.DescribeVault(new DescribeVaultRequest() { AccountId = conInfo.AccountId, VaultName = conInfo.VaultName }); var response = client.DeleteVault(new DeleteVaultRequest() { AccountId = conInfo.AccountId, VaultName = conInfo.VaultName }); // 5/22/14 fixing amazon aws deprecation if (response.HttpStatusCode != null) { do { var verificationResponse = client.DescribeVault(new DescribeVaultRequest() { }); // 5/22/14 fixing amazaon aws deprecration if (verificationResponse == null) { deprovisionResult.IsSuccess = true; break; } Thread.Sleep(TimeSpan.FromSeconds(10d)); } while (true); } } catch (ResourceNotFoundException) { deprovisionResult.IsSuccess = true; } catch (Exception e) { deprovisionResult.EndUserMessage = e.Message; } return(deprovisionResult); }
// 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 { AmazonGlacierClient client; DeveloperOptions devOptions; var parseOptionsResult = ParseDevOptions(developerOptions, manifest, 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.CreateVault(CreateVaultRequest(devOptions)); // fix 5/22/14 resolves amazon aws deprecation // wait for response to come back with a location while (true) { if (response.Location != null) { var conInfo = new ConnectionInfo() { AccountId = devOptions.AccountId, VaultName = devOptions.VaultName, Location = response.Location }; provisionResult.IsSuccess = true; provisionResult.ConnectionData = conInfo.ToString(); break; } Thread.Sleep(10); } } catch (Exception e) { provisionResult.EndUserMessage = e.Message; } return(provisionResult); }
private CreateVaultRequest CreateVaultRequest(DeveloperOptions devOptions) { var request = new CreateVaultRequest() { // TODO - need to determine where defaults are used, and then not create the constructor where value is null (to use default) // These are required values. AccountId = devOptions.AccountId, VaultName = devOptions.VaultName }; return(request); }
private OperationResult EstablishClient(AddonManifest manifest, DeveloperOptions devOptions, out AmazonGlacierClient client) { OperationResult result; bool requireCreds; //var accessKey = manifest.ProvisioningUsername; //var secretAccessKey = manifest.ProvisioningPassword; var accessKey = devOptions.AccessKey; var secretAccessKey = devOptions.SecretAccessKey; 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; } AmazonGlacierConfig config = new AmazonGlacierConfig() { RegionEndpoint = RegionEndpoint.USEast1 }; client = new AmazonGlacierClient(devOptions.AccessKey, devOptions.SecretAccessKey, config); result = new OperationResult { IsSuccess = true }; 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, AddonManifest manifest, out DeveloperOptions devOptions) { devOptions = null; var result = new OperationResult() { IsSuccess = false }; var progress = ""; try { progress += "Parsing developer options...\n"; devOptions = DeveloperOptions.Parse(developerOptions); // we're probably going to need these lines a few times Dictionary<string, string> manifestProperties = manifest.GetProperties().ToDictionary(x => x.Key, x => x.Value); devOptions.AccessKey = manifestProperties["AWSClientKey"]; devOptions.SecretAccessKey = manifestProperties["AWSSecretKey"]; devOptions.AccountId = manifestProperties["AWSAccountID"]; //devOptions.RegionEndpoint = manifestProperties["RegionEndpoint"]; } 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 AmazonGlacierClient client) { OperationResult result; bool requireCreds; //var accessKey = manifest.ProvisioningUsername; //var secretAccessKey = manifest.ProvisioningPassword; var accessKey = devOptions.AccessKey; var secretAccessKey = devOptions.SecretAccessKey; 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; } AmazonGlacierConfig config = new AmazonGlacierConfig() { RegionEndpoint = RegionEndpoint.USEast1 }; client = new AmazonGlacierClient(devOptions.AccessKey, devOptions.SecretAccessKey, config); result = new OperationResult { IsSuccess = true }; return result; }
private CreateVaultRequest CreateVaultRequest(DeveloperOptions devOptions) { var request = new CreateVaultRequest() { // TODO - need to determine where defaults are used, and then not create the constructor where value is null (to use default) // These are required values. AccountId = devOptions.AccountId, VaultName = devOptions.VaultName }; return request; }
// TODO: We might be able to extend this. private bool ValidateDevCreds(DeveloperOptions devOptions) { return(!(string.IsNullOrWhiteSpace(devOptions.AccessKey) || string.IsNullOrWhiteSpace(devOptions.SecretAccessKey))); }