Commit 9d860e5e authored by Sonia Zorba's avatar Sonia Zorba
Browse files

CLI improvements

parent 6e84490a
import os
base_cmd = "java -jar ~/code/ia2-gms/gms-client/gms-cli/target/gms-cli.jar --token-file ~/Downloads/token.txt --config-file ~/code/ia2-gms/gms-client/gms-cli/gms.properties "
def exec(cmd):
result = os.popen(base_cmd + cmd).read()
print(result)
return result
assert exec("create-group test false") == "Group created\n"
assert exec("create-group test.test2 true") == "Group created\n"
assert exec("list-groups test") == "test2\n"
assert exec("add-member test.test2 2386") == "Member added\n"
assert exec("add-permission test.test2 2386 VIEW_MEMBERS") == "Permission added\n"
exec("get-user-permissions 2386")
assert exec("get-group-permissions test.test2") == "2386 VIEW_MEMBERS\n"
exec("get-member-email-addresses test.test2 VIEW_MEMBERS")
exec("get-user-groups 2386")
assert exec("set-permission test.test2 2386 ADMIN") == "Permission changed\n"
assert exec("get-group-permissions test.test2") == "2386 ADMIN\n"
assert exec("delete-permission test.test2 2386") == "Permission removed\n"
assert exec("get-group-permissions test.test2") == ""
exec("remove-member test.test2 2386")
exec("get-member-email-addresses test.test2 VIEW_MEMBERS") == ""
exec("delete-group test.test2")
assert exec("list-groups test") == ""
gms_url=http://localhost:8082/gms/ws/jwt
gms_url=http://localhost:8082/gms
client_id=gms_cli
client_secret=gms
rap_url=http://localhost/rap-ia2
......@@ -20,6 +20,11 @@
<artifactId>gms-client</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>
</dependencies>
<build>
<finalName>gms-cli</finalName>
......
......@@ -2,7 +2,9 @@ package it.inaf.ia2.gms.cli;
import it.inaf.ia2.client.ClientException;
import it.inaf.ia2.gms.client.GmsClient;
import it.inaf.ia2.gms.client.model.GroupPermission;
import it.inaf.ia2.gms.client.model.Permission;
import it.inaf.ia2.gms.client.model.UserPermission;
import it.inaf.ia2.rap.client.ClientCredentialsRapClient;
import it.inaf.ia2.rap.client.RapClient;
import it.inaf.ia2.rap.data.AccessTokenResponse;
......@@ -74,6 +76,10 @@ public class CLI {
}
argIndex++;
}
if (!commandParsed) {
displayUsage();
}
}
private String getNextArg() {
......@@ -159,6 +165,16 @@ public class CLI {
private void parseCommand() {
switch (args[argIndex]) {
case "list-groups": {
String parent = "";
if (args.length == argIndex + 2) {
parent = args[argIndex + 1];
}
for (String group : client.listGroups(parent, false)) {
System.out.println(group);
}
break;
}
case "create-group":
boolean leaf = false;
if (argIndex + 2 < args.length) {
......@@ -167,10 +183,31 @@ public class CLI {
client.createGroup(args[argIndex + 1], leaf);
System.out.println("Group created");
break;
case "get-group-permissions": {
String parent = "";
if (args.length == argIndex + 2) {
parent = args[argIndex + 1];
}
for (GroupPermission gp : client.getGroupPermissions(parent)) {
System.out.println(gp.getUserId() + " " + gp.getPermission());
}
break;
}
case "delete-group":
client.deleteGroup(args[argIndex + 1]);
client.deleteGroup(getNextArg());
System.out.println("Group deleted");
break;
case "get-user-groups": {
String userId = getNextArg();
String parent = "";
if (args.length == argIndex + 2) {
parent = args[argIndex + 1];
}
for (String group : client.getUserGroups(userId, parent)) {
System.out.println(group);
}
break;
}
case "add-member":
if (argIndex + 2 >= args.length) {
displayUsage();
......@@ -185,6 +222,11 @@ public class CLI {
client.removeMember(args[argIndex + 1], args[argIndex + 2]);
System.out.println("Member removed");
break;
case "get-user-permissions":
for (UserPermission up : client.getUserPermissions(getNextArg())) {
System.out.println(up.getGroup() + " " + up.getPermission());
}
break;
case "set-permission":
if (argIndex + 3 >= args.length) {
displayUsage();
......@@ -230,8 +272,12 @@ public class CLI {
+ " [--rap-url <url>]\n"
+ " [--client-id <id>]\n"
+ " [--client-secret <secret>]\n"
+ " list-groups [<name1.name2.name3>]\n"
+ " create-group <name1.name2.name3> [<leaf>]\n"
+ " delete-group <name1.name2.name3>\n"
+ " get-user-groups <user_id> [<name1.name2.name3>]\n"
+ " get-group-permissions [<name1.name2.name3>]\n"
+ " get-user-permissions <user_id>\n"
+ " add-member <name1.name2.name3> <user_id>\n"
+ " remove-member <name1.name2.name3> <user_id>\n"
+ " set-permission <name1.name2.name3> <user_id> <permission>\n"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment