Search in sources :

Example 1 with DisableSecretVersionRequest

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

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

the class DisableSecretVersionWithEtag method disableSecretVersion.

// Disable an existing secret version.
public static void disableSecretVersion(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.
        DisableSecretVersionRequest request = DisableSecretVersionRequest.newBuilder().setName(secretVersionName.toString()).setEtag(etag).build();
        // Disable the secret version.
        SecretVersion version = client.disableSecretVersion(request);
        System.out.printf("Disabled secret version %s\n", version.getName());
    }
}
Also used : DisableSecretVersionRequest(com.google.cloud.secretmanager.v1.DisableSecretVersionRequest) SecretVersionName(com.google.cloud.secretmanager.v1.SecretVersionName) SecretVersion(com.google.cloud.secretmanager.v1.SecretVersion) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient)

Aggregations

DisableSecretVersionRequest (com.google.cloud.secretmanager.v1.DisableSecretVersionRequest)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