+++ /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 Attrib extends BaseCmd<NS> {\r
- private final static String[] options = {"add","upd","del"};\r
-\r
- public Attrib(NS ns) throws APIException {\r
- super(ns,"attrib",\r
- new Param(optionsToString(options),true),\r
- new Param("ns",true),\r
- new Param("key",true),\r
- new Param("value",false)\r
- );\r
- }\r
-\r
- @Override\r
- public int _exec(final int idx, final String ... args) throws CadiException, APIException, LocatorException {\r
- final int option = whichOption(options, args[idx]);\r
- final String ns = args[idx+1];\r
- final String key = args[idx+2];\r
- final String value;\r
- if(option!=2) {\r
- if(args.length<=idx+3) {\r
- throw new CadiException("Not added: Need more Data");\r
- }\r
- value = args[idx+3];\r
- } else {\r
- value = "";\r
- }\r
- \r
- return same(new Retryable<Integer>() {\r
- @Override\r
- public Integer code(Rcli<?> client) throws CadiException, APIException { \r
- Future<Void> fp = null;\r
- String message;\r
- switch(option) {\r
- case 0: \r
- fp = client.create("/authz/ns/"+ns+"/attrib/"+key+'/'+value,Void.class);\r
- message = String.format("Add Attrib %s=%s to %s",\r
- key,value,ns);\r
- break;\r
- case 1: \r
- fp = client.update("/authz/ns/"+ns+"/attrib/"+key+'/'+value);\r
- message = String.format("Update Attrib %s=%s for %s",\r
- key,value,ns);\r
- break;\r
- case 2: \r
- fp = client.delete("/authz/ns/"+ns+"/attrib/"+key,Void.class);\r
- message = String.format("Attrib %s deleted from %s",\r
- key,ns);\r
- break;\r
- default:\r
- throw new CadiException("Bad Argument");\r
- };\r
- \r
- if(fp.get(AAFcli.timeout())) {\r
- pw().println(message);\r
- } else {\r
- error(fp);\r
- return fp.code();\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