11from  pubnub  import  utils 
22from  pubnub .endpoints .endpoint  import  Endpoint 
3- from  pubnub .errors  import  PNERR_PAM_NO_FLAGS 
3+ from  pubnub .errors  import  PNERR_PAM_NO_FLAGS ,  PNERR_PAM_INVALID_ARGUMENTS 
44from  pubnub .exceptions  import  PubNubException 
55from  pubnub .enums  import  HttpMethod , PNOperationType 
66from  pubnub .models .consumer .access_manager  import  PNAccessManagerGrantResult 
@@ -14,14 +14,34 @@ def __init__(self, pubnub):
1414        self ._auth_keys  =  []
1515        self ._channels  =  []
1616        self ._groups  =  []
17+         self ._uuids  =  []
1718        self ._read  =  None 
1819        self ._write  =  None 
1920        self ._manage  =  None 
2021        self ._delete  =  None 
2122        self ._ttl  =  None 
23+         self ._get  =  None 
24+         self ._update  =  None 
25+         self ._join  =  None 
2226
2327        self ._sort_params  =  True 
2428
29+     def  get (self , flag ):
30+         self ._get  =  flag 
31+         return  self 
32+ 
33+     def  update (self , flag ):
34+         self ._update  =  flag 
35+         return  self 
36+ 
37+     def  join (self , flag ):
38+         self ._join  =  flag 
39+         return  self 
40+ 
41+     def  uuids (self , uuids ):
42+         utils .extend_list (self ._uuids , uuids )
43+         return  self 
44+ 
2545    def  auth_keys (self , auth_keys ):
2646        utils .extend_list (self ._auth_keys , auth_keys )
2747        return  self 
@@ -79,6 +99,12 @@ def custom_params(self):
7999            params ['m' ] =  '1'  if  self ._manage  is  True  else  '0' 
80100        if  self ._delete  is  not None :
81101            params ['d' ] =  '1'  if  self ._delete  is  True  else  '0' 
102+         if  self ._get  is  not None :
103+             params ['g' ] =  '1'  if  self ._get  is  True  else  '0' 
104+         if  self ._update  is  not None :
105+             params ['u' ] =  '1'  if  self ._update  is  True  else  '0' 
106+         if  self ._join  is  not None :
107+             params ['j' ] =  '1'  if  self ._join  is  True  else  '0' 
82108
83109        if  self ._auth_keys :
84110            params ['auth' ] =  utils .join_items (self ._auth_keys )
@@ -89,6 +115,9 @@ def custom_params(self):
89115        if  self ._groups :
90116            params ['channel-group' ] =  utils .join_items (self ._groups )
91117
118+         if  self ._uuids :
119+             params ['target-uuid' ] =  utils .join_items (self ._uuids )
120+ 
92121        if  self ._ttl  is  not None :
93122            params ['ttl' ] =  str (int (self ._ttl ))
94123
@@ -103,9 +132,21 @@ def http_method(self):
103132    def  validate_params (self ):
104133        self .validate_subscribe_key ()
105134        self .validate_secret_key ()
135+         self .validate_publish_key ()
106136        # self.validate_channels_and_groups() 
107137
108-         if  self ._write  is  None  and  self ._read  is  None  and  self ._manage  is  None :
138+         if  self ._channels  and  self ._groups  and  self ._uuids :
139+             raise  PubNubException (
140+                 pn_error = PNERR_PAM_INVALID_ARGUMENTS ,
141+                 errormsg = "Grants for channels or channelGroups can't be changed together with grants for UUIDs" )
142+ 
143+         if  self ._uuids  and  not  self ._auth_keys :
144+             raise  PubNubException (pn_error = PNERR_PAM_INVALID_ARGUMENTS , errormsg = "UUIDs grant management require " 
145+                                                                                  "providing non empty authKeys" 
146+                                   )
147+ 
148+         if  self ._write  is  None  and  self ._read  is  None  and  self ._manage  is  None  and  self ._get  is  None  \
149+                 and  self ._update  is  None  and  self ._join  is  None :
109150            raise  PubNubException (pn_error = PNERR_PAM_NO_FLAGS )
110151
111152    def  create_response (self , envelope ):
0 commit comments