use of com.google.cloud.secretmanager.v1.SecretName in project java-docs-samples by GoogleCloudPlatform.
the class GetSecret method getSecret.
// Get an existing secret.
public static void getSecret(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);
// Create the secret.
Secret secret = client.getSecret(secretName);
// Get the replication policy.
String replication = "";
if (secret.getReplication().getAutomatic() != null) {
replication = "AUTOMATIC";
} else if (secret.getReplication().getUserManaged() != null) {
replication = "MANAGED";
} else {
throw new IllegalStateException("Unknown replication type");
}
System.out.printf("Secret %s, replication %s\n", secret.getName(), replication);
}
}
use of com.google.cloud.secretmanager.v1.SecretName in project micronaut-gcp by micronaut-projects.
the class GoogleClientExample method onStartup.
@EventListener
public void onStartup(StartupEvent event) {
AccessSecretVersionResponse response = client.accessSecretVersion(AccessSecretVersionRequest.newBuilder().setName(SecretVersionName.of("my-cloud-project", "secretName", "latest").toString()).build());
String secret = response.getPayload().getData().toStringUtf8();
}
use of com.google.cloud.secretmanager.v1.SecretName in project nomulus by google.
the class SecretManagerClientImpl method addSecretVersion.
@Override
public String addSecretVersion(String secretId, String data) {
checkNotNull(secretId, "secretId");
checkNotNull(data, "data");
SecretName secretName = SecretName.of(project, secretId);
SecretPayload secretPayload = SecretPayload.newBuilder().setData(ByteString.copyFromUtf8(data)).build();
SecretVersion response = callSecretManager(() -> csmClient.addSecretVersion(secretName, secretPayload));
checkState(SecretVersionName.isParsableFrom(response.getName()));
SecretVersionName secretVersionName = SecretVersionName.parse(response.getName());
return secretVersionName.getSecretVersion();
}
use of com.google.cloud.secretmanager.v1.SecretName in project spring-cloud-gcp by GoogleCloudPlatform.
the class SecretManagerTemplateTests method verifyDeleteSecretRequest.
private void verifyDeleteSecretRequest(String secretId, String projectId) {
SecretName name = SecretName.of(projectId, secretId);
DeleteSecretRequest request = DeleteSecretRequest.newBuilder().setName(name.toString()).build();
verify(this.client).deleteSecret(request);
}
use of com.google.cloud.secretmanager.v1.SecretName in project spring-cloud-gcp by GoogleCloudPlatform.
the class SecretManagerTemplate method deleteSecret.
@Override
public void deleteSecret(String secretId, String projectId) {
SecretName name = SecretName.of(projectId, secretId);
DeleteSecretRequest request = DeleteSecretRequest.newBuilder().setName(name.toString()).build();
this.secretManagerServiceClient.deleteSecret(request);
}
Aggregations