예제 #1
0
 public void Invoke(CancellationToken cancellationToken)
 {
     if (cancellationToken.IsCancellationRequested)
     {
         return;
     }
     ThreadHelper.JoinableTaskFactory.Run(() =>
     {
         var ssmClient = new Amazon.SimpleSystemsManagement.AmazonSimpleSystemsManagementClient(Amazon.RegionEndpoint.GetBySystemName(Options.Instance.AWSKMSRegion));
         string name, secret, keyalias = "";
         var prompt = new Prompt();
         prompt.promptMessage.Text = "Supply a name for the parameter!";
         prompt.ShowDialog();
         name = prompt.ResponseText;
         if (name is null || name == String.Empty)
         {
             return(System.Threading.Tasks.Task.CompletedTask);
         }
         var list = new Amazon.KeyManagementService.AmazonKeyManagementServiceClient().ListAliases(new ListAliasesRequest()
         {
         }).Aliases.Select(e => new { e.AliasName, e.AliasArn });
         var listchooser = new ListChooser(list.Select(e => e.AliasName).ToList());
         listchooser.ShowDialog();
         keyalias = listchooser.ListElement.SelectedItem as string;
         if (keyalias is null || keyalias == String.Empty)
         {
             return(System.Threading.Tasks.Task.CompletedTask);
         }
         var promptv = new Prompt();
         promptv.promptMessage.Text = "Validate the secret (remove '', etc.)!";
         promptv.ResponseText       = value;
         promptv.ShowDialog();
         secret = promptv.ResponseText;
         if (secret is null || secret == String.Empty)
         {
             return(System.Threading.Tasks.Task.CompletedTask);
         }
         ssmClient.PutParameterAsync(new Amazon.SimpleSystemsManagement.Model.PutParameterRequest()
         {
             KeyId = keyalias,
             Value = secret,
             Type  = "SecureString",
             Name  = name
         }).Wait();
         _span.TextBuffer.Replace(_span.GetSpan(_snapshot), String.Format(replacementTexts[language], name, Options.Instance.AWSSSMRegion));
         return(System.Threading.Tasks.Task.CompletedTask);
     });
 }
예제 #2
0
 public void Invoke(CancellationToken cancellationToken)
 {
     if (cancellationToken.IsCancellationRequested)
     {
         return;
     }
     ThreadHelper.JoinableTaskFactory.Run(() =>
     {
         string secret, keyalias;
         var list = new Amazon.KeyManagementService.AmazonKeyManagementServiceClient().ListAliases(new ListAliasesRequest()
         {
         }).Aliases.Select(e => new { e.AliasName, e.AliasArn });
         var listchooser = new ListChooser(list.Select(e => e.AliasName).ToList());
         listchooser.ShowDialog();
         keyalias = listchooser.ListElement.SelectedItem as string;
         if (keyalias is null || keyalias == String.Empty)
         {
             return(System.Threading.Tasks.Task.CompletedTask);
         }
         var promptv = new Prompt();
         promptv.promptMessage.Text = "Validate the secret (remove '', etc.)!";
         promptv.ResponseText       = value;
         promptv.ShowDialog();
         secret = promptv.ResponseText;
         if (secret is null || secret == String.Empty)
         {
             return(System.Threading.Tasks.Task.CompletedTask);
         }
         var vaultClient = new Amazon.KeyManagementService.AmazonKeyManagementServiceClient(Amazon.RegionEndpoint.GetBySystemName(Options.Instance.AWSKMSRegion));
         var response    = vaultClient.Encrypt(new EncryptRequest()
         {
             KeyId     = keyalias,
             Plaintext = new MemoryStream(Encoding.UTF8.GetBytes(secret))
         });
         _span.TextBuffer.Replace(_span.GetSpan(_snapshot), String.Format(replacementTexts[language], Convert.ToBase64String(response.CiphertextBlob.ToArray()), Options.Instance.AWSKMSRegion));
         return(System.Threading.Tasks.Task.CompletedTask);
     });
 }