Search in sources :

Example 71 with ProjectName

use of com.google.bigtable.repackaged.com.google.monitoring.v3.ProjectName in project java-secretmanager by googleapis.

the class NativeImageSecretManagerSample method createSecret.

static void createSecret(SecretManagerServiceClient client, String projectId, String secretId) {
    Secret secret = Secret.newBuilder().setReplication(Replication.newBuilder().setAutomatic(Replication.Automatic.newBuilder().build()).build()).build();
    ProjectName projectName = ProjectName.of(projectId);
    Secret createdSecret = client.createSecret(projectName, secretId, secret);
    System.out.println("Created secret: " + createdSecret.getName());
}
Also used : Secret(com.google.cloud.secretmanager.v1.Secret) ProjectName(com.google.cloud.secretmanager.v1.ProjectName)

Example 72 with ProjectName

use of com.google.bigtable.repackaged.com.google.monitoring.v3.ProjectName in project java-secretmanager by googleapis.

the class NativeImageSecretManagerSample method hasSecret.

static boolean hasSecret(SecretManagerServiceClient client, String projectId, String secretId) {
    ProjectName projectName = ProjectName.of(projectId);
    ListSecretsPagedResponse pagedResponse = client.listSecrets(projectName);
    for (Secret secret : pagedResponse.iterateAll()) {
        String otherSecretId = extractSecretId(secret);
        if (secretId.equals(otherSecretId)) {
            return true;
        }
    }
    return false;
}
Also used : Secret(com.google.cloud.secretmanager.v1.Secret) ProjectName(com.google.cloud.secretmanager.v1.ProjectName) ListSecretsPagedResponse(com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretsPagedResponse) ByteString(com.google.protobuf.ByteString)

Example 73 with ProjectName

use of com.google.bigtable.repackaged.com.google.monitoring.v3.ProjectName in project java-secretmanager by googleapis.

the class CreateSecret method createSecret.

// Add a new version to the existing secret.
public void createSecret(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 parent name from the project.
        ProjectName projectName = ProjectName.of(projectId);
        // Build the secret to create.
        Secret secret = Secret.newBuilder().setReplication(Replication.newBuilder().setAutomatic(Replication.Automatic.newBuilder().build()).build()).build();
        // Create the secret.
        Secret createdSecret = client.createSecret(projectName, secretId, secret);
        System.out.printf("Created secret %s\n", createdSecret.getName());
    }
}
Also used : Secret(com.google.cloud.secretmanager.v1.Secret) ProjectName(com.google.cloud.secretmanager.v1.ProjectName) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient)

Example 74 with ProjectName

use of com.google.bigtable.repackaged.com.google.monitoring.v3.ProjectName in project java-secretmanager by googleapis.

the class Quickstart method quickstart.

public void quickstart(String projectId, String secretId) throws Exception {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
        // Build the parent name from the project.
        ProjectName projectName = ProjectName.of(projectId);
        // Create the parent secret.
        Secret secret = Secret.newBuilder().setReplication(Replication.newBuilder().setAutomatic(Replication.Automatic.newBuilder().build()).build()).build();
        Secret createdSecret = client.createSecret(projectName, secretId, secret);
        // Add a secret version.
        SecretPayload payload = SecretPayload.newBuilder().setData(ByteString.copyFromUtf8("hello world!")).build();
        SecretVersion addedVersion = client.addSecretVersion(createdSecret.getName(), payload);
        // Access the secret version.
        AccessSecretVersionResponse response = client.accessSecretVersion(addedVersion.getName());
        // Print the secret payload.
        // 
        // WARNING: Do not print the secret in a production environment - this
        // snippet is showing how to access the secret material.
        String data = response.getPayload().getData().toStringUtf8();
        System.out.printf("Plaintext: %s\n", data);
    }
}
Also used : Secret(com.google.cloud.secretmanager.v1.Secret) SecretVersion(com.google.cloud.secretmanager.v1.SecretVersion) ProjectName(com.google.cloud.secretmanager.v1.ProjectName) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient) ByteString(com.google.protobuf.ByteString) AccessSecretVersionResponse(com.google.cloud.secretmanager.v1.AccessSecretVersionResponse) SecretPayload(com.google.cloud.secretmanager.v1.SecretPayload)

Example 75 with ProjectName

use of com.google.bigtable.repackaged.com.google.monitoring.v3.ProjectName in project java-secretmanager by googleapis.

the class ListSecrets method listSecrets.

// List all secrets for a project
public void listSecrets(String projectId) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
        // Build the parent name.
        ProjectName projectName = ProjectName.of(projectId);
        // Get all secrets.
        ListSecretsPagedResponse pagedResponse = client.listSecrets(projectName);
        // List all secrets.
        pagedResponse.iterateAll().forEach(secret -> {
            System.out.printf("Secret %s\n", secret.getName());
        });
    }
}
Also used : ProjectName(com.google.cloud.secretmanager.v1.ProjectName) ListSecretsPagedResponse(com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretsPagedResponse) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient)

Aggregations

Test (org.junit.Test)146 StatusRuntimeException (io.grpc.StatusRuntimeException)73 ProjectName (com.google.monitoring.v3.ProjectName)62 AbstractMessage (com.google.protobuf.AbstractMessage)60 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)58 ProjectName (com.google.pubsub.v1.ProjectName)30 ArrayList (java.util.ArrayList)29 ProjectName (com.google.privacy.dlp.v2.ProjectName)22 ByteString (com.google.protobuf.ByteString)18 DataTransferServiceClient (com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient)17 ProjectName (com.google.cloud.bigquery.datatransfer.v1.ProjectName)17 IOException (java.io.IOException)17 CreateTransferConfigRequest (com.google.cloud.bigquery.datatransfer.v1.CreateTransferConfigRequest)16 TransferConfig (com.google.cloud.bigquery.datatransfer.v1.TransferConfig)16 ProjectName (com.google.cloud.secretmanager.v1.ProjectName)16 ProjectName (com.google.containeranalysis.v1beta1.ProjectName)16 ApiException (com.google.api.gax.rpc.ApiException)15 MetricServiceClient (com.google.cloud.monitoring.v3.MetricServiceClient)15 TimeSeries (com.google.monitoring.v3.TimeSeries)15 ProjectName (com.google.logging.v2.ProjectName)14