![]() Please feel free to write comments in case of any more explanation needed. The attached source code will give all the details about how it is built. (Convert.FromBase64String(reader.ReadToEnd())) StreamReader reader = new StreamReader(memoryStream) Deal with the exception here, and/or rethrow at your discretion throw Secrets Manager can't decrypt the protected secret text using the provided KMS key. Response = client.GetSecretValueAsync(request).Result The below code will extract the data from memory stream and give us the plain string which we can convert in the Json format. The AccessKeyID and SecretKey will give you the details of the Response. This will help to get value from the SecretManagerClient. The AmazonSecretsManagerConfig will get the endpoint information. This code block will build the client get the response back. " AWSCURRENT" : secretsDetail.VersionStage // VersionStage defaults to AWSCURRENT if unspecified. Request.VersionStage = secretsDetail.VersionStage = null ? GetSecretValueRequest request = new GetSecretValueRequest() (secretsDetail.AccessKeyID, secretsDetail.SecretKey, amazonSecretsManagerConfig) IAmazonSecretsManager client = new AmazonSecretsManagerClient MemoryStream memoryStream = new MemoryStream() ĪmazonSecretsManagerConfig amazonSecretsManagerConfig = new AmazonSecretsManagerConfig() ĪmazonSecretsManagerConfig.ServiceURL = secretsDetail.ServiceURL Get the Secret name string secretName = secretsDetail.SecretName But outside the Amazon's Network, you need all the details which we are using below: You can just pass the secretName and access id and secretKey. If you are in the network or working on EC2 instance, then you don't need to provide the config. The AmazonSecretManagerClient will take parameters like AccessID SecretKey and config. In the below code block, we are using AmazaonSecretsManagerConfig to build the endpoint info for the Secrets Manager. When we have all the details for AWS communication, we are good to build objects. Once our model is ready, we can use that model in the controller where it will pass to the GetSecretManager class. Public string Region // the path of the endpoint / This is a class which will give us all the information for extracting the data In order to do that, let's create a Model where it can be used to do that. As we are creating this as an API, you can send the details and the secrets.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |