Search in sources :

Example 1 with Secret

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();
}
Also used : Secret(io.datarouter.secret.client.Secret) InOrder(org.mockito.InOrder) SecretOpConfig(io.datarouter.secret.op.SecretOpConfig) Mockito.times(org.mockito.Mockito.times) Test(org.testng.annotations.Test) Mockito.spy(org.mockito.Mockito.spy) SecretJsonSerializer(io.datarouter.secret.service.SecretJsonSerializer) Mockito.verify(org.mockito.Mockito.verify) SecretOpReason(io.datarouter.secret.op.SecretOpReason) Secret(io.datarouter.secret.client.Secret) SecretNamespacingAdapter(io.datarouter.secret.op.adapter.NamespacingAdapter.SecretNamespacingAdapter) Mockito(org.mockito.Mockito) Assert(org.testng.Assert) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Mockito.inOrder(org.mockito.Mockito.inOrder) SecretNamespacer(io.datarouter.secret.service.SecretNamespacer) NamespacingMode(io.datarouter.secret.op.adapter.NamespacingAdapter.NamespacingMode) InOrder(org.mockito.InOrder) SecretNamespacingAdapter(io.datarouter.secret.op.adapter.NamespacingAdapter.SecretNamespacingAdapter) Test(org.testng.annotations.Test)

Example 2 with Secret

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);
    }
}
Also used : Secret(io.datarouter.secret.client.Secret) GetSecretValueResult(com.amazonaws.services.secretsmanager.model.GetSecretValueResult) GetSecretValueRequest(com.amazonaws.services.secretsmanager.model.GetSecretValueRequest) ResourceNotFoundException(com.amazonaws.services.secretsmanager.model.ResourceNotFoundException) SecretNotFoundException(io.datarouter.secret.exception.SecretNotFoundException)

Example 3 with Secret

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);
}
Also used : Secret(io.datarouter.secret.client.Secret) Test(org.testng.annotations.Test)

Aggregations

Secret (io.datarouter.secret.client.Secret)3 Test (org.testng.annotations.Test)2 GetSecretValueRequest (com.amazonaws.services.secretsmanager.model.GetSecretValueRequest)1 GetSecretValueResult (com.amazonaws.services.secretsmanager.model.GetSecretValueResult)1 ResourceNotFoundException (com.amazonaws.services.secretsmanager.model.ResourceNotFoundException)1 SecretNotFoundException (io.datarouter.secret.exception.SecretNotFoundException)1 SecretOpConfig (io.datarouter.secret.op.SecretOpConfig)1 SecretOpReason (io.datarouter.secret.op.SecretOpReason)1 NamespacingMode (io.datarouter.secret.op.adapter.NamespacingAdapter.NamespacingMode)1 SecretNamespacingAdapter (io.datarouter.secret.op.adapter.NamespacingAdapter.SecretNamespacingAdapter)1 SecretJsonSerializer (io.datarouter.secret.service.SecretJsonSerializer)1 SecretNamespacer (io.datarouter.secret.service.SecretNamespacer)1 InOrder (org.mockito.InOrder)1 Mockito (org.mockito.Mockito)1 Mockito.inOrder (org.mockito.Mockito.inOrder)1 Mockito.spy (org.mockito.Mockito.spy)1 Mockito.times (org.mockito.Mockito.times)1 Mockito.verify (org.mockito.Mockito.verify)1 Mockito.verifyNoMoreInteractions (org.mockito.Mockito.verifyNoMoreInteractions)1 Assert (org.testng.Assert)1