use of com.google.cloud.secretmanager.v1.SecretName in project java-docs-samples by GoogleCloudPlatform.
the class UpdateSecretWithEtag method updateSecret.
// Update an existing secret.
public static void updateSecret(String projectId, String secretId, 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.
SecretName secretName = SecretName.of(projectId, secretId);
// Build the updated secret.
Secret secret = Secret.newBuilder().setName(secretName.toString()).setEtag(etag).putLabels("secretmanager", "rocks").build();
// Build the field mask.
FieldMask fieldMask = FieldMaskUtil.fromString("labels");
// Update the secret.
Secret updatedSecret = client.updateSecret(secret, fieldMask);
System.out.printf("Updated secret %s\n", updatedSecret.getName());
}
}
use of com.google.cloud.secretmanager.v1.SecretName in project java-docs-samples by GoogleCloudPlatform.
the class SnippetsIT method testListSecrets.
@Test
public void testListSecrets() throws IOException {
SecretName name = SecretName.parse(TEST_SECRET.getName());
ListSecrets.listSecrets(name.getProject());
assertThat(stdOut.toString()).contains("Secret projects/");
assertThat(stdOut.toString()).contains(name.getSecret());
}
use of com.google.cloud.secretmanager.v1.SecretName in project java-docs-samples by GoogleCloudPlatform.
the class SnippetsIT method testListSecretVersionsWithFilter.
@Test
public void testListSecretVersionsWithFilter() throws IOException {
SecretName name = SecretName.parse(TEST_SECRET_WITH_VERSIONS.getName());
ListSecretVersionsWithFilter.listSecretVersions(name.getProject(), name.getSecret(), "name:1");
assertThat(stdOut.toString()).contains("Secret version");
}
use of com.google.cloud.secretmanager.v1.SecretName in project java-docs-samples by GoogleCloudPlatform.
the class SnippetsIT method testListSecretVersions.
@Test
public void testListSecretVersions() throws IOException {
SecretName name = SecretName.parse(TEST_SECRET_WITH_VERSIONS.getName());
ListSecretVersions.listSecretVersions(name.getProject(), name.getSecret());
assertThat(stdOut.toString()).contains("Secret version");
}
use of com.google.cloud.secretmanager.v1.SecretName in project java-docs-samples by GoogleCloudPlatform.
the class SnippetsIT method testUpdateSecret.
@Test
public void testUpdateSecret() throws IOException {
SecretName name = SecretName.parse(TEST_SECRET.getName());
UpdateSecret.updateSecret(name.getProject(), name.getSecret());
assertThat(stdOut.toString()).contains("Updated secret");
}
Aggregations