use of io.datarouter.secret.client.Secret in project datarouter by hotpads.
the class SecretOpAdapterChainUnitTests method testMultiItemChain.
@Test
public void testMultiItemChain() {
var nsSpy = spy(new SecretNamespacingAdapter(namespacer, manualConfig, NamespacingMode.REMOVING));
var deserializeSpy = spy(new DeserializingAdapter<>(jsonSerializer, String.class, manualConfig));
var extractSpy = spy(new SecretValueExtractingAdapter<String>());
SecretOpAdapterChain<Secret, String> chain = new SecretOpAdapterChain<>(nsSpy).chain(deserializeSpy).chain(extractSpy);
Secret secret = new Secret("manual/name", "value");
String result = chain.adapt(secret);
Assert.assertEquals(result, "value");
InOrder inOrder = inOrder(nsSpy, deserializeSpy, extractSpy);
inOrder.verify(nsSpy, times(1)).adapt(secret);
// Secret does not define equals, so I can't check the exact input
inOrder.verify(deserializeSpy, times(1)).adapt(Mockito.argThat(input -> {
return input.getName().equals("name") && input.getValue().equals("value");
}));
inOrder.verify(extractSpy, times(1)).adapt(Mockito.argThat(input -> {
return input.getName().equals("name") && input.getValue().equals("value");
}));
inOrder.verifyNoMoreInteractions();
}
use of io.datarouter.secret.client.Secret in project datarouter by hotpads.
the class AwsSecretClient method read.
@Override
public final Secret read(String name) {
var request = new GetSecretValueRequest().withSecretId(name);
// .withVersionStage("")// related to AWS rotation
try {
GetSecretValueResult result;
try (var $ = TracerTool.startSpan("AWSSecretsManager getSecretValue", TraceSpanGroupType.CLOUD_STORAGE)) {
TracerTool.appendToSpanInfo(name);
result = client.getSecretValue(request);
}
return new Secret(name, result.getSecretString());
} catch (ResourceNotFoundException e) {
throw new SecretNotFoundException(name, e);
}
}
use of io.datarouter.secret.client.Secret in project datarouter by hotpads.
the class SecretOpAdapterChainUnitTests method testSingleItemChain.
@Test
public void testSingleItemChain() {
SecretValueExtractingAdapter<String> spy = spy(new SecretValueExtractingAdapter<>());
SecretOpAdapter<TypedSecret<String>, String> chain = new SecretOpAdapterChain<>(spy);
Secret secret = new Secret("name", "value");
String result = chain.adapt(secret);
Assert.assertEquals(result, "value");
verify(spy, times(1)).adapt(secret);
verifyNoMoreInteractions(spy);
}
Aggregations