2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
7 * Modifications Copyright (C) 2018 IBM.
8 * ===========================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END====================================================
24 package org.onap.aaf.auth.cmd.role;
26 import org.onap.aaf.auth.cmd.AAFcli;
27 import org.onap.aaf.auth.cmd.Cmd;
28 import org.onap.aaf.auth.cmd.Param;
29 import org.onap.aaf.auth.rserv.HttpMethods;
30 import org.onap.aaf.cadi.CadiException;
31 import org.onap.aaf.cadi.LocatorException;
32 import org.onap.aaf.cadi.client.Future;
33 import org.onap.aaf.cadi.client.Rcli;
34 import org.onap.aaf.cadi.client.Retryable;
35 import org.onap.aaf.misc.env.APIException;
37 import aaf.v2_0.RoleRequest;
44 public class CreateDelete extends Cmd {
45 private static final String ROLE_PATH = "/authz/role";
46 private static final String[] options = {"create","delete"};
47 public CreateDelete(Role parent) {
49 new Param(optionsToString(options),true),
50 new Param("name",true));
54 public int _exec(final int index, final String ... args) throws CadiException, APIException, LocatorException {
55 return same(new Retryable<Integer>() {
57 public Integer code(Rcli<?> client) throws CadiException, APIException {
59 String action = args[idx++];
60 int option = whichOption(options, action);
62 RoleRequest rr = new RoleRequest();
63 rr.setName(args[idx++]);
65 // Set Start/End commands
68 Future<RoleRequest> fp = null;
75 getDF(RoleRequest.class),
81 // Send "Force" if set
82 setQueryParamsOn(client);
84 ROLE_PATH, // +args[idx++],
85 getDF(RoleRequest.class),
90 default: // note, if not an option, whichOption throws Exception
94 boolean rolesSupplied = (args.length>idx);
95 if (fp == null) {// This useless code brought to you by Sonar.
96 throw new CadiException("No call made.");
98 if (fp.get(AAFcli.timeout())) {
101 pw().println("d Role");
103 for (;args.length>idx;++idx ) {
105 if (201!=(rv=((Role)parent)._exec(0,new String[] {"user","add",rr.getName(),args[idx]}))) {
106 rv = 206 /*HttpStatus.PARTIAL_CONTENT_206*/;
108 } catch (LocatorException e) {
109 throw new CadiException(e);
114 if ((rv=fp.code())==202) {
117 pw().println(" Accepted, but requires Approvals before actualizing");
128 public void detailedHelp(int indent, StringBuilder sb) {
129 detailLine(sb,indent,"Create OR Delete a Role");
130 detailLine(sb,indent+2,"name - Name of Role to create");
131 api(sb,indent,HttpMethods.POST,"authz/role",RoleRequest.class,true);
132 api(sb,indent,HttpMethods.DELETE,"authz/role",RoleRequest.class,false);