use of com.google.cloud.secretmanager.v1beta1.Secret in project java-secretmanager by googleapis.
the class UpdateSecret method updateSecret.
// Update an existing secret.
public 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");
// Create the secret.
Secret updatedSecret = client.updateSecret(secret, fieldMask);
System.out.printf("Updated secret %s\n", updatedSecret.getName());
}
}
use of com.google.cloud.secretmanager.v1beta1.Secret in project nomulus by google.
the class SecretManagerClientImpl method createSecret.
@Override
public void createSecret(String secretId) {
checkNotNull(secretId, "secretId");
Secret secretSettings = Secret.newBuilder().setReplication(defaultReplicationPolicy()).build();
callSecretManager(() -> csmClient.createSecret(ProjectName.of(project), secretId, secretSettings));
}
use of com.google.cloud.secretmanager.v1beta1.Secret in project native-image-support-java by GoogleCloudPlatform.
the class SecretManagerSampleApplication method hasSecret.
static boolean hasSecret(SecretManagerServiceClient client, String projectId, String secretId) {
ProjectName projectName = ProjectName.of(projectId);
ListSecretsPagedResponse pagedResponse = client.listSecrets(projectName);
for (Secret secret : pagedResponse.iterateAll()) {
String otherSecretId = extractSecretId(secret);
if (secretId.equals(otherSecretId)) {
return true;
}
}
return false;
}
use of com.google.cloud.secretmanager.v1beta1.Secret in project native-image-support-java by GoogleCloudPlatform.
the class SecretManagerSampleApplication method createSecret.
static void createSecret(SecretManagerServiceClient client, String projectId, String secretId) {
ProjectName projectName = ProjectName.of(projectId);
Secret secret = Secret.newBuilder().setReplication(Replication.newBuilder().setAutomatic(Replication.Automatic.newBuilder().build()).build()).build();
Secret createdSecret = client.createSecret(projectName, secretId, secret);
System.out.println("Created secret: " + createdSecret.getName());
}
use of com.google.cloud.secretmanager.v1beta1.Secret in project spring-cloud-gcp by spring-cloud.
the class SecretManagerTemplateTests method verifyCreateSecretRequest.
private void verifyCreateSecretRequest(String secretId, String projectId) {
Secret secretToAdd = Secret.newBuilder().setReplication(Replication.newBuilder().setAutomatic(Replication.Automatic.newBuilder()).build()).build();
CreateSecretRequest createSecretRequest = CreateSecretRequest.newBuilder().setParent("projects/" + projectId).setSecretId(secretId).setSecret(secretToAdd).build();
verify(this.client).createSecret(createSecretRequest);
}
Aggregations