aboutsummaryrefslogtreecommitdiffstats
path: root/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpListNamedConfigsHandler.java
blob: e5a517bb224e3482a020d6135797deee8350eec2 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.http.v2;

import java.util.Optional;
import java.util.Set;

import com.yahoo.component.annotation.Inject;
import com.yahoo.config.provision.Zone;
import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.container.jdisc.HttpResponse;
import com.yahoo.vespa.config.ConfigKey;
import com.yahoo.vespa.config.server.RequestHandler;
import com.yahoo.vespa.config.server.http.v2.request.HttpConfigRequests;
import com.yahoo.vespa.config.server.http.v2.request.HttpListConfigsRequest;
import com.yahoo.vespa.config.server.tenant.TenantRepository;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.vespa.config.server.http.HttpConfigRequest;
import com.yahoo.vespa.config.server.http.HttpHandler;

/**
 * Handler for a list named configs operation. Lists all configs in model for a given application and tenant, config name and optionally config id.
 *
 * @author vegardh
 * @since 5.3
 */
public class HttpListNamedConfigsHandler extends HttpHandler {

    private final TenantRepository tenantRepository;
    private final Zone zone;
    
    @Inject
    public HttpListNamedConfigsHandler(HttpHandler.Context ctx,
                                       TenantRepository tenantRepository, Zone zone)
    {
        super(ctx);
        this.tenantRepository = tenantRepository;
        this.zone = zone;
    }
    
    @Override
    public HttpResponse handleGET(HttpRequest req) {
        HttpListConfigsRequest listReq = HttpListConfigsRequest.createFromNamedListRequest(req);
        RequestHandler requestHandler = HttpConfigRequests.getRequestHandler(tenantRepository, listReq);
        ApplicationId appId = listReq.getApplicationId();
        HttpConfigRequest.validateRequestKey(listReq.getKey(), requestHandler, appId);
        Set<ConfigKey<?>> configs = requestHandler.listNamedConfigs(appId, Optional.empty(), listReq.getKey(), listReq.isRecursive());
        String urlBase = HttpListConfigsHandler.getUrlBase(req, listReq, appId, zone);
        Set<ConfigKey<?>> allConfigs = requestHandler.allConfigsProduced(appId, Optional.empty());
        return new HttpListConfigsHandler.ListConfigsResponse(configs, allConfigs, urlBase, listReq.isRecursive());
    }
}