Search in sources :

Example 6 with SecretVersion

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

Example 7 with SecretVersion

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

Example 10 with SecretVersion

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

the class NativeImageSecretManagerSample method main.

/**
 * Runs the Secret Manager sample application.
 */
public static void main(String[] args) throws IOException {
    String projectId = ServiceOptions.getDefaultProjectId();
    try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
        if (!hasSecret(client, projectId, NATIVE_TEST_SECRET_ID)) {
            createSecret(client, projectId, NATIVE_TEST_SECRET_ID);
        } else {
            System.out.println("Project already has secret: " + NATIVE_TEST_SECRET_ID);
        }
        SecretVersion version = addSecretVersion(client, projectId, NATIVE_TEST_SECRET_ID);
        printSecretVersion(client, version);
    }
}
Also used : SecretVersion(com.google.cloud.secretmanager.v1.SecretVersion) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient) ByteString(com.google.protobuf.ByteString)

Aggregations

SecretVersion (com.google.cloud.secretmanager.v1.SecretVersion)22 SecretManagerServiceClient (com.google.cloud.secretmanager.v1.SecretManagerServiceClient)19 SecretVersionName (com.google.cloud.secretmanager.v1.SecretVersionName)13 SecretPayload (com.google.cloud.secretmanager.v1.SecretPayload)7 Test (org.junit.Test)7 SecretName (com.google.cloud.secretmanager.v1.SecretName)5 ByteString (com.google.protobuf.ByteString)5 AccessSecretVersionResponse (com.google.cloud.secretmanager.v1.AccessSecretVersionResponse)4 SecretVersion (com.google.cloud.secretmanager.v1beta1.SecretVersion)4 AccessSecretVersionRequest (com.google.cloud.secretmanager.v1.AccessSecretVersionRequest)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.v1beta1.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 AddSecretVersionRequest (com.google.cloud.secretmanager.v1beta1.AddSecretVersionRequest)1