aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/vespa/model/container/xml/CloudSecretStore.java
blob: f917ad5aeb01e818155c5a1e1ee978ca56d2f866 (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
57
58
59
60
61
62
63
64
// 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.container.bundle.BundleInstantiationSpecification;
import com.yahoo.container.jdisc.secretstore.SecretStoreConfig;
import com.yahoo.osgi.provider.model.ComponentModel;
import com.yahoo.vespa.model.container.component.SimpleComponent;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author olaa
 */
public class CloudSecretStore extends SimpleComponent implements SecretStoreConfig.Producer {

    private static final String CLASS = "com.yahoo.jdisc.cloud.aws.AwsParameterStore";
    private static final String BUNDLE = "jdisc-cloud-aws";

    private final List<StoreConfig> configList;

    public CloudSecretStore() {
        super(new ComponentModel(BundleInstantiationSpecification.fromStrings(CLASS, CLASS, BUNDLE)));
        configList = new ArrayList<>();
    }

    public void addConfig(String name, String region, String awsId, String role, String externalId) {
        configList.add(
                new StoreConfig(name, region, awsId, role, externalId)
        );
    }

    @Override
    public void getConfig(SecretStoreConfig.Builder builder) {
        builder.awsParameterStores(
                configList.stream()
                .map(config -> new SecretStoreConfig.AwsParameterStores.Builder()
                        .name(config.name)
                        .region(config.region)
                        .awsId(config.awsId)
                        .role(config.role)
                        .externalId(config.externalId)
                ).toList()
        );
    }

    class StoreConfig {
        private final String name;
        private final String region;
        private final String awsId;
        private final String role;
        private final String externalId;

        public StoreConfig(String name, String region, String awsId, String role, String externalId) {
            this.name = name;
            this.region = region;
            this.awsId = awsId;
            this.role = role;
            this.externalId = externalId;
        }

    }
}