[docs]classScopeCollection(abc.ABC):""" The common base for scope collections. ScopeCollections act as namespaces with attribute access to get scopes. They can also be iterated to get all of their defined scopes and provide the appropriate resource_server string for use in OAuth2 flows. """@property@abc.abstractmethoddefresource_server(self)->str:...@abc.abstractmethoddef__iter__(self)->t.Iterator[Scope]:...
[docs]classStaticScopeCollection(ScopeCollection):""" A static scope collection is a data container which provides various scopes as class attributes. ``resource_server`` must be available as a class attribute. """resource_server:t.ClassVar[str]def__iter__(self)->t.Iterator[Scope]:forviewin(vars(self).values(),vars(self.__class__).values()):forvalueinview:ifisinstance(value,Scope):yieldvalue
[docs]classDynamicScopeCollection(ScopeCollection):""" The base type for dynamic scope collections, where the resource server is variable. The default implementation takes the resource server as the only init-time parameter. :param resource_server: The resource_server to use for all scopes attached to this scope collection. """# DynamicScopeCollection classes are expected to provide# the scope names which they provide as a classvar# these are often properties for dynamic computation_scope_names:t.ClassVar[tuple[str,...]]def__init__(self,resource_server:str)->None:self._resource_server=resource_serverdef__iter__(self)->t.Iterator[Scope]:fornameinself._scope_names:value=getattr(self,name)ifisinstance(value,Scope):yieldvalue@propertydefresource_server(self)->str:returnself._resource_server
def_urn_scope(resource_server:str,scope_name:str)->Scope:""" Convert a short name + resource server string to a scope, in the Globus Auth URN format. Example Usage: >>> _urn_scope("transfer.api.globus.org", "all") Scope('urn:globus:auth:scope:transfer.api.globus.org:all') :param resource_server: The resource server string. :param scope_name: The short name for the scope. """returnScope(f"urn:globus:auth:scope:{resource_server}:{scope_name}")def_url_scope(resource_server:str,scope_name:str)->Scope:""" Convert a short name + resource server string to a scope, in the Globus Auth URL format. Example Usage: >>> _url_scope("actions.globus.org", "hello_world") Scope('https://auth.globus.org/scopes/actions.globus.org/hello_world') :param resource_server: The resource server string. :param scope_name: The short name for the scope. """returnScope(f"https://auth.globus.org/scopes/{resource_server}/{scope_name}")