use of com.google.cloud.secretmanager.v1.SecretName in project java-docs-samples by GoogleCloudPlatform.
the class SnippetsIT method testListSecretsWithFilter.
@Test
public void testListSecretsWithFilter() throws IOException {
SecretName name = SecretName.parse(TEST_SECRET.getName());
ListSecretsWithFilter.listSecrets(name.getProject(), String.format("name:%s", name.getSecret()));
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 testGetSecret.
@Test
public void testGetSecret() throws IOException {
SecretName name = SecretName.parse(TEST_SECRET.getName());
GetSecret.getSecret(name.getProject(), name.getSecret());
assertThat(stdOut.toString()).contains("Secret");
assertThat(stdOut.toString()).contains("replication AUTOMATIC");
}
use of com.google.cloud.secretmanager.v1.SecretName 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.SecretName in project java-docs-samples by GoogleCloudPlatform.
the class SnippetsIT method testDeleteSecret.
@Test
public void testDeleteSecret() throws IOException {
SecretName name = SecretName.parse(TEST_SECRET_TO_DELETE.getName());
DeleteSecret.deleteSecret(name.getProject(), name.getSecret());
assertThat(stdOut.toString()).contains("Deleted secret");
}
use of com.google.cloud.secretmanager.v1.SecretName in project java-docs-samples by GoogleCloudPlatform.
the class DeleteSecret method deleteSecret.
// Delete an existing secret with the given name.
public static void deleteSecret(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 secret name.
SecretName secretName = SecretName.of(projectId, secretId);
// Delete the secret.
client.deleteSecret(secretName);
System.out.printf("Deleted secret %s\n", secretId);
}
}
Aggregations