"""Management of runZero organizations."""importuuidfromtypingimportList,Optionalfromrunzero.clientimportClientfromrunzero.typesimportOrganization,OrgOptions
[docs]classOrgsAdmin:"""Management of runZero organizations. Organizations are an administrative boundary for various platform-level objects and methods. :param client: A handle to the :class:`runzero.Client` client which manages interactions with the runZero server. """_ENDPOINT="api/v1.0/account/orgs"def__init__(self,client:Client):"""Constructor method"""self._client=client
[docs]defget_all(self)->List[Organization]:""" Retrieves all runZero Organizations available to your account :returns: A list of all Organizations available to your account :raises: AuthError, ClientError, ServerError """res=self._client.execute("GET",self._ENDPOINT)result:List[Organization]=[]fororginres.json_obj:result.append(Organization.parse_obj(org))returnresult
[docs]defget(self,org_id:Optional[uuid.UUID]=None,name:Optional[str]=None)->Optional[Organization]:""" Retrieves the runZero Organization with the provided name or id, if it exists in your account. :param org_id: Optional id of the organization to retrieve :param name: Optional name of the organization to retrieve :returns: Organization if found, or None :raises: AuthError, ClientError, ServerError """ifnameisNoneandorg_idisNone:raiseValueError("must provide org_id or organization name")iforg_idisnotNone:res=self._client.execute("GET",f"{self._ENDPOINT}/{org_id}")returnOrganization.parse_obj(res.json_obj)# namefororginself.get_all():iforg.name==name:returnorgreturnNone
[docs]defcreate(self,org_options:OrgOptions)->Optional[Organization]:""" Creates a new organization in your account. :param org_options: Description of organization to create :returns: Organization created or None :raises: AuthError, ClientError, ServerError """res=self._client.execute("PUT",self._ENDPOINT,data=org_options)obj=res.json_objdata_obj=obj.get("data","")ifdata_obj:obj=data_objreturnOrganization.parse_obj(obj)
[docs]defupdate(self,org_id:uuid.UUID,org_options:OrgOptions)->Optional[Organization]:""" Updates an organization associated with your account. :param org_id: The ID of the organization to patch :param org_options: Organization's updated values :returns: Organization updated or None :raises: AuthError, ClientError, ServerError """res=self._client.execute("PATCH",f"{self._ENDPOINT}/{org_id}",data=org_options)returnOrganization.parse_obj(res.json_obj)
[docs]defdelete(self,org_id:uuid.UUID)->None:""" Deletes an organization with provided ID from your account. :param org_id: The ID of the organization to operate against :returns: None :raises: AuthError, ClientError, ServerError """self._client.execute("DELETE",f"{self._ENDPOINT}/{org_id}")