2 * ============LICENSE_START====================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
22 package org.onap.aaf.auth.cmd.perm;
25 import java.io.UnsupportedEncodingException;
26 import java.net.URLEncoder;
28 import org.onap.aaf.auth.cmd.AAFcli;
29 import org.onap.aaf.auth.cmd.Cmd;
30 import org.onap.aaf.auth.cmd.Param;
31 import org.onap.aaf.auth.rserv.HttpMethods;
32 import org.onap.aaf.cadi.CadiException;
33 import org.onap.aaf.cadi.LocatorException;
34 import org.onap.aaf.cadi.client.Future;
35 import org.onap.aaf.cadi.client.Rcli;
36 import org.onap.aaf.cadi.client.Retryable;
37 import org.onap.aaf.cadi.config.Config;
38 import org.onap.aaf.misc.env.APIException;
40 import aaf.v2_0.PermRequest;
42 public class Rename extends Cmd {
43 public Rename(Perm parent) {
44 super(parent,"rename",
45 new Param("type",true),
46 new Param("instance",true),
47 new Param("action", true),
48 new Param("new type",true),
49 new Param("new instance",true),
50 new Param("new action", true)
55 public int _exec(final int index, final String ... args) throws CadiException, APIException, LocatorException {
56 return same(new Retryable<Integer>() {
58 public Integer code(Rcli<?> client) throws CadiException, APIException {
60 String origType = args[idx++];
61 String origInstance = args[idx++];
62 String origAction = args[idx++];
64 //Create new permission
65 PermRequest pr = new PermRequest();
66 pr.setType(args[idx++]);
67 pr.setInstance(args[idx++]);
68 pr.setAction(args[idx]);
70 // Set Start/End commands
73 Future<PermRequest> fp = client.update(
76 URLEncoder.encode(origInstance,Config.UTF_8) + '/' +
78 getDF(PermRequest.class),
82 if (fp.get(AAFcli.timeout())) {
84 pw().println("Updated Permission");
88 pw().println("Permission Update Accepted, but requires Approvals before actualizing");
94 } catch (UnsupportedEncodingException e) {
95 throw new CadiException(e);
103 public void detailedHelp(int indent, StringBuilder sb) {
104 detailLine(sb,indent,"Rename a Permission from:");
105 detailLine(sb,indent+2,"<type> <instance> <action>");
106 detailLine(sb,indent,"to:");
107 detailLine(sb,indent+2,"<new type> <new instance> <new action>");
109 detailLine(sb,indent,"Namespace must be the same in <type> and <new type>");
110 detailLine(sb,indent+4,"see Create for definitions of type,instance and action");
111 api(sb,indent,HttpMethods.PUT,"authz/perm/<type>/<instance>/<action>",PermRequest.class,true);