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.role;
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;
35 import aaf.v2_0.RoleRequest;
42 public class CreateDelete extends Cmd {
43 private static final String ROLE_PATH = "/authz/role";
44 private final static String[] options = {"create","delete"};
45 public CreateDelete(Role parent) {
47 new Param(optionsToString(options),true),
48 new Param("name",true));
52 public int _exec(final int index, final String ... args) throws CadiException, APIException, LocatorException {
53 return same(new Retryable<Integer>() {
55 public Integer code(Rcli<?> client) throws CadiException, APIException {
57 String action = args[idx++];
58 int option = whichOption(options, action);
60 RoleRequest rr = new RoleRequest();
61 rr.setName(args[idx++]);
63 // Set Start/End commands
66 Future<RoleRequest> fp = null;
73 getDF(RoleRequest.class),
79 // Send "Force" if set
80 setQueryParamsOn(client);
82 ROLE_PATH, // +args[idx++],
83 getDF(RoleRequest.class),
88 default: // note, if not an option, whichOption throws Exception
92 boolean rolesSupplied = (args.length>idx);
93 if(fp == null) {// This useless code brought to you by Sonar.
94 throw new CadiException("No call made.");
96 if(fp.get(AAFcli.timeout())) {
99 pw().println("d Role");
101 for(;args.length>idx;++idx ) {
103 if(201!=(rv=((Role)parent)._exec(0,new String[] {"user","add",rr.getName(),args[idx]}))) {
104 rv = 206 /*HttpStatus.PARTIAL_CONTENT_206*/;
106 } catch (LocatorException e) {
107 throw new CadiException(e);
112 if((rv=fp.code())==202) {
115 pw().println(" Accepted, but requires Approvals before actualizing");
126 public void detailedHelp(int indent, StringBuilder sb) {
127 detailLine(sb,indent,"Create OR Delete a Role");
128 detailLine(sb,indent+2,"name - Name of Role to create");
129 api(sb,indent,HttpMethods.POST,"authz/role",RoleRequest.class,true);
130 api(sb,indent,HttpMethods.DELETE,"authz/role",RoleRequest.class,false);