from__future__importannotationsimporttypingastfromglobus_sdk._typesimportUUIDLikefrom..builderimportScopeBuilder,ScopeBuilderScopesclass_FlowsScopeBuilder(ScopeBuilder):""" The Flows service breaks the scopes/resource server convention: its resource server is a domain name but its scopes are built around the client ID. Given that there isn't a simple way to support this more generally (and we shouldn't encourage supporting this more generally), this class serves to build out the scopes accurately specifically for Flows. """def__init__(self,domain_name:str,client_id:str,known_scopes:ScopeBuilderScopes=None,known_url_scopes:ScopeBuilderScopes=None,)->None:self._client_id=client_idsuper().__init__(domain_name,known_scopes=known_scopes,known_url_scopes=known_url_scopes)defurn_scope_string(self,scope_name:str)->str:returnf"urn:globus:auth:scope:{self._client_id}:{scope_name}"defurl_scope_string(self,scope_name:str)->str:returnf"https://auth.globus.org/scopes/{self._client_id}/{scope_name}"FlowsScopes=_FlowsScopeBuilder("flows.globus.org","eec9b274-0c81-4334-bdc2-54e90e689b9a",known_url_scopes=["all","manage_flows","view_flows","run","run_status","run_manage",],)class_SpecificFlowScopesClassStub(ScopeBuilder):""" This stub object ensures that the type deductions for type checkers (e.g. mypy) on SpecificFlowClient.scopes are correct. Primarily, it should be possible to access the `scopes` attribute, the `user` scope, and the `resource_server`, but these usages should raise specific and informative runtime errors. Our types are therefore less accurate for class-var access, but more accurate for instance-var access. """def__init__(self,*args:t.Any,**kwargs:t.Any)->None:super().__init__("<stub>")def__getattr__(self,name:str)->t.Any:ifname=="user":_raise_attr_error("scopes")elifname=="resource_server":_raise_attr_error("resource_server")returnsuper().__getattr__(name)def__getattribute__(self,name:str)->t.Any:ifname=="resource_server":_raise_attr_error("resource_server")returnobject.__getattribute__(self,name)def_raise_attr_error(name:str)->t.NoReturn:raiseAttributeError(f"It is not valid to attempt to access the '{name}' attribute of the ""SpecificFlowClient class. "f"Instead, instantiate a SpecificFlowClient and access the '{name}' attribute ""from that instance.")
[docs]classSpecificFlowScopeBuilder(ScopeBuilder):""" This defines the scopes for a single flow (as distinct from the Flows service). It primarily provides the `user` scope which is typically needed to start a run of a flow. Example usage: .. code-block:: python sb = SpecificFlowScopeBuilder("my-flow-id-here") flow_scope = sb.user """_CLASS_STUB=_SpecificFlowScopesClassStub()def__init__(self,flow_id:UUIDLike)->None:self._flow_id=flow_idstr_flow_id=str(flow_id)super().__init__(resource_server=str_flow_id,known_url_scopes=[("user",f"flow_{str_flow_id.replace('-','_')}_user")],)