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.ns;
26 import org.onap.aaf.auth.cmd.AAFcli;
27 import org.onap.aaf.auth.cmd.BaseCmd;
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 public class Attrib extends BaseCmd<NS> {
38 private static final String[] options = {"add","upd","del"};
39 private String authzString = "/authz/ns/";
40 private String atrributeString = "/attrib/";
42 public Attrib(NS ns) {
44 new Param(optionsToString(options),true),
45 new Param("ns-name",true),
46 new Param("key",true),
47 new Param("value",false)
52 public int _exec(final int idx, final String ... args) throws CadiException, APIException, LocatorException {
53 final int option = whichOption(options, args[idx]);
54 final String ns = args[idx+1];
55 final String key = args[idx+2];
58 if (args.length<=idx+3) {
59 throw new CadiException("Not added: Need more Data");
66 return same(new Retryable<Integer>() {
68 public Integer code(Rcli<?> client) throws CadiException, APIException {
69 Future<Void> fp = null;
73 fp = client.create(authzString+ns+atrributeString+key+'/'+value,Void.class);
74 message = String.format("Add Attrib %s=%s to %s",
78 fp = client.update(authzString+ns+atrributeString+key+'/'+value);
79 message = String.format("Update Attrib %s=%s for %s",
83 fp = client.delete(authzString+ns+atrributeString+key,Void.class);
84 message = String.format("Attrib %s deleted from %s",
88 throw new CadiException("Bad Argument");
93 if (fp.get(AAFcli.timeout())) {
94 pw().println(message);
106 public void detailedHelp(int indentValue, StringBuilder sb) {
107 int indent = indentValue;
108 detailLine(sb,indent,"Add or Delete Administrator to/from Namespace");
110 detailLine(sb,indent,"name - Name of Namespace");
111 detailLine(sb,indent,"id - Credential of Person(s) to be Administrator");
113 detailLine(sb,indent,"aafcli will call API on each ID presented.");
115 api(sb,indent,HttpMethods.POST,"authz/ns/<ns>/admin/<id>",Void.class,true);
116 api(sb,indent,HttpMethods.DELETE,"authz/ns/<ns>/admin/<id>",Void.class,false);