Example #1
0
    def get(
            cls,
            environment_or_domain: Union[Environment, str] = Environment.PROD,
            client_id: Optional[str] = None,
            client_secret: Optional[str] = None,
            scopes: Optional[Union[Tuple, List]] = (),
            token: str = '',
            is_gssso: bool = False,
            api_version: str = API_VERSION,
            application: str = DEFAULT_APPLICATION,
            http_adapter: requests.adapters.HTTPAdapter = None
    ) -> 'GsSession':
        """ Return an instance of the appropriate session type for the given credentials"""

        environment_or_domain = environment_or_domain.name if isinstance(environment_or_domain,
                                                                         Environment) else environment_or_domain

        if client_id is not None:
            if environment_or_domain not in (Environment.PROD.name, Environment.QA.name, Environment.DEV.name):
                raise MqUninitialisedError('Only PROD, QA and DEV are valid environments')

            return OAuth2Session(environment_or_domain, client_id, client_secret, scopes, api_version=api_version,
                                 application=application, http_adapter=http_adapter)
        elif token:
            return PassThroughSession(environment_or_domain, token, is_gssso, api_version=api_version,
                                      application=application, http_adapter=http_adapter)
        else:
            try:
                return KerberosSession(environment_or_domain, api_version=api_version, http_adapter=http_adapter)
            except NameError:
                raise MqUninitialisedError('Must specify client_id and client_secret')
Example #2
0
    def get(
        cls,
        environment_or_domain: Union[Environment, str] = Environment.PROD,
        client_id: Optional[str] = None,
        client_secret: Optional[str] = None,
        scopes: Optional[Union[Tuple, List, str]] = (),
        token: str = '',
        is_gssso: bool = False,
        api_version: str = API_VERSION,
        application: str = DEFAULT_APPLICATION,
        http_adapter: requests.adapters.HTTPAdapter = None,
        application_version: str = APP_VERSION,
    ) -> 'GsSession':
        """ Return an instance of the appropriate session type for the given credentials"""

        environment_or_domain = environment_or_domain.name if isinstance(
            environment_or_domain, Environment) else environment_or_domain

        if client_id is not None:
            if isinstance(scopes, str):
                scopes = (scopes, )

            scopes = tuple(
                set(itertools.chain(scopes, cls.Scopes.get_default())))

            return OAuth2Session(environment_or_domain,
                                 client_id,
                                 client_secret,
                                 scopes,
                                 api_version=api_version,
                                 application=application,
                                 http_adapter=http_adapter)
        elif token:
            if is_gssso:
                try:
                    return PassThroughGSSSOSession(environment_or_domain,
                                                   token,
                                                   api_version=api_version,
                                                   application=application,
                                                   http_adapter=http_adapter)
                except NameError:
                    raise MqUninitialisedError(
                        'This option requires gs_quant_internal to be installed'
                    )
            else:
                return PassThroughSession(environment_or_domain,
                                          token,
                                          api_version=api_version,
                                          application=application,
                                          http_adapter=http_adapter)
        else:
            try:
                return KerberosSession(environment_or_domain,
                                       api_version=api_version,
                                       http_adapter=http_adapter,
                                       application_version=application_version)
            except NameError:
                raise MqUninitialisedError(
                    'Must specify client_id and client_secret')
Example #3
0
    def current(cls):
        """
        The current instance of this context
        """
        current = next(iter(cls.path), cls.default)
        if current is None:
            raise MqUninitialisedError('{} is not initialised'.format(cls.__name__))

        return current
    def current(cls) -> 'ContextBase':
        """
        The current instance of this context
        """
        current = getattr(thread_local, '{}_current'.format(cls.__name__), None) or cls.default
        if current is None:
            raise MqUninitialisedError('{} is not initialised'.format(cls.__name__))

        return current
Example #5
0
    def current(cls):
        """
        The current instance of this context
        """
        path = cls.path
        current = cls.__default if not path else next(iter(path))
        if current is None:
            raise MqUninitialisedError('{} is not initialised'.format(
                cls.__name__))

        return current
Example #6
0
 def __raise_initialization_error(self, action_msg: str):
     raise MqUninitialisedError(
         f'Basket must be initialized with some identifier to {action_msg}')