Search in sources :

Example 1 with EnableSecretVersionRequest

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

use of com.google.cloud.secretmanager.v1.EnableSecretVersionRequest in project java-docs-samples by GoogleCloudPlatform.

the class EnableSecretVersionWithEtag method enableSecretVersion.

// Enable an existing secret version.
public static void enableSecretVersion(String projectId, String secretId, String versionId, String etag) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
        // Build the name from the version.
        SecretVersionName secretVersionName = SecretVersionName.of(projectId, secretId, versionId);
        // Build the request.
        EnableSecretVersionRequest request = EnableSecretVersionRequest.newBuilder().setName(secretVersionName.toString()).setEtag(etag).build();
        // Enable the secret version.
        SecretVersion version = client.enableSecretVersion(request);
        System.out.printf("Enabled secret version %s\n", version.getName());
    }
}
Also used : SecretVersionName(com.google.cloud.secretmanager.v1.SecretVersionName) SecretVersion(com.google.cloud.secretmanager.v1.SecretVersion) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient) EnableSecretVersionRequest(com.google.cloud.secretmanager.v1.EnableSecretVersionRequest)

Aggregations

EnableSecretVersionRequest (com.google.cloud.secretmanager.v1.EnableSecretVersionRequest)1 SecretManagerServiceClient (com.google.cloud.secretmanager.v1.SecretManagerServiceClient)1 SecretVersion (com.google.cloud.secretmanager.v1.SecretVersion)1 SecretVersionName (com.google.cloud.secretmanager.v1.SecretVersionName)1 DisableSecretVersionRequest (com.google.cloud.secretmanager.v1beta1.DisableSecretVersionRequest)1 EnableSecretVersionRequest (com.google.cloud.secretmanager.v1beta1.EnableSecretVersionRequest)1 SecretVersion (com.google.cloud.secretmanager.v1beta1.SecretVersion)1 Test (org.junit.Test)1