use of com.google.cloud.secretmanager.v1.SecretVersionName in project spring-cloud-gcp by GoogleCloudPlatform.
the class SecretManagerPropertyUtilsTests method testShortProperty_projectSecretId.
@Test
void testShortProperty_projectSecretId() {
String property = "sm://the-secret/the-version";
SecretVersionName secretIdentifier = SecretManagerPropertyUtils.getSecretVersionName(property, DEFAULT_PROJECT_ID_PROVIDER);
assertThat(secretIdentifier.getProject()).isEqualTo("defaultProject");
assertThat(secretIdentifier.getSecret()).isEqualTo("the-secret");
assertThat(secretIdentifier.getSecretVersion()).isEqualTo("the-version");
}
use of com.google.cloud.secretmanager.v1.SecretVersionName in project java-secretmanager by googleapis.
the class SnippetsIT method testGetSecretVersion.
@Test
public void testGetSecretVersion() throws IOException {
SecretVersionName name = SecretVersionName.parse(TEST_SECRET_VERSION.getName());
new GetSecretVersion().getSecretVersion(name.getProject(), name.getSecret(), name.getSecretVersion());
assertThat(stdOut.toString()).contains("Secret version");
assertThat(stdOut.toString()).contains("state ENABLED");
}
use of com.google.cloud.secretmanager.v1.SecretVersionName in project java-secretmanager by googleapis.
the class SnippetsIT method testEnableSecretVersion.
@Test
public void testEnableSecretVersion() throws IOException {
SecretVersionName name = SecretVersionName.parse(TEST_SECRET_VERSION_TO_ENABLE.getName());
new EnableSecretVersion().enableSecretVersion(name.getProject(), name.getSecret(), name.getSecretVersion());
assertThat(stdOut.toString()).contains("Enabled secret version");
}
use of com.google.cloud.secretmanager.v1.SecretVersionName in project java-secretmanager by googleapis.
the class SnippetsIT method testDestroySecretVersion.
@Test
public void testDestroySecretVersion() throws IOException {
SecretVersionName name = SecretVersionName.parse(TEST_SECRET_VERSION_TO_DESTROY.getName());
new DestroySecretVersion().destroySecretVersion(name.getProject(), name.getSecret(), name.getSecretVersion());
assertThat(stdOut.toString()).contains("Destroyed secret version");
}
use of com.google.cloud.secretmanager.v1.SecretVersionName in project java-secretmanager by googleapis.
the class AccessSecretVersion method accessSecretVersion.
// Access the payload for the given secret version if one exists. The version
// can be a version number as a string (e.g. "5") or an alias (e.g. "latest").
public void accessSecretVersion(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()) {
SecretVersionName secretVersionName = SecretVersionName.of(projectId, secretId, versionId);
// Access the secret version.
AccessSecretVersionResponse response = client.accessSecretVersion(secretVersionName);
// Print the secret payload.
//
// WARNING: Do not print the secret in a production environment - this
// snippet is showing how to access the secret material.
String payload = response.getPayload().getData().toStringUtf8();
System.out.printf("Plaintext: %s\n", payload);
}
}
Aggregations