Remove legacy certificate handling
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / servlets / ConfigMgrServlet.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.openecomp.sdc.be.servlets;
21
22 import com.jcabi.aspects.Loggable;
23 import io.swagger.v3.oas.annotations.servers.Server;
24 import io.swagger.v3.oas.annotations.servers.Servers;
25 import io.swagger.v3.oas.annotations.tags.Tag;
26 import io.swagger.v3.oas.annotations.tags.Tags;
27 import javax.servlet.ServletContext;
28 import javax.servlet.http.HttpServletRequest;
29 import javax.ws.rs.Consumes;
30 import javax.ws.rs.GET;
31 import javax.ws.rs.POST;
32 import javax.ws.rs.PUT;
33 import javax.ws.rs.Path;
34 import javax.ws.rs.Produces;
35 import javax.ws.rs.QueryParam;
36 import javax.ws.rs.core.Context;
37 import javax.ws.rs.core.MediaType;
38 import org.openecomp.sdc.be.config.Configuration;
39 import org.openecomp.sdc.be.config.ConfigurationManager;
40 import org.openecomp.sdc.common.api.Constants;
41 import org.openecomp.sdc.common.log.wrappers.Logger;
42 import org.openecomp.sdc.common.servlets.BasicServlet;
43
44 /**
45  * Root resource (exposed at "/" path)
46  */
47 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
48 @Tags({@Tag(name = "SDCE-2 APIs")})
49 @Servers({@Server(url = "/sdc2/rest")})
50 @Path("/configmgr")
51 public class ConfigMgrServlet extends BasicServlet {
52
53     private static final Logger log = Logger.getLogger(ConfigMgrServlet.class);
54
55     @GET
56     @Path("/get")
57     @Produces(MediaType.APPLICATION_JSON)
58     public String getConfig(@Context final HttpServletRequest request, @QueryParam("type") String type) {
59         String result = null;
60         ServletContext context = request.getSession().getServletContext();
61         ConfigurationManager configurationManager = (ConfigurationManager) context.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR);
62         if (type == null || type.equals("configuration")) {
63             Configuration configuration = configurationManager.getConfiguration();
64             if (configuration == null) {
65                 log.warn("Configuration of type {} was not found", Configuration.class);
66             } else {
67                 log.info("The value returned from getConfig is {}", configuration);
68                 result = gson.toJson(configuration);
69             }
70         }
71         return result;
72     }
73
74     @POST
75     @Path("/set1")
76     @Produces(MediaType.TEXT_PLAIN)
77     @Consumes(MediaType.APPLICATION_JSON)
78     public String setConfig1(@Context final HttpServletRequest request, Configuration configuration) {
79         log.debug("{}", configuration);
80         return "ok";
81     }
82
83     @POST
84     @Path("/set2")
85     @Produces(MediaType.TEXT_PLAIN)
86     @Consumes(MediaType.APPLICATION_JSON)
87     public void setConfig2(@Context final HttpServletRequest request, Configuration configuration) {
88         log.debug("{}", configuration);
89     }
90
91     @PUT
92     @Path("/setput1")
93     @Produces(MediaType.TEXT_PLAIN)
94     @Consumes(MediaType.APPLICATION_JSON)
95     public String setConfig3(@Context final HttpServletRequest request, Configuration configuration) {
96         log.debug("{}", configuration);
97         return "ok";
98     }
99
100     @PUT
101     @Path("/setput2")
102     @Produces(MediaType.TEXT_PLAIN)
103     @Consumes(MediaType.APPLICATION_JSON)
104     public void setConfig4(@Context final HttpServletRequest request, Configuration configuration) {
105         log.debug("{}", configuration);
106     }
107 }