use of com.google.cloud.secretmanager.v1.SecretManagerServiceClient in project java-docs-samples by GoogleCloudPlatform.
the class EnableSecretVersion method enableSecretVersion.
// Enable an existing secret version.
public static void enableSecretVersion(String projectId, String secretId, String versionId) 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);
// Enable the secret version.
SecretVersion version = client.enableSecretVersion(secretVersionName);
System.out.printf("Enabled secret version %s\n", version.getName());
}
}
use of com.google.cloud.secretmanager.v1.SecretManagerServiceClient 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());
}
}
use of com.google.cloud.secretmanager.v1.SecretManagerServiceClient in project java-docs-samples by GoogleCloudPlatform.
the class GetSecret method getSecret.
// Get an existing secret.
public static void getSecret(String projectId, String secretId) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
// Build the name.
SecretName secretName = SecretName.of(projectId, secretId);
// Create the secret.
Secret secret = client.getSecret(secretName);
// Get the replication policy.
String replication = "";
if (secret.getReplication().getAutomatic() != null) {
replication = "AUTOMATIC";
} else if (secret.getReplication().getUserManaged() != null) {
replication = "MANAGED";
} else {
throw new IllegalStateException("Unknown replication type");
}
System.out.printf("Secret %s, replication %s\n", secret.getName(), replication);
}
}
use of com.google.cloud.secretmanager.v1.SecretManagerServiceClient in project java-docs-samples by GoogleCloudPlatform.
the class GetSecretVersion method getSecretVersion.
// Get an existing secret version.
public static void getSecretVersion(String projectId, String secretId, String versionId) 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);
// Create the secret.
SecretVersion version = client.getSecretVersion(secretVersionName);
System.out.printf("Secret version %s, state %s\n", version.getName(), version.getState());
}
}
use of com.google.cloud.secretmanager.v1.SecretManagerServiceClient in project java-secretmanager by googleapis.
the class SnippetsIT method createSecret.
private static Secret createSecret() throws IOException {
ProjectName parent = ProjectName.of(PROJECT_ID);
CreateSecretRequest request = CreateSecretRequest.newBuilder().setParent(parent.toString()).setSecretId(randomSecretId()).setSecret(Secret.newBuilder().setReplication(Replication.newBuilder().setAutomatic(Replication.Automatic.newBuilder().build()).build()).build()).build();
try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
return client.createSecret(request);
}
}
Aggregations