Search in sources :

Example 6 with SecretVersion

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

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

the class ITSystemTest method tearDown.

@AfterClass
public static void tearDown() {
    /* destroy secret version */
    DestroySecretVersionRequest versionRequest = DestroySecretVersionRequest.newBuilder().setName(formattedSecretVersion).build();
    SecretVersion actualSecretVersion = client.destroySecretVersion(versionRequest);
    assertEquals(secretVersion.getCreateTime(), actualSecretVersion.getCreateTime());
    assertEquals(SecretVersion.State.DESTROYED, actualSecretVersion.getState());
    /* delete secret */
    DeleteSecretRequest secretRequest = DeleteSecretRequest.newBuilder().setName(formattedSecretName).build();
    client.deleteSecret(secretRequest);
    client.close();
}
Also used : SecretVersion(com.google.cloud.secretmanager.v1beta1.SecretVersion) DestroySecretVersionRequest(com.google.cloud.secretmanager.v1beta1.DestroySecretVersionRequest) DeleteSecretRequest(com.google.cloud.secretmanager.v1beta1.DeleteSecretRequest) AfterClass(org.junit.AfterClass)

Example 8 with SecretVersion

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

the class ITSystemTest method disableAndEnableSecretVersionTest.

@Test
public void disableAndEnableSecretVersionTest() {
    DisableSecretVersionRequest disableSecretVersionRequest = DisableSecretVersionRequest.newBuilder().setName(formattedSecretVersion).build();
    SecretVersion disableSecretVersion = client.disableSecretVersion(disableSecretVersionRequest);
    assertEquals(secretVersion.getName(), disableSecretVersion.getName());
    assertEquals(secretVersion.getCreateTime(), disableSecretVersion.getCreateTime());
    assertEquals(SecretVersion.State.DISABLED, disableSecretVersion.getState());
    EnableSecretVersionRequest enableSecretVersionRequest = EnableSecretVersionRequest.newBuilder().setName(formattedSecretVersion).build();
    SecretVersion enableSecretVersion = client.enableSecretVersion(enableSecretVersionRequest);
    assertEquals(secretVersion.getName(), enableSecretVersion.getName());
    assertEquals(secretVersion.getCreateTime(), enableSecretVersion.getCreateTime());
    assertEquals(SecretVersion.State.ENABLED, enableSecretVersion.getState());
}
Also used : DisableSecretVersionRequest(com.google.cloud.secretmanager.v1beta1.DisableSecretVersionRequest) SecretVersion(com.google.cloud.secretmanager.v1beta1.SecretVersion) EnableSecretVersionRequest(com.google.cloud.secretmanager.v1beta1.EnableSecretVersionRequest) Test(org.junit.Test)

Example 9 with SecretVersion

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

Example 10 with SecretVersion

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

the class NativeImageSecretManagerSample method addSecretVersion.

static SecretVersion addSecretVersion(SecretManagerServiceClient client, String projectId, String secretId) {
    SecretName secretName = SecretName.of(projectId, secretId);
    SecretPayload payload = SecretPayload.newBuilder().setData(ByteString.copyFromUtf8("Hello World")).build();
    SecretVersion version = client.addSecretVersion(secretName, payload);
    System.out.println("Added Secret Version: " + version.getName());
    return version;
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) SecretVersion(com.google.cloud.secretmanager.v1.SecretVersion) SecretPayload(com.google.cloud.secretmanager.v1.SecretPayload)

Aggregations

SecretVersion (com.google.cloud.secretmanager.v1.SecretVersion)22 SecretManagerServiceClient (com.google.cloud.secretmanager.v1.SecretManagerServiceClient)21 SecretVersionName (com.google.cloud.secretmanager.v1.SecretVersionName)13 SecretName (com.google.cloud.secretmanager.v1.SecretName)7 SecretPayload (com.google.cloud.secretmanager.v1.SecretPayload)7 Test (org.junit.Test)7 ByteString (com.google.protobuf.ByteString)6 AccessSecretVersionResponse (com.google.cloud.secretmanager.v1.AccessSecretVersionResponse)5 SecretVersion (com.google.cloud.secretmanager.v1beta1.SecretVersion)4 AccessSecretVersionRequest (com.google.cloud.secretmanager.v1.AccessSecretVersionRequest)2 AddSecretVersionRequest (com.google.cloud.secretmanager.v1.AddSecretVersionRequest)2 ListSecretVersionsRequest (com.google.cloud.secretmanager.v1.ListSecretVersionsRequest)2 ProjectName (com.google.cloud.secretmanager.v1.ProjectName)2 Secret (com.google.cloud.secretmanager.v1.Secret)2 ListSecretVersionsPagedResponse (com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretVersionsPagedResponse)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 ArrayList (java.util.ArrayList)2 DestroySecretVersionRequest (com.google.cloud.secretmanager.v1.DestroySecretVersionRequest)1 DisableSecretVersionRequest (com.google.cloud.secretmanager.v1.DisableSecretVersionRequest)1 EnableSecretVersionRequest (com.google.cloud.secretmanager.v1.EnableSecretVersionRequest)1