Search in sources :

Example 16 with Secret

use of com.google.cloud.secretmanager.v1beta1.Secret in project java-secretmanager by googleapis.

the class UpdateSecret method updateSecret.

// Update an existing secret.
public void updateSecret(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);
        // Build the updated secret.
        Secret secret = Secret.newBuilder().setName(secretName.toString()).putLabels("secretmanager", "rocks").build();
        // Build the field mask.
        FieldMask fieldMask = FieldMaskUtil.fromString("labels");
        // Create the secret.
        Secret updatedSecret = client.updateSecret(secret, fieldMask);
        System.out.printf("Updated secret %s\n", updatedSecret.getName());
    }
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) Secret(com.google.cloud.secretmanager.v1.Secret) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient) FieldMask(com.google.protobuf.FieldMask)

Example 17 with Secret

use of com.google.cloud.secretmanager.v1beta1.Secret in project nomulus by google.

the class SecretManagerClientImpl method createSecret.

@Override
public void createSecret(String secretId) {
    checkNotNull(secretId, "secretId");
    Secret secretSettings = Secret.newBuilder().setReplication(defaultReplicationPolicy()).build();
    callSecretManager(() -> csmClient.createSecret(ProjectName.of(project), secretId, secretSettings));
}
Also used : Secret(com.google.cloud.secretmanager.v1.Secret)

Example 18 with Secret

use of com.google.cloud.secretmanager.v1beta1.Secret in project native-image-support-java by GoogleCloudPlatform.

the class SecretManagerSampleApplication 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 19 with Secret

use of com.google.cloud.secretmanager.v1beta1.Secret in project native-image-support-java by GoogleCloudPlatform.

the class SecretManagerSampleApplication method createSecret.

static void createSecret(SecretManagerServiceClient client, String projectId, String secretId) {
    ProjectName projectName = ProjectName.of(projectId);
    Secret secret = Secret.newBuilder().setReplication(Replication.newBuilder().setAutomatic(Replication.Automatic.newBuilder().build()).build()).build();
    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 20 with Secret

use of com.google.cloud.secretmanager.v1beta1.Secret in project spring-cloud-gcp by spring-cloud.

the class SecretManagerTemplateTests method verifyCreateSecretRequest.

private void verifyCreateSecretRequest(String secretId, String projectId) {
    Secret secretToAdd = Secret.newBuilder().setReplication(Replication.newBuilder().setAutomatic(Replication.Automatic.newBuilder()).build()).build();
    CreateSecretRequest createSecretRequest = CreateSecretRequest.newBuilder().setParent("projects/" + projectId).setSecretId(secretId).setSecret(secretToAdd).build();
    verify(this.client).createSecret(createSecretRequest);
}
Also used : Secret(com.google.cloud.secretmanager.v1.Secret) CreateSecretRequest(com.google.cloud.secretmanager.v1.CreateSecretRequest)

Aggregations

Secret (com.google.cloud.secretmanager.v1.Secret)21 ProjectName (com.google.cloud.secretmanager.v1.ProjectName)11 SecretManagerServiceClient (com.google.cloud.secretmanager.v1.SecretManagerServiceClient)11 Test (org.junit.Test)6 SecretName (com.google.cloud.secretmanager.v1.SecretName)5 ByteString (com.google.protobuf.ByteString)5 CreateSecretRequest (com.google.cloud.secretmanager.v1.CreateSecretRequest)4 Secret (com.google.cloud.secretmanager.v1beta1.Secret)3 AbstractMessage (com.google.protobuf.AbstractMessage)3 FieldMask (com.google.protobuf.FieldMask)3 Secret (com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret)3 Test (org.junit.jupiter.api.Test)3 AccessSecretVersionResponse (com.google.cloud.secretmanager.v1.AccessSecretVersionResponse)2 ListSecretsRequest (com.google.cloud.secretmanager.v1.ListSecretsRequest)2 ListSecretsPagedResponse (com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretsPagedResponse)2 SecretPayload (com.google.cloud.secretmanager.v1.SecretPayload)2 SecretVersion (com.google.cloud.secretmanager.v1.SecretVersion)2 ListSecretsPagedResponse (com.google.cloud.secretmanager.v1beta1.SecretManagerServiceClient.ListSecretsPagedResponse)2 Configuration (com.marcnuri.yakc.config.Configuration)2 Node (com.marcnuri.yakc.model.io.k8s.api.core.v1.Node)2