Search in sources :

Example 6 with ListSecretVersionsPagedResponse

use of com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretVersionsPagedResponse in project nomulus by google.

the class SecretManagerClientImpl method listSecretVersions.

@Override
public Iterable<SecretVersionState> listSecretVersions(String secretId) {
    checkNotNull(secretId, "secretId");
    ListSecretVersionsPagedResponse response = callSecretManager(() -> csmClient.listSecretVersions(SecretName.of(project, secretId)));
    return () -> Streams.stream(response.iterateAll()).map(SecretManagerClientImpl::toSecretVersionState).iterator();
}
Also used : ListSecretVersionsPagedResponse(com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretVersionsPagedResponse)

Example 7 with ListSecretVersionsPagedResponse

use of com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretVersionsPagedResponse 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)

Example 8 with ListSecretVersionsPagedResponse

use of com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretVersionsPagedResponse 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.v1beta1.SecretManagerServiceClient.ListSecretVersionsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Aggregations

ListSecretVersionsPagedResponse (com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretVersionsPagedResponse)6 AbstractMessage (com.google.protobuf.AbstractMessage)4 Test (org.junit.Test)4 SecretManagerServiceClient (com.google.cloud.secretmanager.v1.SecretManagerServiceClient)3 SecretName (com.google.cloud.secretmanager.v1.SecretName)3 ListSecretVersionsPagedResponse (com.google.cloud.secretmanager.v1beta1.SecretManagerServiceClient.ListSecretVersionsPagedResponse)2 ByteString (com.google.protobuf.ByteString)2 ListSecretVersionsRequest (com.google.cloud.secretmanager.v1.ListSecretVersionsRequest)1