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