Search in sources :

Example 41 with SecretName

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

Example 42 with SecretName

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();
}
Also used : AccessSecretVersionResponse(com.google.cloud.secretmanager.v1.AccessSecretVersionResponse) EventListener(io.micronaut.runtime.event.annotation.EventListener)

Example 43 with SecretName

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();
}
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 44 with SecretName

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

Example 45 with SecretName

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

Aggregations

SecretName (com.google.cloud.secretmanager.v1.SecretName)53 SecretManagerServiceClient (com.google.cloud.secretmanager.v1.SecretManagerServiceClient)23 Test (org.junit.Test)22 DeleteSecretRequest (com.google.cloud.secretmanager.v1.DeleteSecretRequest)8 SecretVersion (com.google.cloud.secretmanager.v1.SecretVersion)6 Secret (com.google.cloud.secretmanager.v1.Secret)5 SecretPayload (com.google.cloud.secretmanager.v1.SecretPayload)5 AddSecretVersionRequest (com.google.cloud.secretmanager.v1.AddSecretVersionRequest)4 ListSecretVersionsPagedResponse (com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretVersionsPagedResponse)4 Binding (com.google.iam.v1.Binding)4 Policy (com.google.iam.v1.Policy)4 FieldMask (com.google.protobuf.FieldMask)3 AfterClass (org.junit.AfterClass)3 ListSecretVersionsRequest (com.google.cloud.secretmanager.v1.ListSecretVersionsRequest)2 AccessSecretVersionResponse (com.google.cloud.secretmanager.v1.AccessSecretVersionResponse)1 SecretVersionName (com.google.cloud.secretmanager.v1.SecretVersionName)1 AbstractMessage (com.google.protobuf.AbstractMessage)1 ByteString (com.google.protobuf.ByteString)1 EventListener (io.micronaut.runtime.event.annotation.EventListener)1 ArrayList (java.util.ArrayList)1