/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { GetParametersByPathResponse response = new GetParametersByPathResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("NextToken", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.NextToken = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("Parameters", targetDepth)) { var unmarshaller = new ListUnmarshaller <Parameter, ParameterUnmarshaller>(ParameterUnmarshaller.Instance); response.Parameters = unmarshaller.Unmarshall(context); continue; } } return(response); }
public static GetParametersByPathResponse Unmarshall(UnmarshallerContext context) { GetParametersByPathResponse getParametersByPathResponse = new GetParametersByPathResponse(); getParametersByPathResponse.HttpResponse = context.HttpResponse; getParametersByPathResponse.RequestId = context.StringValue("GetParametersByPath.RequestId"); getParametersByPathResponse.NextToken = context.StringValue("GetParametersByPath.NextToken"); getParametersByPathResponse.MaxResults = context.IntegerValue("GetParametersByPath.MaxResults"); getParametersByPathResponse.TotalCount = context.IntegerValue("GetParametersByPath.TotalCount"); List <GetParametersByPathResponse.GetParametersByPath_Parameter> getParametersByPathResponse_parameters = new List <GetParametersByPathResponse.GetParametersByPath_Parameter>(); for (int i = 0; i < context.Length("GetParametersByPath.Parameters.Length"); i++) { GetParametersByPathResponse.GetParametersByPath_Parameter parameter = new GetParametersByPathResponse.GetParametersByPath_Parameter(); parameter.Id = context.StringValue("GetParametersByPath.Parameters[" + i + "].Id"); parameter.Name = context.StringValue("GetParametersByPath.Parameters[" + i + "].Name"); parameter.CreatedDate = context.StringValue("GetParametersByPath.Parameters[" + i + "].CreatedDate"); parameter.CreatedBy = context.StringValue("GetParametersByPath.Parameters[" + i + "].CreatedBy"); parameter.UpdatedDate = context.StringValue("GetParametersByPath.Parameters[" + i + "].UpdatedDate"); parameter.UpdatedBy = context.StringValue("GetParametersByPath.Parameters[" + i + "].UpdatedBy"); parameter.Description = context.StringValue("GetParametersByPath.Parameters[" + i + "].Description"); parameter.ShareType = context.StringValue("GetParametersByPath.Parameters[" + i + "].ShareType"); parameter.ParameterVersion = context.IntegerValue("GetParametersByPath.Parameters[" + i + "].ParameterVersion"); parameter.Type = context.StringValue("GetParametersByPath.Parameters[" + i + "].Type"); parameter._Value = context.StringValue("GetParametersByPath.Parameters[" + i + "].Value"); parameter.Constraints = context.StringValue("GetParametersByPath.Parameters[" + i + "].Constraints"); getParametersByPathResponse_parameters.Add(parameter); } getParametersByPathResponse.Parameters = getParametersByPathResponse_parameters; return(getParametersByPathResponse); }
public async void TestRetrieveDictionarySsmUnencrypted() { StaticTestingMethods.IoCEnableMocking(); var testObj = new StorageValueRetriever(); var expectedName = "expectedName"; var expectedResponseValue = "expectedResponseValue"; var expectedResponse = new Dictionary <string, string> () { { expectedName, expectedResponseValue } }; var response = new GetParametersByPathResponse() { Parameters = new List <Parameter> () { new Parameter() { Name = expectedName, Value = expectedResponseValue } } }; var keyPair = new KeyValuePair <ValueStorageType, string> (ValueStorageType.SystemManagerParameterStoreUnencrypted, "ssm/key/string"); testObj.StoreManager.GetParametersByPathAsync(Arg.Any <GetParametersByPathRequest> ()).Returns(response); var actual = await testObj.GetValuesAsync(keyPair.Key, keyPair.Value);; Assert.Equal(expectedResponse, actual); await testObj.StoreManager.Received().GetParametersByPathAsync(Arg.Is <GetParametersByPathRequest> (x => x.WithDecryption == false)); }
public void ShouldOverrideExistingKeyWhenReload() { var client = Substitute.For <IAmazonSimpleSystemsManagement>(); var parameter = new Parameter { Name = "parameter1", Type = ParameterType.String, Value = "value1" }; var response = new GetParametersByPathResponse { HttpStatusCode = System.Net.HttpStatusCode.OK, NextToken = "nexttoken", Parameters = new List <Parameter> { parameter } }; client.GetParametersByPathAsync(Arg.Is <GetParametersByPathRequest>(x => x.NextToken == null)).Returns(response); var provider = new AwsParameterStoreConfigurationProvider(client, ValidPath, new StartsWithFilteredParameterManager()); provider.Load(); provider.ShouldHaveKeyWithValue("parameter1", "value1"); parameter.Value = "value2"; provider.Load(); provider.ShouldHaveKeyWithValue("parameter1", "value2"); }
private async Task <IReadOnlyCollection <XElement> > GetAllElementsAsync() { var request = new GetParametersByPathRequest { Path = _parameterNamePrefix, WithDecryption = true }; GetParametersByPathResponse response = null; var results = new List <XElement>(); do { request.NextToken = response?.NextToken; try { response = await _ssmClient.GetParametersByPathAsync(request); } catch (Exception e) { _logger.LogError($"Error calling SSM to get parameters starting with {_parameterNamePrefix}: {e.Message}"); throw; } foreach (var parameter in response.Parameters) { try { var xml = XElement.Parse(parameter.Value); results.Add(xml); } catch (Exception e) { _logger.LogError($"Error parsing key {parameter.Name}, key will be skipped: {e.Message}"); } } } while(!string.IsNullOrEmpty(response.NextToken)); _logger.LogInformation($"Loaded {results.Count} DataProtection keys"); return(results); }
public void GetKeys() { var prefix = "/" + BasePrefix + "/"; _mockSSM.Setup(client => client.GetParametersByPathAsync(It.IsAny <GetParametersByPathRequest>(), It.IsAny <CancellationToken>())) .Callback <GetParametersByPathRequest, CancellationToken>((request, token) => { Assert.NotNull(request.Path); Assert.Equal(prefix, request.Path); Assert.True(request.WithDecryption); }) .Returns((GetParametersByPathRequest r, CancellationToken token) => { var response = new GetParametersByPathResponse(); response.Parameters.Add(new Parameter { Name = prefix + "foo", Type = ParameterType.SecureString, Value = "<key id=\"foo\"></key>" }); response.Parameters.Add(new Parameter { Name = prefix + "bar", Type = ParameterType.SecureString, Value = "<key id=\"bar\"></key>" }); return(Task.FromResult(response)); }); var repository = new SSMXmlRepository(_mockSSM.Object, prefix, null, null); var elements = repository.GetAllElements(); Assert.Equal(2, elements.Count); foreach (var key in elements) { Assert.NotNull(key); } }
private async Task FillPhoneNumberOptionsAsync() { GetParametersByPathRequest request = new GetParametersByPathRequest { Path = PhoneNumberOptionsParameterPath, WithDecryption = true, }; GetParametersByPathResponse response = await _ssm.GetParametersByPathAsync(request); PhoneNumberOptions.Clear(); IEnumerable <Parameter> sortedParameters = (from p in response.Parameters orderby p.Name select p); foreach (Parameter parameter in sortedParameters) { PhoneNumberOptions.Add(new SelectListItem { Text = parameter.Name.Substring(parameter.Name.LastIndexOf('/') + 1), Value = parameter.Value, }); } }
private async Task <GetParametersByPathResponse> GetParametersByPath(GetParametersByPathRequest request) { ++NumTimesGetParamsByPathCalled; var primaryResponse = new GetParametersByPathResponse { NextToken = "some-token", Parameters = new List <Parameter> { new Parameter { Name = "/app/someapp/dev/thing/testing/name1", Value = "value1" } } }; var secondaryResponse = new GetParametersByPathResponse { NextToken = null, Parameters = new List <Parameter> { new Parameter { Name = "/app/someapp/dev/thing/testing/name2", Value = "value2" } } }; var response = primaryResponse; if (NumTimesGetParamsByPathCalled > 1) { response = secondaryResponse; } return(await Task.FromResult(response)); }
private IAmazonSimpleSystemsManagement CreateMockSSMClient(string kmsKeyId) { var mockSSM = new Mock <IAmazonSimpleSystemsManagement>(); var parameters = new List <Parameter>(); mockSSM.Setup(client => client.PutParameterAsync(It.IsAny <PutParameterRequest>(), It.IsAny <CancellationToken>())) .Callback <PutParameterRequest, CancellationToken>((request, token) => { if (!string.IsNullOrEmpty(kmsKeyId)) { Assert.Equal(kmsKeyId, request.KeyId); } parameters.Add(new Parameter { Name = request.Name, Value = request.Value, Type = request.Type }); }) .Returns((PutParameterRequest r, CancellationToken token) => { return(Task.FromResult(new PutParameterResponse())); }); mockSSM.Setup(client => client.GetParametersByPathAsync(It.IsAny <GetParametersByPathRequest>(), It.IsAny <CancellationToken>())) .Returns((GetParametersByPathRequest r, CancellationToken t) => { var response = new GetParametersByPathResponse { Parameters = parameters }; return(Task.FromResult(response)); }); return(mockSSM.Object); }
public void EnsureValidKeysComebackEvenWhenOneIsInvalid() { var prefix = "/" + BasePrefix + "/"; _mockSSM.Setup(client => client.GetParametersByPathAsync(It.IsAny <GetParametersByPathRequest>(), It.IsAny <CancellationToken>())) .Callback <GetParametersByPathRequest, CancellationToken>((request, token) => { Assert.NotNull(request.Path); Assert.Equal(prefix, request.Path); Assert.True(request.WithDecryption); }) .Returns((GetParametersByPathRequest r, CancellationToken token) => { var response = new GetParametersByPathResponse(); response.Parameters.Add(new Parameter { Name = prefix + "foo", Type = ParameterType.SecureString, Value = "<key id=\"foo\"></key>" }); response.Parameters.Add(new Parameter { Name = prefix + "bar", Type = ParameterType.SecureString, Value = "<key id=\"bar\"></missing-endtag>" }); return(Task.FromResult(response)); }); var repository = new SSMXmlRepository(_mockSSM.Object, prefix, null, null); var elements = repository.GetAllElements(); Assert.Equal(1, elements.Count); Assert.NotNull(elements.FirstOrDefault(x => string.Equals(x.Attribute("id").Value, "foo"))); }