Ejemplo n.º 1
0
    def __init__(self, service, environment=config.get_default_environ(),
                 base_path=None, token=None, app_name=None):
        self.environment = environment

        self.base_url = config.get_service_url(environment, service)
        if base_path is not None:
            self.base_url = slash_join(self.base_url, base_path)

        # setup the basics for wrapping a Requests Session
        # including basics for internal header dict
        self._session = requests.Session()
        self._headers = {
            'Accept': 'application/json',
            'User-Agent': self.BASE_USER_AGENT
        }

        # load a token for the client's service if it is not given as a param
        # assign the result
        if not token:
            token = self.config_load_token()
        self.set_token(token)

        # verify SSL? Usually true
        self._verify = config.get_ssl_verify(environment)

        # set application name if given
        self.app_name = None
        if app_name is not None:
            self.set_app_name(app_name)
Ejemplo n.º 2
0
    def __init__(self, service, environment=config.get_default_environ(), base_path=None, token=None, app_name=None):
        self.environment = environment

        self.base_url = config.get_service_url(environment, service)
        if base_path is not None:
            self.base_url = slash_join(self.base_url, base_path)

        # setup the basics for wrapping a Requests Session
        # including basics for internal header dict
        self._session = requests.Session()
        self._headers = {"Accept": "application/json", "User-Agent": self.BASE_USER_AGENT}

        # load a token for the client's service if it is not given as a param
        # assign the result
        if not token:
            token = self.config_load_token()
        self.set_token(token)

        # verify SSL? Usually true
        self._verify = config.get_ssl_verify(environment)

        # set application name if given
        self.app_name = None
        if app_name is not None:
            self.set_app_name(app_name)
Ejemplo n.º 3
0
 def __init__(self,
              environment=config.get_default_environ(),
              token=None,
              app_name=None):
     BaseClient.__init__(self,
                         "auth",
                         environment,
                         token=token,
                         app_name=app_name)
Ejemplo n.º 4
0
 def __init__(self,
              environment=config.get_default_environ(),
              token=None,
              app_name=None):
     BaseClient.__init__(self,
                         "transfer",
                         environment,
                         "/v0.10/",
                         token=token,
                         app_name=None)
Ejemplo n.º 5
0
    def __init__(self, service, environment=None,
                 base_path=None, authorizer=None, app_name=None):
        # get the fully qualified name of the client class, so that it's a
        # child of globus_sdk
        self.logger = ClientLogAdapter(
            logging.getLogger(self.__module__ + '.' + self.__class__.__name__),
            {'client': self})
        self.logger.info('Creating client of type {} for service "{}"'
                         .format(type(self), service))
        # if restrictions have been placed by a child class on the allowed
        # authorizer types, make sure we are not in violation of those
        # constraints
        if self.allowed_authorizer_types is not None and (
                authorizer is not None and
                type(authorizer) not in self.allowed_authorizer_types):
            self.logger.error("{} doesn't support authorizer={}"
                              .format(type(self), type(authorizer)))
            raise ValueError(
                ("{0} can only take authorizers from {1}, "
                 "but you have provided {2}").format(
                    type(self), self.allowed_authorizer_types,
                    type(authorizer)))

        # defer this default until instantiation time so that logging can
        # capture the execution of the config load
        if environment is None:
            environment = config.get_default_environ()

        self.environment = environment
        self.authorizer = authorizer

        self.base_url = config.get_service_url(environment, service)
        if base_path is not None:
            self.base_url = slash_join(self.base_url, base_path)

        # setup the basics for wrapping a Requests Session
        # including basics for internal header dict
        self._session = requests.Session()
        self._headers = {
            'Accept': 'application/json',
            'User-Agent': self.BASE_USER_AGENT
        }

        # verify SSL? Usually true
        self._verify = config.get_ssl_verify(environment)

        # set application name if given
        self.app_name = None
        if app_name is not None:
            self.set_app_name(app_name)
Ejemplo n.º 6
0
    def __init__(self, authorizer=None, **kwargs):
        if authorizer is None:
            # TODO: remove; this is a temporary backwards compatibility hack
            access_token = config.get_transfer_token(
                kwargs.get('environment', config.get_default_environ()))
            if access_token is not None:
                logger.warn(('Using deprecated config token. '
                             'Switch to use of AccessTokenAuthorizer'))
                authorizer = AccessTokenAuthorizer(access_token)

        BaseClient.__init__(self,
                            "transfer",
                            base_path="/v0.10/",
                            authorizer=authorizer,
                            **kwargs)
