use of com.google.cloud.secretmanager.v1.SecretVersionName in project spring-cloud-gcp by spring-cloud.
the class SecretManagerTemplate method deleteSecretVersion.
@Override
public void deleteSecretVersion(String secretId, String version, String projectId) {
SecretVersionName secretVersionName = SecretVersionName.newBuilder().setProject(projectId).setSecret(secretId).setSecretVersion(version).build();
this.secretManagerServiceClient.destroySecretVersion(secretVersionName);
}
use of com.google.cloud.secretmanager.v1.SecretVersionName in project spring-cloud-gcp by spring-cloud.
the class SecretManagerPropertyUtilsTests method testLongProperty_projectSecret.
@Test
public void testLongProperty_projectSecret() {
String property = "sm://projects/my-project/secrets/the-secret";
SecretVersionName secretIdentifier = SecretManagerPropertyUtils.getSecretVersionName(property, DEFAULT_PROJECT_ID_PROVIDER);
assertThat(secretIdentifier.getProject()).isEqualTo("my-project");
assertThat(secretIdentifier.getSecret()).isEqualTo("the-secret");
assertThat(secretIdentifier.getSecretVersion()).isEqualTo("latest");
}
use of com.google.cloud.secretmanager.v1.SecretVersionName in project spring-cloud-gcp by spring-cloud.
the class SecretManagerPropertyUtilsTests method testShortProperty_projectSecretId.
@Test
public void testShortProperty_projectSecretId() {
String property = "sm://the-secret/the-version";
SecretVersionName secretIdentifier = SecretManagerPropertyUtils.getSecretVersionName(property, DEFAULT_PROJECT_ID_PROVIDER);
assertThat(secretIdentifier.getProject()).isEqualTo("defaultProject");
assertThat(secretIdentifier.getSecret()).isEqualTo("the-secret");
assertThat(secretIdentifier.getSecretVersion()).isEqualTo("the-version");
}
use of com.google.cloud.secretmanager.v1.SecretVersionName in project spring-cloud-gcp by spring-cloud.
the class SecretManagerPropertyUtilsTests method testShortProperty_secretId.
@Test
public void testShortProperty_secretId() {
String property = "sm://the-secret";
SecretVersionName secretIdentifier = SecretManagerPropertyUtils.getSecretVersionName(property, DEFAULT_PROJECT_ID_PROVIDER);
assertThat(secretIdentifier.getProject()).isEqualTo("defaultProject");
assertThat(secretIdentifier.getSecret()).isEqualTo("the-secret");
assertThat(secretIdentifier.getSecretVersion()).isEqualTo("latest");
}
use of com.google.cloud.secretmanager.v1.SecretVersionName in project spring-cloud-config by spring-cloud.
the class GoogleSecretManagerV1AccessStrategy method getSecretValue.
@Override
public String getSecretValue(Secret secret, Comparator<SecretVersion> comparator) {
String result = null;
List<SecretVersion> versions = getSecretVersions(secret);
SecretVersion winner = null;
for (SecretVersion secretVersion : versions) {
if ((secretVersion.getState().getNumber() == SecretVersion.State.ENABLED_VALUE) && comparator.compare(secretVersion, winner) > 0) {
winner = secretVersion;
}
}
if (winner != null) {
SecretVersionName name = SecretVersionName.parse(winner.getName());
// Access the secret version.
AccessSecretVersionRequest request = AccessSecretVersionRequest.newBuilder().setName(name.toString()).build();
AccessSecretVersionResponse response = client.accessSecretVersion(request);
result = response.getPayload().getData().toStringUtf8();
}
return result;
}
Aggregations