com.amazonaws.services.secretsmanager.model.ResourceNotFoundException Java Examples

The following examples show how to use com.amazonaws.services.secretsmanager.model.ResourceNotFoundException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestAWSSecretsManagerCredentialStore.java    From datacollector with Apache License 2.0 6 votes vote down vote up
@Test
public void testInitResourceNotFoundException() throws Exception {
  String region = "us-west-2";
  String awsAccessKey = "access-key";
  String awsSecretKey = "secret-key";

  CredentialStore.Context context = Mockito.mock(CredentialStore.Context.class);
  Mockito.when(context.getConfig(AWSSecretsManagerCredentialStore.AWS_REGION_PROP)).thenReturn(region);
  Mockito.when(context.getConfig(AWSSecretsManagerCredentialStore.AWS_ACCESS_KEY_PROP)).thenReturn(awsAccessKey);
  Mockito.when(context.getConfig(AWSSecretsManagerCredentialStore.AWS_SECRET_KEY_PROP)).thenReturn(awsSecretKey);

  SecretCache secretCache = Mockito.mock(SecretCache.class);
  AWSSecretsManagerException exception = new ResourceNotFoundException("message");
  exception.setErrorCode("ResourceNotFoundException");
  AWSSecretsManagerCredentialStore secretManager = createAWSSecretsManagerCredentialStore(secretCache, exception);
  List<CredentialStore.ConfigIssue> issues = secretManager.init(context);
  Assert.assertEquals(0, issues.size());  // ResourceNotFoundException should be ignored at initialization.
}
 
Example #2
Source File: AbstractFernetKeyRotator.java    From fernet-java8 with Apache License 2.0 5 votes vote down vote up
protected void conditionallyCreateSecret(final String secretId, final String clientRequestToken) {
    getSecretsManager().assertCurrentStageExists(secretId);
    try {
        getSecretsManager().getSecretVersion(secretId, clientRequestToken);
        getLogger().warn("createSecret: Successfully retrieved secret for {}. Doing nothing.", secretId);
    } catch (final ResourceNotFoundException rnfe) {
        createSecret(secretId, clientRequestToken);
    }
}
 
Example #3
Source File: SecretsManagerTest.java    From fernet-java8 with Apache License 2.0 5 votes vote down vote up
@Test
public final void verifyAssertCurrentStageExistsThrowsException() {
    // given
    final GetSecretValueRequest request = new GetSecretValueRequest();
    request.setSecretId("secret");
    request.setVersionStage("AWSCURRENT");
    given(delegate.getSecretValue(eq(request))).willThrow(new ResourceNotFoundException("not found"));

    // when
    thrown.expect(ResourceNotFoundException.class);
    manager.assertCurrentStageExists("secret");

    // then (exception thrown)
}
 
Example #4
Source File: SimpleFernetKeyRotatorTest.java    From fernet-java8 with Apache License 2.0 5 votes vote down vote up
@Test
public void verifyHandleRequestCreatesKey() throws IOException {
    // given
    final Context context = mock(Context.class);
    final String clientRequestToken = "clientRequestToken";
    final String secretId = "secretId";

    final DescribeSecretResult secretDescription = new DescribeSecretResult();
    secretDescription.setRotationEnabled(true);
    secretDescription.addVersionIdsToStagesEntry(clientRequestToken, singletonList("AWSPENDING"));
    given(secretsManager.describeSecret(secretId)).willReturn(secretDescription);
    given(secretsManager.getSecretVersion(secretId, clientRequestToken))
            .willThrow(new ResourceNotFoundException("no value yet"));

    final RotationRequest creationRequest = new RotationRequest();
    creationRequest.setClientRequestToken(clientRequestToken);
    creationRequest.setSecretId(secretId);
    creationRequest.setStep(Step.CREATE_SECRET);
    final byte[] creationRequestBytes = mapper.writeValueAsBytes(creationRequest);

    // when
    try (InputStream input = new ByteArrayInputStream(creationRequestBytes)) {
        try (OutputStream output = new ByteArrayOutputStream()) {
            rotator.handleRequest(input, output, context);

            // then
            verify(secretsManager).putSecretValue(eq("secretId"), eq(clientRequestToken), any(Key.class),
                    eq(PENDING));
        }
    }
}
 
Example #5
Source File: AbstractFernetKeyRotatorTest.java    From fernet-java8 with Apache License 2.0 5 votes vote down vote up
@Test
public final void verifyConditionallyCreateCreatesSecret() throws UnsupportedEncodingException {
    // given
    given(secretsManager.getSecretVersion("secret", "version")).willThrow(new ResourceNotFoundException("not found"));

    // when
    rotator.conditionallyCreateSecret("secret", "version");

    // then
    verify(rotator).createSecret("secret", "version");
}
 
Example #6
Source File: TestAWSSecretsManagerCredentialStore.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetCredentialNotFound2() throws Exception {
  SecretCache secretCache = Mockito.mock(SecretCache.class);
  AWSSecretsManagerCredentialStore secretManager = setupNominalAWSSecretsManagerCredentialStore(secretCache);

  String credName = "credName";
  String credKey = "credKey";
  Mockito.when(secretCache.getSecretString(credName)).thenThrow(new ResourceNotFoundException(""));
  try {
    secretManager.get("", credName + "&" + credKey, null);
    Assert.fail("Expected a StageException");
  } catch (StageException e) {
    Assert.assertEquals(Errors.AWS_SECRETS_MANAGER_CRED_STORE_03, e.getErrorCode());
  }
}
 
Example #7
Source File: TestAWSSecretsManagerCredentialStore.java    From datacollector with Apache License 2.0 4 votes vote down vote up
private AWSSecretsManagerCredentialStore createAWSSecretsManagerCredentialStore(SecretCache secretCache) {
  return createAWSSecretsManagerCredentialStore(secretCache, new ResourceNotFoundException(""));
}