Search in sources :

Example 21 with Secret

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret in project spring-cloud-config by spring-cloud.

the class GoogleSecretManagerEnvironmentRepository method getSecrets.

/**
 * @param application the application name
 * @param profile the profile name
 * @return the properties to add into the environment
 */
private Map<?, ?> getSecrets(String application, String profile) {
    Map<String, String> result = new HashMap<>();
    String prefix = configProvider.getValue(HttpHeaderGoogleConfigProvider.PREFIX_HEADER, false);
    for (Secret secret : accessStrategy.getSecrets()) {
        if (secret.getLabelsOrDefault(applicationLabel, "application").equalsIgnoreCase(application) && secret.getLabelsOrDefault(profileLabel, "profile").equalsIgnoreCase(profile)) {
            result.put(accessStrategy.getSecretName(secret), accessStrategy.getSecretValue(secret, new GoogleSecretComparatorByVersion()));
        } else if (StringUtils.isNotBlank(prefix) && accessStrategy.getSecretName(secret).startsWith(prefix)) {
            result.put(StringUtils.removeStart(accessStrategy.getSecretName(secret), prefix), accessStrategy.getSecretValue(secret, new GoogleSecretComparatorByVersion()));
        }
    }
    return result;
}
Also used : Secret(com.google.cloud.secretmanager.v1.Secret) GoogleSecretComparatorByVersion(org.springframework.cloud.config.server.environment.secretmanager.GoogleSecretComparatorByVersion) HashMap(java.util.HashMap)

Example 22 with Secret

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret in project spring-cloud-gcp by GoogleCloudPlatform.

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)

Example 23 with Secret

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret in project spring-cloud-gcp by GoogleCloudPlatform.

the class SecretManagerTemplate method createSecretInternal.

/**
 * Creates a new secret for the GCP Project.
 *
 * <p>Note that the {@link Secret} object does not contain the secret payload. You must create
 * versions of the secret which stores the payload of the secret.
 */
private void createSecretInternal(String secretId, String projectId) {
    ProjectName projectName = ProjectName.of(projectId);
    Secret secret = Secret.newBuilder().setReplication(Replication.newBuilder().setAutomatic(Replication.Automatic.getDefaultInstance())).build();
    CreateSecretRequest request = CreateSecretRequest.newBuilder().setParent(projectName.toString()).setSecretId(secretId).setSecret(secret).build();
    this.secretManagerServiceClient.createSecret(request);
}
Also used : Secret(com.google.cloud.secretmanager.v1.Secret) ProjectName(com.google.cloud.secretmanager.v1.ProjectName) CreateSecretRequest(com.google.cloud.secretmanager.v1.CreateSecretRequest)

Example 24 with Secret

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

the class ITSystemTest method setUp.

@BeforeClass
public static void setUp() throws IOException {
    /* create secret */
    client = SecretManagerServiceClient.create();
    Replication createReplication = Replication.newBuilder().setUserManaged(Replication.UserManaged.newBuilder().addReplicas(Replication.UserManaged.Replica.newBuilder().setLocation(LOCATION).build())).build();
    Secret createSecret = Secret.newBuilder().setReplication(createReplication).build();
    CreateSecretRequest secretRequest = CreateSecretRequest.newBuilder().setParent(PROJECT_NAME).setSecretId(SECRET_ID).setSecret(createSecret).build();
    secret = client.createSecret(secretRequest);
    secretId = getName(secret.getName());
    formattedSecretName = SecretName.of(PROJECT_ID, secretId).toString();
    /* create secret version */
    AddSecretVersionRequest versionRequest = AddSecretVersionRequest.newBuilder().setParent(formattedSecretName).setPayload(PAYLOAD).build();
    secretVersion = client.addSecretVersion(versionRequest);
    secretVersionId = getName(secretVersion.getName());
    formattedSecretVersion = SecretVersionName.of(PROJECT_ID, secretId, secretVersionId).toString();
}
Also used : Secret(com.google.cloud.secretmanager.v1beta1.Secret) AddSecretVersionRequest(com.google.cloud.secretmanager.v1beta1.AddSecretVersionRequest) CreateSecretRequest(com.google.cloud.secretmanager.v1beta1.CreateSecretRequest) Replication(com.google.cloud.secretmanager.v1beta1.Replication) BeforeClass(org.junit.BeforeClass)

Example 25 with Secret

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

the class GetSecret method getSecret.

// Get an existing secret.
public 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)

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