ab717eb0f818a98829a7e598e4854f644e496b39
[aaf/authz.git] / authz-cmd / src / main / java / com / att / cmd / ns / Delete.java
1 /*******************************************************************************\r
2  * ============LICENSE_START====================================================\r
3  * * org.onap.aaf\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * * ===========================================================================\r
7  * * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * * you may not use this file except in compliance with the License.\r
9  * * You may obtain a copy of the License at\r
10  * * \r
11  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * * \r
13  *  * Unless required by applicable law or agreed to in writing, software\r
14  * * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * * See the License for the specific language governing permissions and\r
17  * * limitations under the License.\r
18  * * ============LICENSE_END====================================================\r
19  * *\r
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
21  * *\r
22  ******************************************************************************/\r
23 package com.att.cmd.ns;\r
24 \r
25 import com.att.cadi.CadiException;\r
26 import com.att.cadi.LocatorException;\r
27 import com.att.cadi.client.Future;\r
28 import com.att.cadi.client.Rcli;\r
29 import com.att.cadi.client.Retryable;\r
30 import com.att.cmd.AAFcli;\r
31 import com.att.cmd.Cmd;\r
32 import com.att.cmd.Param;\r
33 import com.att.cssa.rserv.HttpMethods;\r
34 import com.att.inno.env.APIException;\r
35 \r
36 /**\r
37  * p\r
38  *\r
39  */\r
40 public class Delete extends Cmd {\r
41         public Delete(NS parent) {\r
42                 super(parent,"delete", \r
43                                 new Param("name",true)); \r
44         }\r
45 \r
46         @Override\r
47         public int _exec(final int idx, final String ... args) throws CadiException, APIException, LocatorException {\r
48                 return same(new Retryable<Integer>() {\r
49                         @Override\r
50                         public Integer code(Rcli<?> client) throws CadiException, APIException {\r
51                                 int index = idx;\r
52                                 StringBuilder path = new StringBuilder("/authz/ns/");\r
53                                 path.append(args[index++]);\r
54                                 \r
55                                 // Send "Force" if set\r
56                                 setQueryParamsOn(client);\r
57                                 Future<Void> fp = client.delete(path.toString(),Void.class);\r
58                                 \r
59                                 if(fp.get(AAFcli.timeout())) {\r
60                                         pw().println("Deleted Namespace");\r
61                                 } else {\r
62                                         error(fp);\r
63                                 }\r
64                                 return fp.code();\r
65                         }\r
66                 });\r
67         }\r
68 \r
69         @Override\r
70         public void detailedHelp(int _indent, StringBuilder sb) {\r
71                 int indent = _indent;\r
72                 detailLine(sb,indent,"Delete a Namespace");\r
73                 indent+=4;\r
74                 detailLine(sb,indent,"Namespaces cannot normally be deleted when there are still credentials,");\r
75                 detailLine(sb,indent,"permissions or roles associated with them. These can be deleted");\r
76                 detailLine(sb,indent,"automatically by setting \"force\" property.");\r
77                 detailLine(sb,indent,"i.e. set force=true or just starting with \"force\"");\r
78                 detailLine(sb,indent," (note force is unset after first use)");\r
79                 sb.append('\n');\r
80                 detailLine(sb,indent,"If \"set force=move\" is set, credentials are deleted, but ");\r
81                 detailLine(sb,indent,"Permissions and Roles are assigned to the Parent Namespace instead of");\r
82                 detailLine(sb,indent,"being deleted.  Similarly, Namespaces can be created even though there");\r
83                 detailLine(sb,indent,"are Roles/Perms whose type starts with the requested sub-namespace.");\r
84                 detailLine(sb,indent,"They are simply reassigned to the Child Namespace");\r
85                 indent-=4;\r
86                 api(sb,indent,HttpMethods.DELETE,"authz/ns/<ns>[?force=true]",Void.class,true);\r
87         }\r
88 \r
89 }\r