Java Code Examples for com.amazonaws.services.secretsmanager.model.GetSecretValueRequest#setSecretId()

The following examples show how to use com.amazonaws.services.secretsmanager.model.GetSecretValueRequest#setSecretId() . 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: SecretsManagerTest.java    From fernet-java8 with Apache License 2.0 6 votes vote down vote up
@Test
public final void verifyGetSecretVersionRetrievesBinary() throws UnsupportedEncodingException {
    // given
    final GetSecretValueRequest request = new GetSecretValueRequest();
    request.setSecretId("secret");
    request.setVersionId("version");
    final GetSecretValueResult response = new GetSecretValueResult();
    response.setSecretBinary(ByteBuffer.wrap("expected".getBytes("UTF-8")));
    given(delegate.getSecretValue(eq(request))).willReturn(response);

    // when
    final ByteBuffer result = manager.getSecretVersion("secret", "version");

    // then
    final byte[] buffer = new byte[result.remaining()];
    result.get(buffer);
    assertEquals("expected", new String(buffer, "UTF-8"));
}
 
Example 2
Source File: SecretsManagerTest.java    From fernet-java8 with Apache License 2.0 6 votes vote down vote up
@Test
public final void verifyGetSecretStageRetrievesBinary() throws UnsupportedEncodingException {
    // given
    final GetSecretValueRequest request = new GetSecretValueRequest();
    request.setSecretId("secret");
    request.setVersionStage("AWSPENDING");
    final GetSecretValueResult response = new GetSecretValueResult();
    response.setSecretBinary(ByteBuffer.wrap("expected".getBytes("UTF-8")));
    given(delegate.getSecretValue(eq(request))).willReturn(response);

    // when
    final ByteBuffer result = manager.getSecretStage("secret", PENDING);

    // then
    final byte[] buffer = new byte[result.remaining()];
    result.get(buffer);
    assertEquals("expected", new String(buffer, "UTF-8"));
}
 
Example 3
Source File: SecretsManager.java    From fernet-java8 with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve a specific version of the secret. This requires the permission <code>secretsmanager:GetSecretValue</code>
 *
 * @param secretId the ARN of the secret
 * @param clientRequestToken the version identifier of the secret
 * @return the Fernet key or keys in binary form
 */
public ByteBuffer getSecretVersion(final String secretId, final String clientRequestToken) {
    final GetSecretValueRequest getSecretValueRequest = new GetSecretValueRequest();
    getSecretValueRequest.setSecretId(secretId);
    getSecretValueRequest.setVersionId(clientRequestToken);
    final GetSecretValueResult result = getDelegate().getSecretValue(getSecretValueRequest);
    return result.getSecretBinary();
}
 
Example 4
Source File: SecretsManager.java    From fernet-java8 with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve a specific stage of the secret.
 *
 * @param secretId the ARN of the secret
 * @param stage the stage of the secret to retrieve
 * @return the Fernet key or keys in binary form
 */
public ByteBuffer getSecretStage(final String secretId, final Stage stage) {
    final GetSecretValueRequest getSecretValueRequest = new GetSecretValueRequest();
    getSecretValueRequest.setSecretId(secretId);
    getSecretValueRequest.setVersionStage(stage.getAwsName());
    final GetSecretValueResult result = getDelegate().getSecretValue(getSecretValueRequest);
    return result.getSecretBinary();
}
 
Example 5
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 6
Source File: SecretsManagerTest.java    From fernet-java8 with Apache License 2.0 5 votes vote down vote up
@Test
public final void verifyAssertDoesNothing() {
    // given
    final GetSecretValueRequest request = new GetSecretValueRequest();
    request.setSecretId("secret");
    request.setVersionStage("AWSCURRENT");
    given(delegate.getSecretValue(eq(request))).willReturn(new GetSecretValueResult());

    // when
    manager.assertCurrentStageExists("secret");

    // then (nothing)
}
 
Example 7
Source File: AwsSecretsManagerPropertySource.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
public void init() {
	GetSecretValueRequest secretValueRequest = new GetSecretValueRequest();
	secretValueRequest.setSecretId(context);
	readSecretValue(secretValueRequest);
}
 
Example 8
Source File: SecretsManager.java    From fernet-java8 with Apache License 2.0 3 votes vote down vote up
/**
 * Ensure that the given secret has an AWSCURRENT value. This requires the permission
 * <code>secretsmanager:GetSecretValue</code>
 *
 * @param secretId
 *            the ARN of the secret.
 * @throws ResourceNotFoundException if the secret doesn't exist or it has no AWSCURRENT stage
 */
public void assertCurrentStageExists(final String secretId) {
    final GetSecretValueRequest getSecretValueRequest = new GetSecretValueRequest();
    getSecretValueRequest.setSecretId(secretId);
    getSecretValueRequest.setVersionStage(CURRENT.getAwsName());
    getDelegate().getSecretValue(getSecretValueRequest);
}