Exemplo n.º 1
0
        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 async void TestMultiRetrievalAllHaveValues()
        {
            StaticTestingMethods.IoCEnableMocking();
            var testObj          = new StorageValueRetriever();
            var envName          = "TestEnvName";
            var envValue         = "TestEnvValue";
            var expectedResponse = "expectedReturn";

            Environment.SetEnvironmentVariable(envName, envValue);
            var response = new GetParameterResponse()
            {
                Parameter = new Parameter()
                {
                    Value = expectedResponse
                }
            };

            testObj.StoreManager.GetParameterAsync(Arg.Any <GetParameterRequest> ()).Returns(response);

            var multiKeyPair = new Dictionary <ValueStorageType, string> ()
            {
                { ValueStorageType.SystemManagerParameterStoreUnencrypted, "ssm/key/string" }, { ValueStorageType.EnvironmentVariable, envName }
            };

            var actual = await testObj.GetValueMultiAsync(multiKeyPair);

            Assert.Equal(expectedResponse, actual);
            await testObj.StoreManager.Received().GetParameterAsync(Arg.Is <GetParameterRequest> (x => x.WithDecryption == false));
        }
        public static GetParameterResponse Unmarshall(UnmarshallerContext _ctx)
        {
            GetParameterResponse getParameterResponse = new GetParameterResponse();

            getParameterResponse.HttpResponse = _ctx.HttpResponse;
            getParameterResponse.RequestId    = _ctx.StringValue("GetParameter.RequestId");

            GetParameterResponse.GetParameter_Parameter parameter = new GetParameterResponse.GetParameter_Parameter();
            parameter.Id                   = _ctx.StringValue("GetParameter.Parameter.Id");
            parameter.Name                 = _ctx.StringValue("GetParameter.Parameter.Name");
            parameter.CreatedDate          = _ctx.StringValue("GetParameter.Parameter.CreatedDate");
            parameter.CreatedBy            = _ctx.StringValue("GetParameter.Parameter.CreatedBy");
            parameter.UpdatedDate          = _ctx.StringValue("GetParameter.Parameter.UpdatedDate");
            parameter.UpdatedBy            = _ctx.StringValue("GetParameter.Parameter.UpdatedBy");
            parameter.Description          = _ctx.StringValue("GetParameter.Parameter.Description");
            parameter.ShareType            = _ctx.StringValue("GetParameter.Parameter.ShareType");
            parameter.ParameterVersion     = _ctx.IntegerValue("GetParameter.Parameter.ParameterVersion");
            parameter.Type                 = _ctx.StringValue("GetParameter.Parameter.Type");
            parameter._Value               = _ctx.StringValue("GetParameter.Parameter.Value");
            parameter.Constraints          = _ctx.StringValue("GetParameter.Parameter.Constraints");
            parameter.Tags                 = _ctx.StringValue("GetParameter.Parameter.Tags");
            getParameterResponse.Parameter = parameter;

            return(getParameterResponse);
        }
Exemplo n.º 4
0
        static Entrypoint()
        {
#if DEBUG
            var chain = new CredentialProfileStoreChain();
            if (chain.TryGetAWSCredentials("aws-service-availability", out AWSCredentials profile))
            {
                ddbClient = new AmazonDynamoDBClient(profile);
                cwClient  = new AmazonCloudWatchClient(profile);
                ssmClient = new AmazonSimpleSystemsManagementClient(profile);
                s3Client  = new AmazonS3Client(profile);
            }
            else
            {
                ddbClient = new AmazonDynamoDBClient();
                cwClient  = new AmazonCloudWatchClient();
                ssmClient = new AmazonSimpleSystemsManagementClient();
                s3Client  = new AmazonS3Client();
            }
#else
            ddbClient = new AmazonDynamoDBClient();
            cwClient  = new AmazonCloudWatchClient();
            ssmClient = new AmazonSimpleSystemsManagementClient();
            s3Client  = new AmazonS3Client();
#endif
            ddbContext = new DynamoDBContext(ddbClient);

            GetParameterResponse url = ssmClient.GetParameterAsync(new GetParameterRequest()
            {
                Name = "ServiceHealthDashboardDataUrl"
            }).Result;

            defaultDataUrl = url.Parameter.Value;

            GetParameterResponse tzParam = ssmClient.GetParameterAsync(new GetParameterRequest()
            {
                Name = "TimeZoneMap"
            }).Result;

            timeZoneMap = JsonConvert.DeserializeObject <Dictionary <string, string> >(tzParam.Parameter.Value);

            GetParameterResponse globalServicesParam = ssmClient.GetParameterAsync(new GetParameterRequest()
            {
                Name = "GlobalServicesList"
            }).Result;

            globalServices = globalServicesParam.Parameter.Value.Split(',').ToList();

            GetParameterResponse defaultTzParam = ssmClient.GetParameterAsync(new GetParameterRequest()
            {
                Name = "DefaultTimeZone"
            }).Result;

            defaultTimeZone = defaultTzParam.Parameter.Value;
        }
Exemplo n.º 5
0
        /// <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);
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            GetParameterResponse response = new GetParameterResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("Parameter", targetDepth))
                {
                    var unmarshaller = ParameterUnmarshaller.Instance;
                    response.Parameter = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
        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);
            }
        }
Exemplo n.º 8
0
        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 async void TestRetrieveSingleSsmUnencrypted()
        {
            StaticTestingMethods.IoCEnableMocking();
            var testObj          = new StorageValueRetriever();
            var expectedResponse = "expectedReturn";
            var response         = new GetParameterResponse()
            {
                Parameter = new Parameter()
                {
                    Value = expectedResponse
                }
            };

            var keyPair = new KeyValuePair <ValueStorageType, string> (ValueStorageType.SystemManagerParameterStoreUnencrypted, "ssm/key/string");

            testObj.StoreManager.GetParameterAsync(Arg.Any <GetParameterRequest> ()).Returns(response);

            var actual = await testObj.GetValueAsync(keyPair.Key, keyPair.Value);;

            Assert.Equal(expectedResponse, actual);
            await testObj.StoreManager.Received().GetParameterAsync(Arg.Is <GetParameterRequest> (x => x.WithDecryption == false));
        }