Commit 62dd2c2c authored by Cristiano Urban's avatar Cristiano Urban
Browse files

Added code to implement 'group_read' and 'group_write' listing for a VOSpace node.

parent e206b9bb
Loading
Loading
Loading
Loading
+35 −20
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ import sys

from redis_rpc_client import RedisRPCClient
from config import Config
from tabulate import tabulate


class VOSGroup(RedisRPCClient):
@@ -59,6 +60,20 @@ class VOSGroup(RedisRPCClient):
        else:
            sys.exit("\nFATAL: Unknown response type.\n")
            
    def listGroups(self, groupType, vospacePath):
        if groupType == "read":
            requestType = "GRPR_LST"
        else:
            requestType = "GRPW_LST"
        listGroupsRequest = { "requestType": requestType, "vospacePath": vospacePath }
        listGroupsResponse = self.call(listGroupsRequest)
        groupList = listGroupsResponse["groupList"]
        if not groupList:
            sys.exit(f"\n'group_{groupType}' is empty.\n")
        print()
        print(tabulate(groupList, headers = "keys", tablefmt = "pretty"))
        print()

    def help(self):
        sys.exit("""
NAME
@@ -74,7 +89,7 @@ DESCRIPTION
       Four parameters are required:

       GROUP_TYPE:
           specifies the group type. can be 'read' or 'write'
           specifies the group type: allowed values are 'read' or 'write'

       METHOD:
           there are three supported methods:
@@ -84,9 +99,8 @@ DESCRIPTION

       GROUP_NAME:
           represents a group of users or a single user.
           In the first case, the syntax is 'gms_' followed
           by the group name.
           In the second case, the syntax is:
           In the first case, just specify the group name.
           In the second case, the group name syntax is:

               people.name\\\.surname

@@ -94,14 +108,11 @@ DESCRIPTION
           represents the node VOSpace path.

EXAMPLES
      The following command will import recursively all the nodes contained
      in 'mydir' on the VOSpace for the 'jsmith' user:
      
      Add 'jane.lee' to 'group_read' for the VOSpace node /john.smith/test/foo:
      Add 'jane.lee' to 'group_read' for the VOSpace node '/john.smith/test/foo' and any child nodes:
      # vos_group read add people.jane\\\.lee /john.smith/test/foo

      Add 'my_group' to 'group_write' for the VOSpace node /john.smith/test/foo:
      # vos_group write add gms_mygroup /john.smith/test/foo
      Add 'my_group' to 'group_write' for the VOSpace node '/john.smith/test/foo' and any child nodes:
      # vos_group write add my_group /john.smith/test/foo

    """)

@@ -111,6 +122,8 @@ vosGroupCli = VOSGroup()
# Check the number of input args
if len(sys.argv) == 5:
    script, groupType, method, groupname, vospacePath = sys.argv
elif len(sys.argv) == 4:
    script, groupType, method, vospacePath = sys.argv
else:
    vosGroupCli.help()

@@ -121,5 +134,7 @@ if method == "add":
    vosGroupCli.addGroup(groupType, groupname, vospacePath)
elif method == "del":
    vosGroupCli.delGroup(groupType, groupname, vospacePath)
elif method == "list":
    vosGroupCli.listGroups(groupType, vospacePath)
else:
    vosGroupCli.help()
+12 −0
Original line number Diff line number Diff line
@@ -80,6 +80,18 @@ class GroupRwRPCServer(RedisRPCServer):
                self.groupRwReadyQueue.insertJob(jobObj)

                response = { "responseType": f"{jobType}_STARTED" }
        elif requestBody["requestType"] == "GRPR_LST":
            vospacePath = requestBody["vospacePath"]
            result = self.dbConn.getGroupRead(vospacePath)

            response = { "responseType": "GRPR_LST_DONE",
                         "groupList": result }
        elif requestBody["requestType"] == "GRPW_LST":
            vospacePath = requestBody["vospacePath"]
            result = self.dbConn.getGroupWrite(vospacePath)

            response = { "responseType": "GRPW_LST_DONE",
                         "groupList": result }
        else:
            response = { "responseType": "ERROR",
                         "errorCode": 4,