Search in sources :

Example 31 with Secret

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

Example 32 with Secret

use of com.google.cloud.secretmanager.v1.Secret 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.v1.SecretManagerServiceClient.ListSecretsPagedResponse) Test(org.junit.Test)

Example 33 with Secret

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

the class ITSystemTest method getSecretTest.

@Test
public void getSecretTest() {
    GetSecretRequest request = GetSecretRequest.newBuilder().setName(formattedSecretName).build();
    Secret actualSecret = client.getSecret(request);
    assertEquals(secret.getName(), actualSecret.getName());
    assertEquals(secret.getReplication(), actualSecret.getReplication());
    assertEquals(secret.getCreateTime(), actualSecret.getCreateTime());
}
Also used : Secret(com.google.cloud.secretmanager.v1beta1.Secret) GetSecretRequest(com.google.cloud.secretmanager.v1beta1.GetSecretRequest) Test(org.junit.Test)

Example 34 with Secret

use of com.google.cloud.secretmanager.v1.Secret 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 35 with Secret

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

the class NativeImageSecretManagerSample method printSecretVersion.

static void printSecretVersion(SecretManagerServiceClient client, SecretVersion version) {
    AccessSecretVersionResponse response = client.accessSecretVersion(version.getName());
    String payload = response.getPayload().getData().toStringUtf8();
    System.out.println("Reading secret value: " + payload);
    System.out.println("(Note: Don't print secret values in prod!)");
}
Also used : ByteString(com.google.protobuf.ByteString) AccessSecretVersionResponse(com.google.cloud.secretmanager.v1.AccessSecretVersionResponse)

Aggregations

SecretManagerServiceClient (com.google.cloud.secretmanager.v1.SecretManagerServiceClient)51 SecretName (com.google.cloud.secretmanager.v1.SecretName)44 Test (org.junit.Test)42 SecretVersionName (com.google.cloud.secretmanager.v1.SecretVersionName)38 SecretVersion (com.google.cloud.secretmanager.v1.SecretVersion)22 Secret (com.google.cloud.secretmanager.v1.Secret)21 ProjectName (com.google.cloud.secretmanager.v1.ProjectName)16 ByteString (com.google.protobuf.ByteString)13 AccessSecretVersionResponse (com.google.cloud.secretmanager.v1.AccessSecretVersionResponse)9 ListSecretsPagedResponse (com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretsPagedResponse)7 CreateSecretRequest (com.google.cloud.secretmanager.v1.CreateSecretRequest)6 SecretPayload (com.google.cloud.secretmanager.v1.SecretPayload)6 Test (org.junit.jupiter.api.Test)5 AddSecretVersionRequest (com.google.cloud.secretmanager.v1.AddSecretVersionRequest)4 DeleteSecretRequest (com.google.cloud.secretmanager.v1.DeleteSecretRequest)4 ListSecretVersionsPagedResponse (com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretVersionsPagedResponse)4 Binding (com.google.iam.v1.Binding)4 Policy (com.google.iam.v1.Policy)4 ListSecretsRequest (com.google.cloud.secretmanager.v1.ListSecretsRequest)3 Secret (com.google.cloud.secretmanager.v1beta1.Secret)3