Exemple #1
0
        private async Task StoreElementAsync(XElement element)
        {
            var secretStream = await TryGetSecretAsync();

            XDocument doc = null;

            if (secretStream == null)
            {
                doc = new XDocument(new XElement(RepositoryElementName));
            }
            else
            {
                doc = CreateDocumentFromStream(secretStream);
            }
            doc.Root.Add(element);

            var serializedDoc = new MemoryStream();

            doc.Save(serializedDoc, SaveOptions.DisableFormatting);

            if (secretStream == null)
            {
                await _secretsManager.CreateSecretAsync(new CreateSecretRequest { Name = _key, SecretBinary = serializedDoc });
            }
            else
            {
                await _secretsManager.UpdateSecretAsync(new UpdateSecretRequest { SecretId = _key, SecretBinary = serializedDoc });
            }
        }
Exemple #2
0
        private async Task <string> Set(string key, string value)
        {
            var request = new CreateSecretRequest
            {
                Name         = key,
                SecretString = value
            };

            try
            {
                var createResponse = await _amazonSecretsManager.CreateSecretAsync(request);

                return(createResponse.VersionId);
            }
            catch (ResourceExistsException)
            {
                var updateRequest = new UpdateSecretRequest
                {
                    SecretId     = key,
                    SecretString = value
                };

                var response = await _amazonSecretsManager.UpdateSecretAsync(updateRequest);

                return(response.VersionId);
            }
        }
Exemple #3
0
 private Amazon.SecretsManager.Model.CreateSecretResponse CallAWSServiceOperation(IAmazonSecretsManager client, Amazon.SecretsManager.Model.CreateSecretRequest request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Secrets Manager", "CreateSecret");
     try
     {
         #if DESKTOP
         return(client.CreateSecret(request));
         #elif CORECLR
         return(client.CreateSecretAsync(request).GetAwaiter().GetResult());
         #else
                 #error "Unknown build edition"
         #endif
     }
     catch (AmazonServiceException exc)
     {
         var webException = exc.InnerException as System.Net.WebException;
         if (webException != null)
         {
             throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
         }
         throw;
     }
 }