Source code for globus_sdk.local_endpoint.personal.owner_info
from__future__importannotationsimportbase64importshleximportuuidclass_B32DecodeError(ValueError):"""custom exception type"""def_b32decode(v:str)->str:# should start with "u_"ifnotv.startswith("u_"):raise_B32DecodeError("should start with 'u_'")v=v[2:]# wrong lengthiflen(v)!=26:raise_B32DecodeError("wrong length")# append padding and uppercase so that b32decode will workv=v.upper()+(6*"=")# try to decodetry:returnstr(uuid.UUID(bytes=base64.b32decode(v)))# if it fails, then it can't be a b32-encoded identityexceptValueErroraserr:raise_B32DecodeError("decode and load as UUID failed")fromerrdef_parse_dn_username(s:str)->tuple[str,bool]:try:user,is_id=_b32decode(s),Trueexcept_B32DecodeError:user,is_id=f"{s}@globusid.org",Falsereturn(user,is_id)
[docs]classGlobusConnectPersonalOwnerInfo:""" Information about the owner of the local Globus Connect Personal endpoint. Users should never create these objects directly, but instead rely upon :meth:`LocalGlobusConnectPersonal.get_owner_info()`. The info object contains ether ``id`` or ``username``. Parsing an info object from local data cannot guarantee that the ``id`` or ``username`` value will be found. Whichever one is present will be set and the other attribute will be ``None``. :ivar id: The Globus Auth ID of the endpoint owner :vartype id: str or None :ivar username: The Globus Auth Username of the endpoint owner :vartype username: str or None :param config_dn: A DN value from GCP configuration, which will be parsed into username or ID """_GRIDMAP_DN_START='"/C=US/O=Globus Consortium/OU=Globus Connect User/CN='username:str|Noneid:str|Nonedef__init__(self,*,config_dn:str)->None:lineinfo=shlex.split(config_dn)iflen(lineinfo)!=2:raiseValueError("Malformed DN: not right length")dn,_local_username=lineinfousername_or_id=dn.split("=",4)[-1]user,is_id=_parse_dn_username(username_or_id)ifis_id:self.username=Noneself.id=userelse:self.username=userself.id=Nonedef__str__(self)->str:return("GlobusConnectPersonalOwnerInfo("+(f"username={self.username}"ifself.usernameisnotNoneelsef"id={self.id}")+")")# private methods for SDK usage only@classmethoddef_from_file(cls,filename:str)->GlobusConnectPersonalOwnerInfo:withopen(filename,encoding="utf-8")asfp:forlineinfp:ifline.startswith(cls._GRIDMAP_DN_START):returncls(config_dn=line.strip())raiseValueError("Could not find GCP DN in data stream")