Search in sources :

Example 1 with ListSecretVersionsRequest

use of com.google.cloud.secretmanager.v1.ListSecretVersionsRequest in project spring-cloud-config by spring-cloud.

the class GoogleSecretManagerV1AccessStrategy method getSecretVersions.

private List<SecretVersion> getSecretVersions(Secret secret) {
    SecretName parent = SecretName.parse(secret.getName());
    // Create the request.
    ListSecretVersionsRequest listVersionRequest = ListSecretVersionsRequest.newBuilder().setParent(parent.toString()).build();
    // Get all versions.
    SecretManagerServiceClient.ListSecretVersionsPagedResponse pagedListVersionResponse = client.listSecretVersions(listVersionRequest);
    List<SecretVersion> result = new ArrayList<SecretVersion>();
    pagedListVersionResponse.iterateAll().forEach(result::add);
    return result;
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) SecretVersion(com.google.cloud.secretmanager.v1.SecretVersion) ArrayList(java.util.ArrayList) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient) ListSecretVersionsRequest(com.google.cloud.secretmanager.v1.ListSecretVersionsRequest)

Example 2 with ListSecretVersionsRequest

use of com.google.cloud.secretmanager.v1.ListSecretVersionsRequest in project java-secretmanager by googleapis.

the class SecretManagerServiceClientTest method listSecretVersionsTest2.

@Test
public void listSecretVersionsTest2() throws Exception {
    SecretVersion responsesElement = SecretVersion.newBuilder().build();
    ListSecretVersionsResponse expectedResponse = ListSecretVersionsResponse.newBuilder().setNextPageToken("").addAllVersions(Arrays.asList(responsesElement)).build();
    mockSecretManagerService.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListSecretVersionsPagedResponse pagedListResponse = client.listSecretVersions(parent);
    List<SecretVersion> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getVersionsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockSecretManagerService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListSecretVersionsRequest actualRequest = ((ListSecretVersionsRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListSecretVersionsPagedResponse(com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretVersionsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 3 with ListSecretVersionsRequest

use of com.google.cloud.secretmanager.v1.ListSecretVersionsRequest in project java-docs-samples by GoogleCloudPlatform.

the class ListSecretVersionsWithFilter method listSecretVersions.

// List all secret versions for a secret.
public static void listSecretVersions(String projectId, String secretId, String filter) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
        // Build the parent name.
        SecretName secretName = SecretName.of(projectId, secretId);
        // Get filtered versions.
        ListSecretVersionsRequest request = ListSecretVersionsRequest.newBuilder().setParent(secretName.toString()).setFilter(filter).build();
        ListSecretVersionsPagedResponse pagedResponse = client.listSecretVersions(request);
        // List all versions and their state.
        pagedResponse.iterateAll().forEach(version -> {
            System.out.printf("Secret version %s, %s\n", version.getName(), version.getState());
        });
    }
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) ListSecretVersionsPagedResponse(com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretVersionsPagedResponse) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient) ListSecretVersionsRequest(com.google.cloud.secretmanager.v1.ListSecretVersionsRequest)

Example 4 with ListSecretVersionsRequest

use of com.google.cloud.secretmanager.v1.ListSecretVersionsRequest in project java-secretmanager by googleapis.

the class ITSystemTest method listSecretVersionsTest.

@Test
public void listSecretVersionsTest() {
    ListSecretVersionsRequest request = ListSecretVersionsRequest.newBuilder().setParent(formattedSecretName).build();
    for (SecretVersion actualSecretVersion : client.listSecretVersions(request).iterateAll()) {
        if (secretVersion.getName().equals(actualSecretVersion.getName())) {
            assertEquals(secretVersion.getCreateTime(), actualSecretVersion.getCreateTime());
            assertEquals(SecretVersion.State.ENABLED, actualSecretVersion.getState());
        }
    }
}
Also used : SecretVersion(com.google.cloud.secretmanager.v1beta1.SecretVersion) ListSecretVersionsRequest(com.google.cloud.secretmanager.v1beta1.ListSecretVersionsRequest) Test(org.junit.Test)

Example 5 with ListSecretVersionsRequest

use of com.google.cloud.secretmanager.v1.ListSecretVersionsRequest in project java-secretmanager by googleapis.

the class SecretManagerServiceClientTest method listSecretVersionsTest.

@Test
public void listSecretVersionsTest() throws Exception {
    SecretVersion responsesElement = SecretVersion.newBuilder().build();
    ListSecretVersionsResponse expectedResponse = ListSecretVersionsResponse.newBuilder().setNextPageToken("").addAllVersions(Arrays.asList(responsesElement)).build();
    mockSecretManagerService.addResponse(expectedResponse);
    SecretName parent = SecretName.of("[PROJECT]", "[SECRET]");
    ListSecretVersionsPagedResponse pagedListResponse = client.listSecretVersions(parent);
    List<SecretVersion> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getVersionsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockSecretManagerService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListSecretVersionsRequest actualRequest = ((ListSecretVersionsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListSecretVersionsPagedResponse(com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretVersionsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Aggregations

ListSecretVersionsPagedResponse (com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretVersionsPagedResponse)3 Test (org.junit.Test)3 ListSecretVersionsRequest (com.google.cloud.secretmanager.v1.ListSecretVersionsRequest)2 SecretManagerServiceClient (com.google.cloud.secretmanager.v1.SecretManagerServiceClient)2 SecretName (com.google.cloud.secretmanager.v1.SecretName)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 SecretVersion (com.google.cloud.secretmanager.v1.SecretVersion)1 ListSecretVersionsRequest (com.google.cloud.secretmanager.v1beta1.ListSecretVersionsRequest)1 SecretVersion (com.google.cloud.secretmanager.v1beta1.SecretVersion)1 ByteString (com.google.protobuf.ByteString)1 ArrayList (java.util.ArrayList)1