Search in sources :

Example 46 with SecretVersionName

use of com.google.cloud.secretmanager.v1.SecretVersionName 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();
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) SecretVersion(com.google.cloud.secretmanager.v1.SecretVersion) SecretVersionName(com.google.cloud.secretmanager.v1.SecretVersionName) SecretPayload(com.google.cloud.secretmanager.v1.SecretPayload)

Example 47 with SecretVersionName

use of com.google.cloud.secretmanager.v1.SecretVersionName in project spring-cloud-gcp by GoogleCloudPlatform.

the class SecretManagerPropertyUtilsTests method testShortProperty_projectSecretIdVersion.

@Test
void testShortProperty_projectSecretIdVersion() {
    String property = "sm://my-project/the-secret/2";
    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("2");
}
Also used : SecretVersionName(com.google.cloud.secretmanager.v1.SecretVersionName) Test(org.junit.jupiter.api.Test)

Example 48 with SecretVersionName

use of com.google.cloud.secretmanager.v1.SecretVersionName in project spring-cloud-gcp by GoogleCloudPlatform.

the class SecretManagerTemplateTests method verifyDeleteSecretVersionRequest.

private void verifyDeleteSecretVersionRequest(String secretId, String version, String projectId) {
    SecretVersionName secretVersionName = SecretVersionName.newBuilder().setProject(projectId).setSecret(secretId).setSecretVersion(version).build();
    verify(this.client).destroySecretVersion(secretVersionName);
}
Also used : SecretVersionName(com.google.cloud.secretmanager.v1.SecretVersionName)

Example 49 with SecretVersionName

use of com.google.cloud.secretmanager.v1.SecretVersionName in project spring-cloud-gcp by GoogleCloudPlatform.

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);
}
Also used : SecretVersionName(com.google.cloud.secretmanager.v1.SecretVersionName)

Example 50 with SecretVersionName

use of com.google.cloud.secretmanager.v1.SecretVersionName in project spring-cloud-gcp by GoogleCloudPlatform.

the class SecretManagerPropertyUtilsTests method testLongProperty_projectSecret.

@Test
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");
}
Also used : SecretVersionName(com.google.cloud.secretmanager.v1.SecretVersionName) Test(org.junit.jupiter.api.Test)

Aggregations

SecretVersionName (com.google.cloud.secretmanager.v1.SecretVersionName)63 Test (org.junit.Test)19 SecretManagerServiceClient (com.google.cloud.secretmanager.v1.SecretManagerServiceClient)15 SecretVersion (com.google.cloud.secretmanager.v1.SecretVersion)13 Test (org.junit.jupiter.api.Test)12 AccessSecretVersionResponse (com.google.cloud.secretmanager.v1.AccessSecretVersionResponse)7 ByteString (com.google.protobuf.ByteString)3 ApiException (com.google.api.gax.rpc.ApiException)1 AccessSecretVersionRequest (com.google.cloud.secretmanager.v1.AccessSecretVersionRequest)1 DestroySecretVersionRequest (com.google.cloud.secretmanager.v1.DestroySecretVersionRequest)1 DisableSecretVersionRequest (com.google.cloud.secretmanager.v1.DisableSecretVersionRequest)1 EnableSecretVersionRequest (com.google.cloud.secretmanager.v1.EnableSecretVersionRequest)1 SecretName (com.google.cloud.secretmanager.v1.SecretName)1 SecretPayload (com.google.cloud.secretmanager.v1.SecretPayload)1 IOException (java.io.IOException)1 CRC32C (java.util.zip.CRC32C)1 Checksum (java.util.zip.Checksum)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1