use of com.google.cloud.secretmanager.v1.SecretManagerServiceClient in project native-image-support-java by GoogleCloudPlatform.
the class SecretManagerSampleApplication method printSecretVersion.
static void printSecretVersion(SecretManagerServiceClient client, SecretVersion version) {
AccessSecretVersionResponse response = client.accessSecretVersion(version.getName());
String payload = response.getPayload().getData().toStringUtf8();
System.out.println("Reading secret value: " + payload);
System.out.println("(Note: Don't print secret values in prod!)");
}
use of com.google.cloud.secretmanager.v1.SecretManagerServiceClient in project native-image-support-java by GoogleCloudPlatform.
the class SecretManagerSampleApplication method addSecretVersion.
static SecretVersion addSecretVersion(SecretManagerServiceClient client, String projectId, String secretId) {
SecretName secretName = SecretName.of(projectId, secretId);
SecretPayload payload = SecretPayload.newBuilder().setData(ByteString.copyFromUtf8("Hello World")).build();
SecretVersion version = client.addSecretVersion(secretName, payload);
System.out.println("Added Secret Version: " + version.getName());
return version;
}
use of com.google.cloud.secretmanager.v1.SecretManagerServiceClient in project wrongsecrets by commjoen.
the class Challenge11 method getGCPChallenge11Value.
private String getGCPChallenge11Value() {
if (isGCP()) {
log.info("Getting credentials from GCP");
// Based on https://cloud.google.com/secret-manager/docs/reference/libraries
try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
log.info("Fetching secret form Google Secret Manager...");
SecretVersionName secretVersionName = SecretVersionName.of(projectId, "wrongsecret-3", "latest");
AccessSecretVersionResponse response = client.accessSecretVersion(secretVersionName);
return response.getPayload().getData().toStringUtf8();
} catch (ApiException e) {
log.error("Exception getting secret: ", e);
} catch (IOException e) {
log.error("Could not get the web identity token, due to ", e);
}
} else {
log.info("Skipping credentials from GCP");
}
return gcpDefaultValue;
}
use of com.google.cloud.secretmanager.v1.SecretManagerServiceClient in project quarkus-google-cloud-services by quarkiverse.
the class ApplicationProducerMock method secretManagerServiceClient.
@Produces
@Singleton
@Default
public SecretManagerServiceClient secretManagerServiceClient() {
SecretManagerServiceClient client = Mockito.mock(SecretManagerServiceClient.class);
when(client.accessSecretVersion(any(SecretVersionName.class))).thenReturn(AccessSecretVersionResponse.newBuilder().setName("test-secret").setPayload(SecretPayload.newBuilder().setData(ByteString.copyFromUtf8("hello"))).build());
return client;
}
use of com.google.cloud.secretmanager.v1.SecretManagerServiceClient in project quarkus-google-cloud-services by quarkiverse.
the class SecretManagerProducer method secretManagerClient.
@Produces
@Singleton
@Default
@Unremovable
public SecretManagerServiceClient secretManagerClient() throws IOException {
GcpBootstrapConfiguration gcpConfiguration = gcpConfigHolder.getBootstrapConfig();
SecretManagerServiceSettings.Builder builder = SecretManagerServiceSettings.newBuilder().setCredentialsProvider(() -> googleCredentials);
builder.setQuotaProjectId(gcpConfiguration.projectId.orElse(null));
return SecretManagerServiceClient.create(builder.build());
}
Aggregations