1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\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
11 * * http://www.apache.org/licenses/LICENSE-2.0
\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
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.cmd.role;
\r
25 import org.onap.aaf.cmd.AAFcli;
\r
26 import org.onap.aaf.cmd.Cmd;
\r
27 import org.onap.aaf.cmd.Param;
\r
28 import org.onap.aaf.cssa.rserv.HttpMethods;
\r
30 import com.att.aft.dme2.internal.jetty.http.HttpStatus;
\r
31 import org.onap.aaf.cadi.CadiException;
\r
32 import org.onap.aaf.cadi.LocatorException;
\r
33 import org.onap.aaf.cadi.client.Future;
\r
34 import org.onap.aaf.cadi.client.Rcli;
\r
35 import org.onap.aaf.cadi.client.Retryable;
\r
36 import org.onap.aaf.inno.env.APIException;
\r
38 import aaf.v2_0.RoleRequest;
\r
44 public class CreateDelete extends Cmd {
\r
45 private static final String ROLE_PATH = "/authz/role";
\r
46 private final static String[] options = {"create","delete"};
\r
47 public CreateDelete(Role parent) {
\r
49 new Param(optionsToString(options),true),
\r
50 new Param("name",true));
\r
54 public int _exec(final int index, final String ... args) throws CadiException, APIException, LocatorException {
\r
55 return same(new Retryable<Integer>() {
\r
57 public Integer code(Rcli<?> client) throws CadiException, APIException {
\r
59 String action = args[idx++];
\r
60 int option = whichOption(options, action);
\r
62 RoleRequest rr = new RoleRequest();
\r
63 rr.setName(args[idx++]);
\r
65 // Set Start/End commands
\r
68 Future<RoleRequest> fp = null;
\r
75 getDF(RoleRequest.class),
\r
81 // Send "Force" if set
\r
82 setQueryParamsOn(client);
\r
84 ROLE_PATH, // +args[idx++],
\r
85 getDF(RoleRequest.class),
\r
90 default: // note, if not an option, whichOption throws Exception
\r
94 boolean rolesSupplied = (args.length>idx);
\r
95 if(fp.get(AAFcli.timeout())) {
\r
98 pw().println("d Role");
\r
100 for(;args.length>idx;++idx ) {
\r
102 if(201!=(rv=((Role)parent)._exec(0,new String[] {"user","add",rr.getName(),args[idx]}))) {
\r
103 rv = HttpStatus.PARTIAL_CONTENT_206;
\r
105 } catch (LocatorException e) {
\r
106 throw new CadiException(e);
\r
111 if((rv=fp.code())==202) {
\r
112 pw().print("Role ");
\r
114 pw().println(" Accepted, but requires Approvals before actualizing");
\r
125 public void detailedHelp(int indent, StringBuilder sb) {
\r
126 detailLine(sb,indent,"Create OR Delete a Role");
\r
127 detailLine(sb,indent+2,"name - Name of Role to create");
\r
128 api(sb,indent,HttpMethods.POST,"authz/role",RoleRequest.class,true);
\r
129 api(sb,indent,HttpMethods.DELETE,"authz/role",RoleRequest.class,false);
\r