a3a30607123f1021b7e7d46f040ca4ea1f2d6505
[aaf/authz.git] / auth / auth-certman / src / main / java / org / onap / aaf / auth / cm / api / API_Artifact.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 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  */
21
22 package org.onap.aaf.auth.cm.api;
23
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26
27 import org.eclipse.jetty.http.HttpStatus;
28 import org.onap.aaf.auth.cm.AAF_CM;
29 import org.onap.aaf.auth.cm.mapper.Mapper.API;
30 import org.onap.aaf.auth.cm.service.Code;
31 import org.onap.aaf.auth.env.AuthzTrans;
32 import org.onap.aaf.auth.layer.Result;
33 import org.onap.aaf.auth.rserv.HttpMethods;
34
35 /**
36  * API Deployment Artifact Apis.. using Redirect for mechanism
37  * 
38  * @author Jonathan
39  *
40  */
41 public class API_Artifact {
42     private static final String GET_ARTIFACTS = "Get Artifacts";
43   private static final String CERT_ARTIFACTS = "/cert/artifacts";
44     /**
45      * Normal Init level APIs
46      * 
47      * @param cmAPI
48      * @throws Exception
49      */
50     public static void init(final AAF_CM cmAPI) throws Exception {
51         cmAPI.route(HttpMethods.POST, CERT_ARTIFACTS, API.ARTIFACTS, new Code(cmAPI,"Create Artifacts") {
52             @Override
53             public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
54                 Result<Void> r = context.createArtifacts(trans, req, resp);
55                 if (r.isOK()) {
56                     resp.setStatus(HttpStatus.CREATED_201);
57                 } else {
58                     context.error(trans,resp,r);
59                 }
60             }
61         });
62
63         /**
64          * Use Query Params to get Artifacts by Machine or MechID
65          */
66         cmAPI.route(HttpMethods.GET, CERT_ARTIFACTS, API.ARTIFACTS, new Code(cmAPI,GET_ARTIFACTS) {
67             @Override
68             public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
69                 Result<Void> r = context.readArtifacts(trans, req, resp);
70                 if (r.isOK()) {
71                     resp.setStatus(HttpStatus.OK_200);
72                 } else {
73                     context.error(trans,resp,r);
74                 }
75             }
76         });
77
78
79         cmAPI.route(HttpMethods.GET, "/cert/artifacts/:mechid/:machine", API.ARTIFACTS, new Code(cmAPI,GET_ARTIFACTS) {
80             @Override
81             public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
82                 
83                 Result<Void> r = context.readArtifacts(trans, resp, pathParam(req,":mechid"), pathParam(req,":machine"));
84                 if (r.isOK()) {
85                     resp.setStatus(HttpStatus.OK_200);
86                 } else {
87                     context.error(trans,resp,r);
88                 }
89             }
90         });
91         
92         
93         cmAPI.route(HttpMethods.PUT, CERT_ARTIFACTS, API.ARTIFACTS, new Code(cmAPI,"Update Artifacts") {
94             @Override
95             public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
96                 Result<Void> r = context.updateArtifacts(trans, req, resp);
97                 if (r.isOK()) {
98                     resp.setStatus(HttpStatus.OK_200);
99                 } else {
100                     context.error(trans,resp,r);
101                 }
102             }
103         });
104
105         cmAPI.route(HttpMethods.DELETE, "/cert/artifacts/:mechid/:machine", API.VOID, new Code(cmAPI,"Delete Artifacts") {
106             @Override
107             public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
108                 Result<Void> r = context.deleteArtifacts(trans, resp, 
109                         pathParam(req, ":mechid"), pathParam(req,":machine"));
110                 if (r.isOK()) {
111                     resp.setStatus(HttpStatus.OK_200);
112                 } else {
113                     context.error(trans,resp,r);
114                 }
115             }
116         });
117         
118
119         cmAPI.route(HttpMethods.DELETE, CERT_ARTIFACTS, API.VOID, new Code(cmAPI,"Delete Artifacts") {
120             @Override
121             public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
122                 Result<Void> r = context.deleteArtifacts(trans, req, resp);
123                 if (r.isOK()) {
124                     resp.setStatus(HttpStatus.OK_200);
125                 } else {
126                     context.error(trans,resp,r);
127                 }
128             }
129         });
130         
131
132     }
133 }