Commit fc395107 authored by Cristiano Urban's avatar Cristiano Urban
Browse files

Added 'delGroup()' method + minor fixes.

parent 5e48f03d
Loading
Loading
Loading
Loading
+34 −3
Original line number Diff line number Diff line
@@ -20,12 +20,18 @@ class VOSGroup(RedisRPCClient):
        super(VOSGroup, self).__init__(self.host, self.port, self.db, self.rpcQueue)
        
    def addGroup(self, groupType, groupname, vospacePath):
        addGroupRequest = { "requestType": "GRPR_ADD", "vospacePath": vospacePath, "groupName": groupname }
        if groupType == "read":
            requestType = "GRPR_ADD"
        else:
            requestType = "GRPW_ADD"        
        addGroupRequest = { "requestType": requestType, "vospacePath": vospacePath, "groupName": groupname }
        addGroupResponse = self.call(addGroupRequest)
        if "responseType" not in addGroupResponse:
            sys.exit("FATAL: Malformed response, storage acknowledge expected.\n")
        elif addGroupResponse["responseType"] == "GRPR_STARTED":
            print("\nThe procedure to change groupRead persmission has started.\nYou'll receive an email at the end of the operation.\n")
            print("\nThe procedure to change 'group_read' persmissions has started.\nYou'll receive an email at the end of the operation.\n")
        elif addGroupResponse["responseType"] == "GRPW_STARTED":
            print("\nThe procedure to change 'group_write' persmissions has started.\nYou'll receive an email at the end of the operation.\n")
        elif addGroupResponse["responseType"] == "ERROR":
            errorCode = addGroupResponse["errorCode"]
            errorMsg = addGroupResponse["errorMsg"]
@@ -33,6 +39,26 @@ class VOSGroup(RedisRPCClient):
        else:
            sys.exit("\nFATAL: Unknown response type.\n")
    
    def delGroup(self, groupType, groupname, vospacePath):
        if groupType == "read":
            requestType = "GRPR_DEL"
        else:
            requestType = "GRPW_DEL"
        delGroupRequest = { "requestType": requestType, "vospacePath": vospacePath, "groupName": groupname }
        delGroupResponse = self.call(delGroupRequest)
        if "responseType" not in delGroupResponse:
            sys.exit("FATAL: Malformed response, storage acknowledge expected.\n")
        elif delGroupResponse["responseType"] == "GRPR_STARTED":
            print("\nThe procedure to change 'group_read' persmissions has started.\nYou'll receive an email at the end of the operation.\n")
        elif delGroupResponse["responseType"] == "GRPW_STARTED":
            print("\nThe procedure to change 'group_write' persmissions has started.\nYou'll receive an email at the end of the operation.\n")
        elif delGroupResponse["responseType"] == "ERROR":
            errorCode = delGroupResponse["errorCode"]
            errorMsg = delGroupResponse["errorMsg"]
            sys.exit(f"\nError code: {errorCode}\nError message: {errorMsg}\n")
        else:
            sys.exit("\nFATAL: Unknown response type.\n")
    
    def help(self):
        sys.exit("""
NAME
@@ -88,7 +114,12 @@ if len(sys.argv) == 5:
else:
    vosGroupCli.help()
    
if groupType != "read" and groupType != "write":
    vosGroupCli.help()

if method == "add":
    vosGroupCli.addGroup(groupType, groupname, vospacePath)
elif method == "del":
    vosGroupCli.delGroup(groupType, groupname, vospacePath)
else:
    vosGroupCli.help()