use of com.google.cloud.secretmanager.v1.SecretVersionName in project java-secretmanager by googleapis.
the class DisableSecretVersion method disableSecretVersion.
// Disable an existing secret version.
public void disableSecretVersion(String projectId, String secretId, String versionId) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
// Build the name from the version.
SecretVersionName secretVersionName = SecretVersionName.of(projectId, secretId, versionId);
// Create the secret.
SecretVersion version = client.disableSecretVersion(secretVersionName);
System.out.printf("Disabled secret version %s\n", version.getName());
}
}
use of com.google.cloud.secretmanager.v1.SecretVersionName 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.SecretVersionName in project quarkus-google-cloud-services by quarkiverse.
the class SecretManagerConfigSource method getValue.
@Override
public String getValue(String propertyName) {
SecretVersionName secretVersionName = SecretManagerConfigUtils.getSecretVersionName(propertyName, defaultProject);
if (secretVersionName == null) {
// The propertyName is not in the form "${sm//...}" so return null.
return null;
}
AccessSecretVersionResponse response = clientProvider.get().accessSecretVersion(secretVersionName);
return response.getPayload().getData().toStringUtf8();
}
use of com.google.cloud.secretmanager.v1.SecretVersionName in project quarkus-google-cloud-services by quarkiverse.
the class SecretManagerConfigUtilsTest method testLongProperty_projectSecretVersion.
@Test
public void testLongProperty_projectSecretVersion() {
String property = "sm//projects/my-project/secrets/the-secret/versions/3";
SecretVersionName secretIdentifier = SecretManagerConfigUtils.getSecretVersionName(property, DEFAULT_PROJECT);
assertThat(secretIdentifier.getProject()).isEqualTo("my-project");
assertThat(secretIdentifier.getSecret()).isEqualTo("the-secret");
assertThat(secretIdentifier.getSecretVersion()).isEqualTo("3");
}
use of com.google.cloud.secretmanager.v1.SecretVersionName in project quarkus-google-cloud-services by quarkiverse.
the class SecretManagerConfigUtilsTest method testShortProperty_secretId.
@Test
public void testShortProperty_secretId() {
String property = "sm//the-secret";
SecretVersionName secretIdentifier = SecretManagerConfigUtils.getSecretVersionName(property, DEFAULT_PROJECT);
assertThat(secretIdentifier.getProject()).isEqualTo("defaultProject");
assertThat(secretIdentifier.getSecret()).isEqualTo("the-secret");
assertThat(secretIdentifier.getSecretVersion()).isEqualTo("latest");
}
Aggregations