[docs]defcreate(self,action:str,resource:str,subject:str,effect:str|None=None)->None:"""Create policy. :param action: action for policy :type action: str :param resource: resource for policy :type resource: str :param subject: subject for policy :type subject: str :param effect: effect for policy :type effect: str, optional """request_json={"action":action,"resource":resource,"subject":subject}ifeffect:request_json["effect"]=effectresponse=self._client.httpx_client.post(self._client._href_definitions.get_gateway_policies_href(),headers=self._client._get_headers(),json=request_json,)ifresponse.status_codein[200,201]:returnself._handle_response(response.status_code,"policy creation",response)else:returnself._handle_response(201,"policy creation",response)
[docs]defdelete(self,policy_id:str)->str:"""Delete policy. :param policy_id: ID of policy :type policy_id: str :return: status ("SUCCESS" if succeeded) :rtype: str """response=self._client.httpx_client.delete(self._client._href_definitions.get_gateway_policies_href()+"/"+policy_id,headers=self._client._get_headers(),)returnself._handle_response(204,"policy deletion",response,json_response=False)
[docs]deflist(self)->pd.DataFrame:"""List policies. :returns: dataframe with policies details :rtype: pandas.DataFrame """policies_details=self.get_details()["data"]policies_values=[(m["uuid"],m["resource"],m["action"],m["subject"],m.get("effect",""))forminpolicies_details]table=self._list(policies_values,["ID","RESOURCE","ACTION","SUBJECT","EFFECT"],limit=None,)returntable
[docs]@staticmethoddefget_id(policy_details:dict)->str:"""Get policy ID from policy details. :param policy_details: details of the policy for asset registered in Model Gateway :type policy_details: dict :returns: unique policy ID :rtype: str """returnpolicy_details["uuid"]