feb1dec80277fdf968dcd9190c26e7aa66b50954
[aaf/authz.git] / auth / auth-cmd / src / main / java / org / onap / aaf / auth / cmd / role / ListByPerm.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2018 IBM.
7  * ===========================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END====================================================
20  *
21  */
22
23 package org.onap.aaf.auth.cmd.role;
24
25 import org.onap.aaf.auth.cmd.Cmd;
26 import org.onap.aaf.auth.cmd.Param;
27 import org.onap.aaf.auth.rserv.HttpMethods;
28 import org.onap.aaf.cadi.CadiException;
29 import org.onap.aaf.cadi.LocatorException;
30 import org.onap.aaf.cadi.client.Future;
31 import org.onap.aaf.cadi.client.Rcli;
32 import org.onap.aaf.misc.env.APIException;
33
34 import aaf.v2_0.Roles;
35
36 /**
37  * Return Roles by NS
38  * 
39  * @author Jonathan
40  *
41  */
42 public class ListByPerm extends Cmd {
43     private static final String HEADER = "List Roles by Perm ";
44     
45     public ListByPerm(List parent) {
46         super(parent,"perm", 
47                 new Param("type",true),
48                 new Param("instance", true),
49                 new Param("action", true)); 
50     }
51
52     @Override
53     public int _exec(int idx0, final String ... args) throws CadiException, APIException, LocatorException {
54             int idx = idx0;
55         final String type=args[idx];
56         final String instance=args[++idx];
57         final String action=args[++idx];
58
59         return same(((List)parent).new ListRoles() {
60             @Override
61             public Integer code(Rcli<?> client) throws CadiException, APIException {
62
63                 Future<Roles> fp = client.read(
64                         "/authz/roles/perm/"+type+'/'+instance+'/'+action, 
65                         getDF(Roles.class)
66                         );
67                 return list(fp,client, HEADER+type+'|'+instance+'|'+action);
68             }
69         });
70     }
71     
72     @Override
73     public void detailedHelp(int indent, StringBuilder sb) {
74         detailLine(sb,indent,HEADER);
75         api(sb,indent,HttpMethods.GET,"authz/roles/user/<user>",Roles.class,true);
76     }
77
78
79 }