public async Task <BillingResponse> Handle(BillingRequest request, CancellationToken cancellationToken) { var stripeChargeRequest = request.MapToStripeRequest(); var client = new AmazonSimpleSystemsManagementClient(); var ssmRequest = new GetParameterRequest { //differentiate between dev and test later Name = "/stripeSecretKey/test", WithDecryption = true }; var ssmResponse = client.GetParameterAsync(ssmRequest).Result; var stripeKey = ssmResponse.Parameter.Value; StripeConfiguration.ApiKey = stripeKey; var stripeParameters = new ChargeCreateOptions { Amount = stripeChargeRequest.Amount, Currency = "usd", Source = stripeChargeRequest.Source, Description = "Scratch Charge", }; var service = new ChargeService(); var response = service.Create(stripeParameters); return(response == null ? new BillingResponse { Status = false } : new BillingResponse { Status = true }); }
static async Task GetConfiguration() { // NOTE: set the region here to match the region used when you created // the parameter var region = Amazon.RegionEndpoint.USEast1; var request = new GetParameterRequest() { Name = "/TestParameterStore/EnvironmentName" }; using (var client = new AmazonSimpleSystemsManagementClient(region)) { try { var response = await client.GetParameterAsync(request); Console.WriteLine($"Parameter {request.Name} has value: {response.Parameter.Value}"); } catch (Exception ex) { Console.Error.WriteLine($"Error occurred: {ex.Message}"); } } }
static async Task <string> GetUserPassword() { string retVal = ""; var region = Amazon.RegionEndpoint.USEast1; var request = new GetParameterRequest() { Name = "MQBrokerUserPassword" }; using (var client = new AmazonSimpleSystemsManagementClient(region)) { try { var response = await client.GetParameterAsync(request); retVal = response.Parameter.Value; } catch (Exception ex) { Console.Error.WriteLine($"Error occurred: {ex.Message}"); } } return(retVal); }
static async Task GetConfiguration() { var awsAccessKeyId = "..."; //ConfigurationManager.AppSettings["AWSAccessKeyId"]; var awsSecretAccessKey = "..."; //ConfigurationManager.AppSettings["AWSSecretAccessKey"]; var region = Amazon.RegionEndpoint.USEast1; AWSCredentials credentials = new BasicAWSCredentials( awsAccessKeyId, awsSecretAccessKey ); var request = new GetParameterRequest() { Name = "/internal/api/access-logs" }; using (var client = new AmazonSimpleSystemsManagementClient(credentials, region)) { try { GetParameterResponse response = await client.GetParameterAsync(request); Console.WriteLine($"Parameter {request.Name} value is: {response.Parameter.Value}"); JObject json = JObject.Parse(response.Parameter.Value); Console.WriteLine(json.GetValue("url").ToString()); Console.WriteLine(json.GetValue("apiId").ToString()); Console.WriteLine(json.GetValue("headerName").ToString()); } catch (Exception ex) { Console.Error.WriteLine($"Error occurred: {ex.Message}"); } } }
public static async Task <string> GetParameterValue(string parameterKey) { var request = new GetParameterRequest() { Name = parameterKey }; var extensionDownloadCount = String.Empty; try { using (var client = new AmazonSimpleSystemsManagementClient()) { var response = await client.GetParameterAsync(request); extensionDownloadCount = response.Parameter.Value; Console.WriteLine($"Parameter {request.Name} value is: {extensionDownloadCount}"); } } catch (Exception ex) { Console.Error.WriteLine($"Error occurred: {ex.Message}"); } return(extensionDownloadCount); }
public async Task <GetParameterResponse> GetParameter(GetParameterRequest getParameterRequest) { using (var client = new AmazonSimpleSystemsManagementClient()) { return(await client.GetParameterAsync(getParameterRequest)); } }
static async Task <string> GetFileValueFromSsmUsingAmazonSdk(string filename) { // NOTE: set the region here to match the region used when you created // the parameter var region = Amazon.RegionEndpoint.USEast1; var request = new GetParameterRequest() { Name = filename, WithDecryption = true }; using (var client = new AmazonSimpleSystemsManagementClient(region)) { try { var response = await client.GetParameterAsync(request); Logger.Info($"Retrieved {filename} from SSM"); return(response.Parameter.Value); } catch (Exception ex) { Logger.Error("Error fetching {0} from SSM: {1}", filename, ex); throw; } } }
public async Task <string> GetParameterValue(string key) { var parametersRequest = new GetParameterRequest { Name = key, WithDecryption = true }; var responseTask = await _simpleSystemsManagement.GetParameterAsync(parametersRequest); return(responseTask.Parameter.Value); }
private async Task <GetParameterResponse> GetParameterResultAsync(string parameterName) { var request = new GetParameterRequest() { Name = parameterName, WithDecryption = true }; return(await Client.GetParameterAsync(request)); }
/// <summary> /// Retrieve PAT/Password from AWS SSM(Simple Systems Manager) /// </summary> /// <param name="passwordParameter"></param> async Task <string> GetSourcePassword(string passwordParameter) { AmazonSimpleSystemsManagementClient ssmClient = new AmazonSimpleSystemsManagementClient(); GetParameterRequest request = new GetParameterRequest(); // TODO: revisit hardcoding parameter names/if these are actually passed into container as ENV variables request.Name = passwordParameter; request.WithDecryption = true; GetParameterResponse parameterResponse = await ssmClient.GetParameterAsync(request); return(parameterResponse.Parameter.Value); }
public async Task <string> Fetch(string key) { using (var client = new AmazonSimpleSystemsManagementClient(RegionEndpoint.EUWest2)) { var request = new GetParameterRequest { Name = key, WithDecryption = true }; var response = await client.GetParameterAsync(request); return(response.Parameter.Value); } }
/// <summary> /// パラメータストアにあるWebhook URLを取得 /// </summary> /// <returns>Webhook URL</returns> private async Task <string> GetWebhookUrl() { var request = new GetParameterRequest() { Name = WEBHOOK_URL, WithDecryption = true }; using var ssmClient = new AmazonSimpleSystemsManagementClient(region); var response = await ssmClient.GetParameterAsync(request); return(response.Parameter.Value); }
public SecureEnvironmentVariable(IAmazonSimpleSystemsManagement ssm, string name) { lazyValue = new AsyncLazy <string>(async() => { var request = new GetParameterRequest { Name = name, WithDecryption = true }; var response = await ssm.GetParameterAsync(request); return(response.Parameter?.Value); }); }
public string GetParamValue(string paramKey) { lock (_ResolveCache) { string paramKeyWithoutPhs = paramKey; foreach (var phName in this.ParameterKeyPlaceholderResolvers.Keys) { string pt = "{" + phName + "}"; if (paramKeyWithoutPhs.Contains(pt)) { string pv = this.ParameterKeyPlaceholderResolvers[phName].Invoke(); paramKeyWithoutPhs = paramKeyWithoutPhs.Replace(pt, pv); } } if (_ResolveCache.ContainsKey(paramKeyWithoutPhs)) { return(_ResolveCache[paramKeyWithoutPhs]); } string pValue = null; using (var client = new AmazonSimpleSystemsManagementClient(this.AwsCredentials, this.AwsRegion)) { var request = new GetParameterRequest() { Name = paramKeyWithoutPhs }; var t = client.GetParameterAsync(request); t.Wait(); if (t.IsCompleted && t.Result is object && t.Result.Parameter is object) { _ResolveCache.Add(paramKeyWithoutPhs, t.Result.Parameter.Value); pValue = t.Result.Parameter.Value; } } if (pValue is object) { lock (_BoundObjects) { foreach (var adapter in _BoundObjects.Values) { adapter.InjectValue(paramKey, pValue); if (!((paramKeyWithoutPhs ?? "") == (paramKey ?? ""))) { adapter.InjectValue(paramKeyWithoutPhs, pValue); } } } } return(pValue); } }
internal string ResolveToValidTopcArn(string topicArnOrParameterKey) { if (topicArnOrParameterKey.StartsWith("arn:")) { return(topicArnOrParameterKey); } if (DateTime.Now >= _ResolveCacheValidUntil) { _ResolveCache = new Dictionary <string, string>(); _ResolveCacheValidUntil = DateTime.Now.AddMinutes(5); } lock (_ResolveCache) { foreach (var phName in this.TopicParameterKeyPlaceholderResolvers.Keys) { string pt = "{" + phName + "}"; if (topicArnOrParameterKey.Contains(pt)) { string pv = this.TopicParameterKeyPlaceholderResolvers[phName].Invoke(); topicArnOrParameterKey = topicArnOrParameterKey.Replace(pt, pv); } } if (_ResolveCache.ContainsKey(topicArnOrParameterKey)) { return(_ResolveCache[topicArnOrParameterKey]); } if (topicArnOrParameterKey.Contains("{")) { throw new Exception($"There is a unresolvable Placeholder within ParameterKey '{topicArnOrParameterKey}'!"); } using (var client = new AmazonSimpleSystemsManagementClient(this.AwsCredentials, this.AwsRegion)) { var request = new GetParameterRequest() { Name = topicArnOrParameterKey }; var t = client.GetParameterAsync(request); t.Wait(); if (t.IsCompleted && t.Result is object && t.Result.Parameter is object) { _ResolveCache.Add(topicArnOrParameterKey, t.Result.Parameter.Value); return(t.Result.Parameter.Value); } } } return(null); }
public async Task <Result <string> > GetConfigAsync() { var getParameterRequest = new GetParameterRequest { Name = $"/{Consts.PARAMETER_STORE_NAME}/settings/electionsConfig", }; var response = await _amazonSettingsClient.GetParameterAsync(getParameterRequest); if (response.HttpStatusCode == HttpStatusCode.OK) { return(Result.Ok(response.Parameter.Value)); } return(Result.Failure <string>("Couldn't update the job timer")); }
public async Task <Result <int> > GetInterval() { var getParameterRequest = new GetParameterRequest { Name = $"/{Consts.PARAMETER_STORE_NAME}/settings/intervalInSeconds", }; var response = await _amazonSettingsClient.GetParameterAsync(getParameterRequest); if (response.HttpStatusCode == HttpStatusCode.OK) { return(Result.Ok(int.Parse(response.Parameter.Value))); } return(Result.Failure <int>("Couldn't retrieve the job timer")); }
public async Task <string> GetKubernetesConfigContent() { using (IAmazonSimpleSystemsManagement client = new AmazonSimpleSystemsManagementClient(_region)) { var name = $"/eks/{_kubernetesClusterName}/default_user"; var request = new GetParameterRequest { Name = name, WithDecryption = true }; var response = await client.GetParameterAsync(request); return(response.Parameter.Value); } }
public string FetchGitHubPersonalAuthToken() { Console.WriteLine("Fetching GitHub personal auth token from Parameter Store"); Console.Write("... "); using (var client = new AmazonSimpleSystemsManagementClient()) { var request = new GetParameterRequest { Name = "/GitHubPersonalTokens/ServerlessTODOList", WithDecryption = true }; var response = client.GetParameterAsync(request).Result; Console.WriteLine("Token found"); return(response.Parameter.Value); } }
private AwsDatabaseConnector() { var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); var parameterName = $"/ConnectionString/{environment}/Mankind"; using (var client = new AmazonSimpleSystemsManagementClient()) { var request = new GetParameterRequest() { Name = parameterName, WithDecryption = true }; using (var response = client.GetParameterAsync(request)) { ConnectionString = response.Result.Parameter.Value; }; } }
public static async Task <string> GetForgeKeysSSM(string SSMkey) { try { AWSCredentials awsCredentials = new InstanceProfileAWSCredentials(); GetParameterRequest parameterRequest = new GetParameterRequest() { Name = SSMkey }; AmazonSimpleSystemsManagementClient client = new AmazonSimpleSystemsManagementClient(awsCredentials, Amazon.RegionEndpoint.GetBySystemName(Environment.GetEnvironmentVariable("AWS_REGION"))); GetParameterResponse response = await client.GetParameterAsync(parameterRequest); return(response.Parameter.Value); } catch (Exception e) { throw new Exception("Cannot obtain Amazon SSM value for " + SSMkey, e); } }
static async Task Main(string[] args) { string _region = "eu-west-1"; using var client = new AmazonSimpleSystemsManagementClient( RegionEndpoint.GetBySystemName(_region)); var request = new GetParameterRequest() { Name = "DD_API_KEY", WithDecryption = true }; GetParameterResponse response = await client.GetParameterAsync(request); Console.WriteLine(RegionEndpoint.GetBySystemName(_region)); Console.WriteLine(response.Parameter.Name); Console.WriteLine(response.Parameter.Value); Console.WriteLine("I am done."); }
public string RecuperarParametro(string chave) { string valor = null; var request = new GetParameterRequest(); request.Name = chave; request.WithDecryption = false; var credentials = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY); using (var client = new AmazonSimpleSystemsManagementClient(credentials, REGION)) { var response = client.GetParameterAsync(request); valor = response.Result.Parameter.Value; } return(valor); }
public async Task <ActionResult> GetIntervalInSeconds() { try { var getParameterRequest = new GetParameterRequest { Name = $"/{Consts.ParameterStoreName}/settings/intervalInSeconds", }; var response = await _amazonSettingsClient.GetParameterAsync(getParameterRequest); if (response.HttpStatusCode == HttpStatusCode.OK) { return(Ok(response.Parameter)); } return(BadRequest("Couldn't retrieve the value")); } catch (Exception e) { throw; } }
private async Task getBucketName() { if (bucketName is null) { Console.WriteLine("Fetching bucket name from parameter store."); // This parameter store stuff is happening here because it is async and // cannot be done in the c'tor. Lambda needs an initialise section? GetParameterRequest ssmRequest = new GetParameterRequest { Name = "thegatehousewereham-s3monitorbucket" }; var ssmResponse = await ssmClient.GetParameterAsync(ssmRequest); bucketName = ssmResponse.Parameter.Value; } else { Console.WriteLine("No need to get bucket name as it isn't null."); } }
private string GetDBConnectionString() { string connectionStr = string.Empty; string keyConnectionStr = "keyConn"; try { if (!this._memoryCache.TryGetValue(keyConnectionStr, out connectionStr)) { //if (string.IsNullOrEmpty(connectionStr)) // connectionStr = @"Data Source=kongsqldb.cugvbjkpc2us.ca-central-1.rds.amazonaws.com;Initial Catalog=awsdb;Integrated Security=false;User ID=wjkong;Password=Wj730615!"; var creds = new InstanceProfileAWSCredentials(); var ssmClient = new AmazonSimpleSystemsManagementClient(creds); var request = new GetParameterRequest() { Name = "/kongsolution/Prod/ConnectionStr", WithDecryption = true }; var response = ssmClient.GetParameterAsync(request).GetAwaiter().GetResult(); if (response.Parameter != null) { connectionStr = response.Parameter.Value; var cacheEntryOptions = new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromDays(7)); this._memoryCache.Set(keyConnectionStr, connectionStr, cacheEntryOptions); } } } catch { } return(connectionStr); }
public async Task <string> WhisperAsync(string secretId) { string result = null; var req = new GetParameterRequest() { Name = secretId, WithDecryption = true }; var response = await _client.GetParameterAsync(req); if (response.Parameter != null) { result = response.Parameter.Value; } else { throw new Exception($"{secretId} does not exist"); } return(result); }
static async Task GetConfiguration() { var region = Amazon.RegionEndpoint.USEast1; var request = new GetParameterRequest() { Name = "/TestParameterStore/EnvironmentName" }; using (var client = new AmazonSimpleSystemsManagementClient(region)) { try { var response = await client.GetParameterAsync(request); Console.WriteLine("Parameter Value: {0}", response.Parameter.Value); } catch (Exception ex) { Console.Error.WriteLine("Error occurred: {0}", ex.Message); } } }
public override string GetValue(string key) { if (_client == null) { return(null); } var request = new GetParameterRequest { Name = $"{BaseParameterPath}/{key}", WithDecryption = true, }; try { var response = _client.GetParameterAsync(request).Result; return(response.Parameter.Value); } catch { return(null); } }
public async override Task <ParameterDto> Handle(GetParameterCommand command, CancellationToken cancellationToken = default) { using var client = _awsClientFactory.Create <AmazonSimpleSystemsManagementClient>(command.AssumeProfile); var request = new GetParameterRequest { Name = command.Name }; ParameterDto result; try { var response = await client.GetParameterAsync(request, cancellationToken); result = _mapper.Map <Amazon.SimpleSystemsManagement.Model.Parameter, ParameterDto>(response.Parameter); } catch (AmazonServiceException e) { throw new AwsFacadeException(e.Message, e); } return(result); }