--- /dev/null
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aaf\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * ===========================================================================\r
+ * * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * * you may not use this file except in compliance with the License.\r
+ * * You may obtain a copy of the License at\r
+ * * \r
+ * * http://www.apache.org/licenses/LICENSE-2.0\r
+ * * \r
+ * * Unless required by applicable law or agreed to in writing, software\r
+ * * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * * See the License for the specific language governing permissions and\r
+ * * limitations under the License.\r
+ * * ============LICENSE_END====================================================\r
+ * *\r
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package org.onap.aaf.cmd.ns;\r
+\r
+import org.onap.aaf.cmd.AAFcli;\r
+import org.onap.aaf.cmd.BaseCmd;\r
+import org.onap.aaf.cmd.Param;\r
+import org.onap.aaf.cssa.rserv.HttpMethods;\r
+\r
+import org.onap.aaf.cadi.CadiException;\r
+import org.onap.aaf.cadi.LocatorException;\r
+import org.onap.aaf.cadi.client.Future;\r
+import org.onap.aaf.cadi.client.Rcli;\r
+import org.onap.aaf.cadi.client.Retryable;\r
+import org.onap.aaf.inno.env.APIException;\r
+\r
+public class Admin extends BaseCmd<NS> {\r
+ private final static String[] options = {"add","del"};\r
+\r
+ public Admin(NS ns) throws APIException {\r
+ super(ns,"admin",\r
+ new Param(optionsToString(options),true),\r
+ new Param("name",true),\r
+ new Param("id[,id]*",true)\r
+ );\r
+ }\r
+\r
+ @Override\r
+ public int _exec(int _idx, final String ... args) throws CadiException, APIException, LocatorException {\r
+ int idx = _idx;\r
+ final int option = whichOption(options, args[idx++]);\r
+ final String ns = args[idx++];\r
+ final String ids[] = args[idx++].split(",");\r
+ final String realm = getOrgRealm();\r
+// int rv = 500;\r
+ return same(new Retryable<Integer>() {\r
+ @Override\r
+ public Integer code(Rcli<?> client) throws CadiException, APIException { \r
+ Future<Void> fp = null;\r
+ for(String id : ids) {\r
+ if (id.indexOf('@') < 0 && realm != null) id += '@' + realm;\r
+ String verb;\r
+ switch(option) {\r
+ case 0: \r
+ fp = client.create("/authz/ns/"+ns+"/admin/"+id,Void.class);\r
+ verb = " added to ";\r
+ break;\r
+ case 1: \r
+ fp = client.delete("/authz/ns/"+ns+"/admin/"+id,Void.class);\r
+ verb = " deleted from ";\r
+ break;\r
+ default:\r
+ throw new CadiException("Bad Argument");\r
+ };\r
+ \r
+ if(fp.get(AAFcli.timeout())) {\r
+ pw().append("Admin ");\r
+ pw().append(id);\r
+ pw().append(verb);\r
+ pw().println(ns);\r
+ } else {\r
+ error(fp);\r
+ return fp.code();\r
+ }\r
+ \r
+ }\r
+ return fp==null?500:fp.code();\r
+ }\r
+ });\r
+ }\r
+\r
+ @Override\r
+ public void detailedHelp(int _indent, StringBuilder sb) {\r
+ int indent = _indent;\r
+ detailLine(sb,indent,"Add or Delete Administrator to/from Namespace");\r
+ indent+=4;\r
+ detailLine(sb,indent,"name - Name of Namespace");\r
+ detailLine(sb,indent,"id - Credential of Person(s) to be Administrator");\r
+ sb.append('\n');\r
+ detailLine(sb,indent,"aafcli will call API on each ID presented.");\r
+ indent-=4;\r
+ api(sb,indent,HttpMethods.POST,"authz/ns/<ns>/admin/<id>",Void.class,true);\r
+ api(sb,indent,HttpMethods.DELETE,"authz/ns/<ns>/admin/<id>",Void.class,false);\r
+ }\r
+\r
+}\r