Ejemplo n.º 1
0
    def __init__(self, tokens=None):
        """Create a CfdeClient.

        Keyword Arguments:
            service_instance (str): The instance of the Globus Automate Flow
                    and/or the DERIVA ingest Action Provider to use. Unless directed otherwise,
                    this should be left to the default. **Default**: ``prod``.
            tokens (dict): A dict keyed by scope, of active Globus Tokens. token keys MUST be a
                    subset of self.scopes. Each token value must contain an additional dict, and
                    have an active "access_token". setting tokens=None will require .login() to
                    be called instead.
                    **Default**: ``None``.
        """
        self.__service_instance = os.getenv("CFDE_SUBMIT_SERVICE_INSTANCE", "prod")
        self.__remote_config = {}  # managed by property
        self.__tokens = {}
        self.__flow_client = None
        self.local_config = fair_research_login.ConfigParserTokenStorage(
            filename=self.config_filename
        )
        cli_message = ('Starting login with Globus Auth, '
                       'press ^C twice to cancel or once to manually authenticate')
        code_handlers = [
            fair_research_login.LocalServerCodeHandler(cli_message=cli_message),
            fair_research_login.InputCodeHandler(),
        ]
        self.__native_client = fair_research_login.NativeClient(client_id=self.client_id,
                                                                app_name=self.app_name,
                                                                token_storage=self.local_config,
                                                                code_handlers=code_handlers,)
        self.last_flow_run = {}
        # Fetch dynamic config info
        self.tokens = tokens or {}
        # Set to true when self.check() passes
        self.ready = False
Ejemplo n.º 2
0
 def get_native_client(self):
     """
     :returns an instance of fair_research_login.NativeClient
     """
     if getattr(self, 'client_id', None) is None:
         raise gladier.exc.AuthException(
             'Gladier client must be instantiated with a '
             '"client_id" to use "login()!')
     secrets_cfg = fair_research_login.ConfigParserTokenStorage(
         filename=self.secret_config_filename)
     return fair_research_login.NativeClient(client_id=self.client_id,
                                             app_name=self.app_name,
                                             token_storage=secrets_cfg)
Ejemplo n.º 3
0
    def get_native_client(self):
        """
        fair_research_login.NativeClient is used when ``authorizers`` are not provided to __init__.
        This enables local login to the Globus Automate Client, FuncX, and any other Globus
        Resource Server.

        :return: an instance of fair_research_login.NativeClient
        """
        if getattr(self, 'client_id', None) is None:
            raise gladier.exc.AuthException(
                'Gladier client must be instantiated with a '
                '"client_id" to use "login()!')
        secrets_cfg = fair_research_login.ConfigParserTokenStorage(
            filename=self.secret_config_filename)
        return fair_research_login.NativeClient(client_id=self.client_id,
                                                app_name=self.app_name,
                                                token_storage=secrets_cfg)
Ejemplo n.º 4
0
    def __init__(self,
                 authorizer=None,
                 app_name=None,
                 native_client=None,
                 config=None,
                 base_url='https://identifiers.fair-research.org/'):
        self.app_name = app_name or self.NAME
        self.config = config or self.CONFIG
        self.base_url = base_url
        self._authorizer = authorizer

        if native_client is None:
            storage = fair_research_login.ConfigParserTokenStorage(
                filename=self.config, section='tokens')
            self.native_client = fair_research_login.NativeClient(
                app_name=self.app_name,
                client_id=self.CLIENT_ID,
                default_scopes=self.SCOPES,
                token_storage=storage)
Ejemplo n.º 5
0
    def __init__(self, tokens=None):
        """Create a CfdeClient.

        Keyword Arguments:
            tokens (dict): A dict keyed by scope, of active Globus Tokens. token keys MUST be a
                    subset of self.scopes. Each token value must contain an additional dict, and
                    have an active "access_token". setting tokens=None will require .login() to
                    be called instead.
                    **Default**: ``None``.
        """
        try:
            with open(self.config_filename) as f:
                config_data = f.readlines()
            if any(x for x in config_data if x.startswith('flows_automated_tests')):
                os.unlink(self.config_filename)
        except FileNotFoundError:
            pass

        self.__service_instance = os.getenv("CFDE_SUBMIT_SERVICE_INSTANCE", "prod")
        self.__remote_config = {}  # managed by property
        self.__tokens = {}
        self.__flow_client = None
        self.__transfer_client = None
        self.transfer_scope = CONFIG["TRANSFER_SCOPE"]
        self.local_config = fair_research_login.ConfigParserTokenStorage(
            filename=self.config_filename
        )
        cli_message = ('Starting login with Globus Auth, '
                       'press ^C twice to cancel or once to manually authenticate')
        code_handlers = [
            fair_research_login.LocalServerCodeHandler(cli_message=cli_message),
            fair_research_login.InputCodeHandler(),
        ]
        self.__native_client = fair_research_login.NativeClient(client_id=self.client_id,
                                                                app_name=self.app_name,
                                                                token_storage=self.local_config,
                                                                code_handlers=code_handlers, )
        self.last_flow_run = {}
        # Fetch dynamic config info
        self.tokens = tokens or {}
        # Set to true when self.check() passes
        self.ready = False