Ejemplo n.º 7
0
    def __init__(self, client_id=None, authorizer=None, **kwargs):
        self.client_id = client_id

        # an AuthClient may contain a GlobusOAuth2FlowManager in order to
        # encapsulate the functionality of various different types of flow
        # managers
        self.current_oauth2_flow_manager = None

        if authorizer is None:
            # TODO: remove; this is a temporary backwards compatibility hack
            access_token = config.get_auth_token(
                kwargs.get('environment', config.get_default_environ()))
            if access_token is not None:
                logger.warn(('Using deprecated config token. '
                             'Switch to use of AccessTokenAuthorizer'))
                authorizer = AccessTokenAuthorizer(access_token)

        BaseClient.__init__(self, "auth", authorizer=authorizer, **kwargs)
Ejemplo n.º 8
0
    def __init__(self, service, environment=config.get_default_environ(),
                 base_path=None):
        self.environment = environment
        self.base_url = config.get_service_url(environment, service)
        if base_path is not None:
            self.base_url = slash_join(self.base_url, base_path)
        self._session = requests.Session()
        self._headers = dict(Accept="application/json")
        self._auth = None

        # potentially add an Authorization header, if a token is specified
        auth_token = config.get_auth_token(environment)
        if auth_token:
            warnings.warn(
                ('Providing raw Auth Tokens is not recommended, and is slated '
                 'for deprecation. If you use this feature, be ready to '
                 'transition to using a new authentication mechanism after we '
                 'announce its availability.'),
                PendingDeprecationWarning)
            self.set_auth_token(auth_token)

        self._verify = config.get_ssl_verify(environment)
Ejemplo n.º 9
0
    def __init__(self,
                 service,
                 environment=None,
                 base_url=None,
                 base_path=None,
                 authorizer=None,
                 app_name=None,
                 http_timeout=None,
                 *args,
                 **kwargs):
        self._init_logger_adapter()
        self.logger.info('Creating client of type {} for service "{}"'.format(
            type(self), service))
        # if restrictions have been placed by a child class on the allowed
        # authorizer types, make sure we are not in violation of those
        # constraints
        if self.allowed_authorizer_types is not None and (
                authorizer is not None
                and type(authorizer) not in self.allowed_authorizer_types):
            self.logger.error("{} doesn't support authorizer={}".format(
                type(self), type(authorizer)))
            raise exc.GlobusSDKUsageError(
                ("{0} can only take authorizers from {1}, "
                 "but you have provided {2}").format(
                     type(self), self.allowed_authorizer_types,
                     type(authorizer)))

        # defer this default until instantiation time so that logging can
        # capture the execution of the config load
        if environment is None:
            environment = config.get_default_environ()

        self.environment = environment
        self.authorizer = authorizer

        if base_url is None:
            self.base_url = config.get_service_url(environment, service)
        else:
            self.base_url = base_url
        if base_path is not None:
            self.base_url = slash_join(self.base_url, base_path)

        # setup the basics for wrapping a Requests Session
        # including basics for internal header dict
        self._session = requests.Session()
        self._headers = {
            'Accept': 'application/json',
            'User-Agent': self.BASE_USER_AGENT
        }

        # verify SSL? Usually true
        self._verify = config.get_ssl_verify(environment)
        # HTTP connection timeout
        # this is passed verbatim to `requests`, and we therefore technically
        # support a tuple for connect/read timeouts, but we don't need to
        # advertise that... Just declare it as an float value
        if http_timeout is None:
            http_timeout = config.get_http_timeout(environment)
        self._http_timeout = http_timeout
        # handle -1 by passing None to requests
        if self._http_timeout == -1:
            self._http_timeout = None

        # set application name if given
        self.app_name = None
        if app_name is not None:
            self.set_app_name(app_name)
Ejemplo n.º 10
0
 def __init__(self, environment=config.get_default_environ()):
     BaseClient.__init__(self, "auth", environment)
Ejemplo n.º 11
0
 def __init__(self, environment=config.get_default_environ(),
              token=None, app_name=None):
     BaseClient.__init__(self, "transfer", environment, "/v0.10/",
                         token=token, app_name=None)
Ejemplo n.º 12
0
 def __init__(self, environment=config.get_default_environ()):
     BaseClient.__init__(self, "nexus", environment)
     # warn that this class is deprecated upon initialization
     warnings.warn(self._DEPRECATION_TEXT, PendingDeprecationWarning)
Ejemplo n.º 13
0
 def __init__(self, environment=config.get_default_environ(), token=None, app_name=None):
     BaseClient.__init__(self, "auth", environment, token=token, app_name=app_name)