use of com.google.cloud.secretmanager.v1.Secret in project java-docs-samples by GoogleCloudPlatform.
the class ListSecretVersionsWithFilter method listSecretVersions.
// List all secret versions for a secret.
public static void listSecretVersions(String projectId, String secretId, String filter) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
// Build the parent name.
SecretName secretName = SecretName.of(projectId, secretId);
// Get filtered versions.
ListSecretVersionsRequest request = ListSecretVersionsRequest.newBuilder().setParent(secretName.toString()).setFilter(filter).build();
ListSecretVersionsPagedResponse pagedResponse = client.listSecretVersions(request);
// List all versions and their state.
pagedResponse.iterateAll().forEach(version -> {
System.out.printf("Secret version %s, %s\n", version.getName(), version.getState());
});
}
}
use of com.google.cloud.secretmanager.v1.Secret in project java-docs-samples by GoogleCloudPlatform.
the class ListSecretsWithFilter method listSecrets.
// List all secrets for a project
public static void listSecrets(String projectId, String filter) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
// Build the parent name.
ProjectName projectName = ProjectName.of(projectId);
// Get filtered secrets.
ListSecretsRequest request = ListSecretsRequest.newBuilder().setParent(projectName.toString()).setFilter(filter).build();
ListSecretsPagedResponse pagedResponse = client.listSecrets(request);
// List all secrets.
pagedResponse.iterateAll().forEach(secret -> {
System.out.printf("Secret %s\n", secret.getName());
});
}
}
use of com.google.cloud.secretmanager.v1.Secret in project java-docs-samples by GoogleCloudPlatform.
the class UpdateSecret method updateSecret.
// Update an existing secret.
public static void updateSecret(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);
// Build the updated secret.
Secret secret = Secret.newBuilder().setName(secretName.toString()).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.Secret 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.Secret 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());
}
Aggregations