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.ns;
24 import java.util.Collections;
25 import java.util.Comparator;
27 import org.onap.aaf.auth.cmd.BaseCmd;
28 import org.onap.aaf.auth.cmd.DeprecatedCMD;
29 import org.onap.aaf.cadi.client.Future;
30 import org.onap.aaf.misc.env.util.Chrono;
33 import aaf.v2_0.Nss.Ns;
34 import aaf.v2_0.Perms;
35 import aaf.v2_0.Roles;
36 import aaf.v2_0.Users;
37 import aaf.v2_0.Users.User;
39 public class List extends BaseCmd<NS> {
41 private static final String cformat = " %-30s %-6s %-24s\n";
42 private static final String pformat = " %-30s %-24s %-15s\n";
43 private static final String sformat = " %-72s\n";
44 protected static final String kformat = " %-72s\n";
46 public List(NS parent) {
48 cmds.add(new ListByName(this));
50 // TODO: uncomment when on cassandra 2.1.2 if we like cli command to get all ns's
51 // a user is admin or responsible for
52 cmds.add(new ListAdminResponsible(this));
53 cmds.add(new DeprecatedCMD<List>(this,"responsible","'responsible' is deprecated. use 'owner'")); // deprecated
54 cmds.add(new ListActivity(this));
55 cmds.add(new ListUsers(this));
56 cmds.add(new ListChildren(this));
57 cmds.add(new ListNsKeysByAttrib(this));
60 public void report(Future<Nss> fp, String ... str) {
63 pw().println(" *** Namespace Not Found ***");
66 if (fp!=null && fp.value!=null) {
67 for (Ns ns : fp.value.getNs()) {
68 pw().println(ns.getName());
69 if (this.aafcli.isDetailed()) {
70 pw().println(" Description");
71 pw().format(sformat,ns.getDescription()==null?"":ns.getDescription());
73 if (!(ns.getAdmin().isEmpty())) {
74 pw().println(" Administrators");
75 for (String admin : ns.getAdmin()) {
76 pw().format(sformat,admin);
79 if (!(ns.getResponsible().isEmpty())) {
80 pw().println(" Owners (Responsible for Namespace)");
81 for (String responsible : ns.getResponsible()) {
82 pw().format(sformat,responsible);
85 if (!(ns.getAttrib().isEmpty())) {
86 pw().println(" Namespace Attributes");
87 for ( Ns.Attrib attr : ns.getAttrib()) {
88 StringBuilder sb = new StringBuilder(attr.getKey());
89 if (attr.getValue()==null || attr.getValue().length()>0) {
91 sb.append(attr.getValue());
93 pw().format(sformat,sb.toString());
101 public void reportName(Future<Nss> fp, String ... str) {
103 if (fp!=null && fp.value!=null) {
104 java.util.List<Ns> nss = fp.value.getNs();
105 Collections.sort(nss, new Comparator<Ns>() {
107 public int compare(Ns ns1, Ns ns2) {
108 return ns1.getName().compareTo(ns2.getName());
113 pw().println(ns.getName());
114 if (this.aafcli.isDetailed() && ns.getDescription() != null) {
115 pw().println(" " + ns.getDescription());
121 public void reportRole(Future<Roles> fr) {
122 if (fr!=null && fr.value!=null && !(fr.value.getRole().isEmpty())) {
123 pw().println(" Roles");
124 for (aaf.v2_0.Role r : fr.value.getRole()) {
125 pw().format(sformat,r.getName());
130 public void reportPerm(Future<Perms> fp) {
131 if (fp!=null && fp.value!=null && !(fp.value.getPerm().isEmpty())) {
132 pw().println(" Permissions");
133 for (aaf.v2_0.Perm p : fp.value.getPerm()) {
134 pw().format(pformat,p.getType(),p.getInstance(),p.getAction());
140 public void reportCred(Future<Users> fc) {
141 if (fc!=null && fc.value!=null && !(fc.value.getUser().isEmpty())) {
142 pw().println(" Credentials");
143 java.util.List<User> users = fc.value.getUser();
144 Collections.sort(users, new Comparator<User>() {
146 public int compare(User u1, User u2) {
147 return u1.getId().compareTo(u2.getId());
150 for (aaf.v2_0.Users.User u : users) {
151 if (this.aafcli.isTest()) {
152 pw().format(sformat,u.getId());
154 pw().format(cformat,u.getId(),getType(u),Chrono.niceDateStamp(u.getExpires()));
160 public static String getType(User u) {
162 if ((type=u.getType())==null) {
166 case 0: return "NoCrd";
167 case 1: return "U/P";
168 case 2: return "U/P2";
169 case 10: return "FQI";
170 case 200: return "x509";