aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/vespa/model/container/xml/CloudDataPlaneFilter.java
blob: a1b569fa1102f9cc0a3c215e7b374bd30e0cf1a2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container.xml;

import com.yahoo.component.ComponentSpecification;
import com.yahoo.component.chain.dependencies.Dependencies;
import com.yahoo.component.chain.model.ChainedComponentModel;
import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.container.bundle.BundleInstantiationSpecification;
import com.yahoo.jdisc.http.filter.security.cloud.config.CloudDataPlaneFilterConfig;
import com.yahoo.security.X509CertificateUtils;
import com.yahoo.vespa.model.container.ApplicationContainerCluster;
import com.yahoo.vespa.model.container.http.Client;
import com.yahoo.vespa.model.container.http.Filter;

import java.util.Collection;
import java.util.List;

class CloudDataPlaneFilter extends Filter implements CloudDataPlaneFilterConfig.Producer {

    private static final String CLASS = "com.yahoo.jdisc.http.filter.security.cloud.CloudDataPlaneFilter";
    private static final String BUNDLE = "jdisc-security-filters";

    private final Collection<Client> clients;
    private final boolean clientsLegacyMode;

    CloudDataPlaneFilter(ApplicationContainerCluster cluster, DeployState state) {
        super(model());
        this.clients = List.copyOf(cluster.getClients());
        this.clientsLegacyMode = cluster.clientsLegacyMode();
    }

    private static ChainedComponentModel model() {
        return new ChainedComponentModel(
                new BundleInstantiationSpecification(
                        new ComponentSpecification(CLASS), null, new ComponentSpecification(BUNDLE)),
                Dependencies.emptyDependencies());
    }

    @Override
    public void getConfig(CloudDataPlaneFilterConfig.Builder builder) {
        if (clientsLegacyMode) {
            builder.legacyMode(true);
        } else {
            var clientsCfg = clients.stream()
                    .filter(c -> !c.certificates().isEmpty())
                    .map(x -> new CloudDataPlaneFilterConfig.Clients.Builder()
                            .id(x.id())
                            .certificates(x.certificates().stream().map(X509CertificateUtils::toPem).toList())
                            .permissions(x.permissions()))
                    .toList();
            builder.clients(clientsCfg).legacyMode(false);
        }
    }


}