use of com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretsPagedResponse in project java-docs-samples by GoogleCloudPlatform.
the class ListSecrets method listSecrets.
// List all secrets for a project
public static void listSecrets(String projectId) 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.
ProjectName projectName = ProjectName.of(projectId);
// Get all secrets.
ListSecretsPagedResponse pagedResponse = client.listSecrets(projectName);
// List all secrets.
pagedResponse.iterateAll().forEach(secret -> {
System.out.printf("Secret %s\n", secret.getName());
});
}
}
use of com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretsPagedResponse in project java-secretmanager by googleapis.
the class SecretManagerServiceClientTest method listSecretsTest2.
@Test
public void listSecretsTest2() throws Exception {
Secret responsesElement = Secret.newBuilder().build();
ListSecretsResponse expectedResponse = ListSecretsResponse.newBuilder().setNextPageToken("").addAllSecrets(Arrays.asList(responsesElement)).build();
mockSecretManagerService.addResponse(expectedResponse);
String parent = "parent-995424086";
ListSecretsPagedResponse pagedListResponse = client.listSecrets(parent);
List<Secret> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getSecretsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockSecretManagerService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListSecretsRequest actualRequest = ((ListSecretsRequest) actualRequests.get(0));
Assert.assertEquals(parent, actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretsPagedResponse in project java-secretmanager by googleapis.
the class SecretManagerServiceClientTest method listSecretsTest.
@Test
public void listSecretsTest() throws Exception {
Secret responsesElement = Secret.newBuilder().build();
ListSecretsResponse expectedResponse = ListSecretsResponse.newBuilder().setNextPageToken("").addAllSecrets(Arrays.asList(responsesElement)).build();
mockSecretManagerService.addResponse(expectedResponse);
ProjectName parent = ProjectName.of("[PROJECT]");
ListSecretsPagedResponse pagedListResponse = client.listSecrets(parent);
List<Secret> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getSecretsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockSecretManagerService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListSecretsRequest actualRequest = ((ListSecretsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretsPagedResponse in project java-secretmanager by googleapis.
the class SecretManagerServiceClientTest method listSecretsTest2.
@Test
public void listSecretsTest2() throws Exception {
Secret responsesElement = Secret.newBuilder().build();
ListSecretsResponse expectedResponse = ListSecretsResponse.newBuilder().setNextPageToken("").addAllSecrets(Arrays.asList(responsesElement)).build();
mockSecretManagerService.addResponse(expectedResponse);
String parent = "parent-995424086";
ListSecretsPagedResponse pagedListResponse = client.listSecrets(parent);
List<Secret> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getSecretsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockSecretManagerService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListSecretsRequest actualRequest = ((ListSecretsRequest) actualRequests.get(0));
Assert.assertEquals(parent, actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretsPagedResponse in project java-secretmanager by googleapis.
the class SecretManagerServiceClientTest method listSecretsTest.
@Test
public void listSecretsTest() throws Exception {
Secret responsesElement = Secret.newBuilder().build();
ListSecretsResponse expectedResponse = ListSecretsResponse.newBuilder().setNextPageToken("").addAllSecrets(Arrays.asList(responsesElement)).build();
mockSecretManagerService.addResponse(expectedResponse);
ProjectName parent = ProjectName.of("[PROJECT]");
ListSecretsPagedResponse pagedListResponse = client.listSecrets(parent);
List<Secret> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getSecretsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockSecretManagerService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListSecretsRequest actualRequest = ((ListSecretsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations