use of com.google.cloud.secretmanager.v1.SecretVersion in project java-secretmanager by googleapis.
the class NativeImageSecretManagerSampleIT method testCreateAndPrintSecret.
@Test
public void testCreateAndPrintSecret() throws IOException {
try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
NativeImageSecretManagerSample.createSecret(client, PROJECT_ID, NATIVE_TEST_SECRET_ID);
SecretVersion version = NativeImageSecretManagerSample.addSecretVersion(client, PROJECT_ID, NATIVE_TEST_SECRET_ID);
NativeImageSecretManagerSample.printSecretVersion(client, version);
assertThat(bout.toString()).contains("Reading secret value: Hello World");
}
}
use of com.google.cloud.secretmanager.v1.SecretVersion in project java-secretmanager by googleapis.
the class AddSecretVersion method addSecretVersion.
// Add a new version to the existing secret.
public void addSecretVersion(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()) {
SecretName secretName = SecretName.of(projectId, secretId);
// Create the secret payload.
SecretPayload payload = SecretPayload.newBuilder().setData(ByteString.copyFromUtf8("my super secret data")).build();
// Add the secret version.
SecretVersion version = client.addSecretVersion(secretName, payload);
System.out.printf("Added secret version %s\n", version.getName());
}
}
use of com.google.cloud.secretmanager.v1.SecretVersion in project java-docs-samples by GoogleCloudPlatform.
the class SnippetsIT method addSecretVersion.
private static SecretVersion addSecretVersion(Secret secret) throws IOException {
SecretName parent = SecretName.parse(secret.getName());
AddSecretVersionRequest request = AddSecretVersionRequest.newBuilder().setParent(parent.toString()).setPayload(SecretPayload.newBuilder().setData(ByteString.copyFromUtf8("my super secret data")).build()).build();
try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
return client.addSecretVersion(request);
}
}
use of com.google.cloud.secretmanager.v1.SecretVersion in project java-docs-samples by GoogleCloudPlatform.
the class DestroySecretVersionWithEtag method destroySecretVersion.
// Destroy an existing secret version.
public static void destroySecretVersion(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.
DestroySecretVersionRequest request = DestroySecretVersionRequest.newBuilder().setName(secretVersionName.toString()).setEtag(etag).build();
// Destroy the secret version.
SecretVersion version = client.destroySecretVersion(request);
System.out.printf("Destroyed secret version %s\n", version.getName());
}
}
use of com.google.cloud.secretmanager.v1.SecretVersion 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