7da6c26b09375728c8251ae471f71378908d91e1
[aaf/authz.git] / auth / auth-cmd / src / main / java / org / onap / aaf / auth / cmd / ns / Delete.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.cmd.ns;
23
24 import org.onap.aaf.auth.cmd.AAFcli;
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.cadi.client.Retryable;
33 import org.onap.aaf.misc.env.APIException;
34
35 /**
36  * p
37  * @author Jonathan
38  *
39  */
40 public class Delete extends Cmd {
41     public Delete(NS parent) {
42         super(parent,"delete", 
43                 new Param("ns-name",true)); 
44     }
45
46     @Override
47     public int _exec(final int idx, final String ... args) throws CadiException, APIException, LocatorException {
48         return same(new Retryable<Integer>() {
49             @Override
50             public Integer code(Rcli<?> client) throws CadiException, APIException {
51                 int index = idx;
52                 StringBuilder path = new StringBuilder("/authz/ns/");
53                 path.append(args[index++]);
54                 
55                 // Send "Force" if set
56                 setQueryParamsOn(client);
57                 Future<Void> fp = client.delete(path.toString(),Void.class);
58                 
59                 if (fp.get(AAFcli.timeout())) {
60                     pw().println("Deleted Namespace");
61                 } else {
62                     error(fp);
63                 }
64                 return fp.code();
65             }
66         });
67     }
68
69     @Override
70     public void detailedHelp(int _indent, StringBuilder sb) {
71             int indent = _indent;
72         detailLine(sb,indent,"Delete a Namespace");
73         indent+=4;
74         detailLine(sb,indent,"Namespaces cannot normally be deleted when there are still credentials,");
75         detailLine(sb,indent,"permissions or roles associated with them. These can be deleted");
76         detailLine(sb,indent,"automatically by setting \"force\" property.");
77         detailLine(sb,indent,"i.e. set force=true or just starting with \"force\"");
78         detailLine(sb,indent," (note force is unset after first use)");
79         sb.append('\n');
80         detailLine(sb,indent,"If \"set force=move\" is set, credentials are deleted, but ");
81         detailLine(sb,indent,"Permissions and Roles are assigned to the Parent Namespace instead of");
82         detailLine(sb,indent,"being deleted.  Similarly, Namespaces can be created even though there");
83         detailLine(sb,indent,"are Roles/Perms whose type starts with the requested sub-namespace.");
84         detailLine(sb,indent,"They are simply reassigned to the Child Namespace");
85         indent-=4;
86         api(sb,indent,HttpMethods.DELETE,"authz/ns/<ns>[?force=true]",Void.class,true);
87     }
88
89 }