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());
}
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());
}
}
Aggregations