Search in sources :

Example 1 with ListSecretsRequest

use of com.google.cloud.secretmanager.v1beta1.ListSecretsRequest in project spring-cloud-config by spring-cloud.

the class GoogleSecretManagerV1AccessStrategy method getSecrets.

@Override
public List<Secret> getSecrets() {
    // Build the parent name.
    ProjectName project = ProjectName.of(getProjectId());
    // Create the request.
    ListSecretsRequest listSecretRequest = ListSecretsRequest.newBuilder().setParent(project.toString()).build();
    // Get all secrets.
    SecretManagerServiceClient.ListSecretsPagedResponse pagedListSecretResponse = client.listSecrets(listSecretRequest);
    List<Secret> result = new ArrayList<Secret>();
    pagedListSecretResponse.iterateAll().forEach(result::add);
    // List all secrets.
    return result;
}
Also used : Secret(com.google.cloud.secretmanager.v1.Secret) ProjectName(com.google.cloud.secretmanager.v1.ProjectName) ListSecretsRequest(com.google.cloud.secretmanager.v1.ListSecretsRequest) ArrayList(java.util.ArrayList) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient)

Example 2 with ListSecretsRequest

use of com.google.cloud.secretmanager.v1beta1.ListSecretsRequest 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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListSecretsPagedResponse(com.google.cloud.secretmanager.v1beta1.SecretManagerServiceClient.ListSecretsPagedResponse) Test(org.junit.Test)

Example 3 with ListSecretsRequest

use of com.google.cloud.secretmanager.v1beta1.ListSecretsRequest 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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListSecretsPagedResponse(com.google.cloud.secretmanager.v1beta1.SecretManagerServiceClient.ListSecretsPagedResponse) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 4 with ListSecretsRequest

use of com.google.cloud.secretmanager.v1beta1.ListSecretsRequest in project java-secretmanager by googleapis.

the class ITSystemTest method listSecretsTest.

@Test
public void listSecretsTest() {
    ListSecretsRequest request = ListSecretsRequest.newBuilder().setParent(PROJECT_NAME).build();
    for (Secret actualSecret : client.listSecrets(request).iterateAll()) {
        if (secret.getName().equals(actualSecret.getName())) {
            assertEquals(secret.getReplication(), actualSecret.getReplication());
            assertEquals(secret.getCreateTime(), actualSecret.getCreateTime());
        }
    }
}
Also used : Secret(com.google.cloud.secretmanager.v1beta1.Secret) ListSecretsRequest(com.google.cloud.secretmanager.v1beta1.ListSecretsRequest) Test(org.junit.Test)

Example 5 with ListSecretsRequest

use of com.google.cloud.secretmanager.v1beta1.ListSecretsRequest in project java-docs-samples by GoogleCloudPlatform.

the class ListSecretsWithFilter method listSecrets.

// List all secrets for a project
public static void listSecrets(String projectId, 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.
        ProjectName projectName = ProjectName.of(projectId);
        // Get filtered secrets.
        ListSecretsRequest request = ListSecretsRequest.newBuilder().setParent(projectName.toString()).setFilter(filter).build();
        ListSecretsPagedResponse pagedResponse = client.listSecrets(request);
        // List all secrets.
        pagedResponse.iterateAll().forEach(secret -> {
            System.out.printf("Secret %s\n", secret.getName());
        });
    }
}
Also used : ProjectName(com.google.cloud.secretmanager.v1.ProjectName) ListSecretsPagedResponse(com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretsPagedResponse) ListSecretsRequest(com.google.cloud.secretmanager.v1.ListSecretsRequest) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient)

Aggregations

Test (org.junit.Test)3 ListSecretsRequest (com.google.cloud.secretmanager.v1.ListSecretsRequest)2 ProjectName (com.google.cloud.secretmanager.v1.ProjectName)2 SecretManagerServiceClient (com.google.cloud.secretmanager.v1.SecretManagerServiceClient)2 ListSecretsPagedResponse (com.google.cloud.secretmanager.v1beta1.SecretManagerServiceClient.ListSecretsPagedResponse)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 Secret (com.google.cloud.secretmanager.v1.Secret)1 ListSecretsPagedResponse (com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretsPagedResponse)1 ListSecretsRequest (com.google.cloud.secretmanager.v1beta1.ListSecretsRequest)1 Secret (com.google.cloud.secretmanager.v1beta1.Secret)1 ByteString (com.google.protobuf.ByteString)1 ArrayList (java.util.ArrayList)1