Search in sources :

Example 6 with Secret

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret 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 7 with Secret

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret 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 8 with Secret

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret 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 9 with Secret

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret in project java-secretmanager by googleapis.

the class ITSystemTest method listSecretsTest.

@Test
public void listSecretsTest() {
    ListSecretsRequest request = ListSecretsRequest.newBuilder().setParent(PROJECT_NAME).build();
    for (Secret actualSecret : client.listSecrets(request).iterateAll()) {
        if (secret.getName().equals(actualSecret.getName())) {
            assertEquals(secret.getReplication(), actualSecret.getReplication());
            assertEquals(secret.getCreateTime(), actualSecret.getCreateTime());
        }
    }
}
Also used : Secret(com.google.cloud.secretmanager.v1beta1.Secret) ListSecretsRequest(com.google.cloud.secretmanager.v1beta1.ListSecretsRequest) Test(org.junit.Test)

Example 10 with Secret

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret in project java-secretmanager by googleapis.

the class ITSystemTest method getSecretTest.

@Test
public void getSecretTest() {
    GetSecretRequest request = GetSecretRequest.newBuilder().setName(formattedSecretName).build();
    Secret actualSecret = client.getSecret(request);
    assertEquals(secret.getName(), actualSecret.getName());
    assertEquals(secret.getReplication(), actualSecret.getReplication());
    assertEquals(secret.getCreateTime(), actualSecret.getCreateTime());
}
Also used : Secret(com.google.cloud.secretmanager.v1beta1.Secret) GetSecretRequest(com.google.cloud.secretmanager.v1beta1.GetSecretRequest) Test(org.junit.Test)

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 SecretName (com.google.cloud.secretmanager.v1.SecretName)5 CreateSecretRequest (com.google.cloud.secretmanager.v1.CreateSecretRequest)4 ByteString (com.google.protobuf.ByteString)4 Secret (com.google.cloud.secretmanager.v1beta1.Secret)3 FieldMask (com.google.protobuf.FieldMask)3 Secret (com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret)3 Test (org.junit.Test)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 Configuration (com.marcnuri.yakc.config.Configuration)2 Node (com.marcnuri.yakc.model.io.k8s.api.core.v1.Node)2 ArrayList (java.util.ArrayList)2 AddSecretVersionRequest (com.google.cloud.secretmanager.v1beta1.AddSecretVersionRequest)1