def session_factory(): auth_tokens = backend_client.api.exchangeApiToken( X_Neptune_Api_Token=api_token).response().result decoded_json_token = jwt.decode(auth_tokens.accessToken, options=_decoding_options) expires_at = decoded_json_token.get(u'exp') client_name = decoded_json_token.get(u'azp') refresh_url = u'{realm_url}/protocol/openid-connect/token'.format( realm_url=decoded_json_token.get(u'iss')) token = { u'access_token': auth_tokens.accessToken, u'refresh_token': auth_tokens.refreshToken, u'expires_in': expires_at - time.time() } session = OAuth2Session( client_id=client_name, token=token, auto_refresh_url=refresh_url, auto_refresh_kwargs={'client_id': client_name}, token_updater=_no_token_updater) session.verify = ssl_verify update_session_proxies(session, proxies) return session
def __init__(self, api_token=None, proxies=None): from neptune import ANONYMOUS, ANONYMOUS_API_TOKEN if api_token == ANONYMOUS: api_token = ANONYMOUS_API_TOKEN self.credentials = Credentials(api_token) ssl_verify = True if os.getenv("NEPTUNE_ALLOW_SELF_SIGNED_CERTIFICATE"): urllib3.disable_warnings() ssl_verify = False self._http_client = RequestsClient(ssl_verify=ssl_verify) update_session_proxies(self._http_client.session, proxies) config_api_url = self.credentials.api_url_opt or self.credentials.token_origin_address self._verify_host_resolution(config_api_url, self.credentials.token_origin_address) backend_client = self._get_swagger_client('{}/api/backend/swagger.json'.format(config_api_url)) self._client_config = self._create_client_config(self.credentials.api_token, backend_client) self._set_swagger_clients(self._client_config, config_api_url, backend_client) self.authenticator = self._create_authenticator(self.credentials.api_token, ssl_verify, proxies) self._http_client.authenticator = self.authenticator # This is not a top-level import because of circular dependencies from neptune import __version__ self.client_lib_version = __version__ user_agent = 'neptune-client/{lib_version} ({system}, python {python_version})'.format( lib_version=self.client_lib_version, system=platform.platform(), python_version=platform.python_version()) self._http_client.session.headers.update({'User-Agent': user_agent})
def session_factory(): try: auth_tokens = (backend_client.api.exchangeApiToken( X_Neptune_Api_Token=api_token).response().result) except HTTPUnauthorized: raise NeptuneInvalidApiTokenException() decoded_json_token = jwt.decode(auth_tokens.accessToken, options=_decoding_options) expires_at = decoded_json_token.get(u"exp") client_name = decoded_json_token.get(u"azp") refresh_url = u"{realm_url}/protocol/openid-connect/token".format( realm_url=decoded_json_token.get(u"iss")) token = { u"access_token": auth_tokens.accessToken, u"refresh_token": auth_tokens.refreshToken, u"expires_in": expires_at - time.time(), } session = OAuth2Session( client_id=client_name, token=token, auto_refresh_url=refresh_url, auto_refresh_kwargs={"client_id": client_name}, token_updater=_no_token_updater, ) session.verify = ssl_verify update_session_proxies(session, proxies) return session
def __init__(self, api_token=None, proxies=None): self._proxies = proxies # This is not a top-level import because of circular dependencies from neptune import __version__ self.client_lib_version = __version__ self.credentials = Credentials(api_token) ssl_verify = True if os.getenv("NEPTUNE_ALLOW_SELF_SIGNED_CERTIFICATE"): urllib3.disable_warnings() ssl_verify = False self._http_client = RequestsClient(ssl_verify=ssl_verify) # for session re-creation we need to keep an authenticator-free version of http client self._http_client_for_token = RequestsClient(ssl_verify=ssl_verify) user_agent = 'neptune-client/{lib_version} ({system}, python {python_version})'.format( lib_version=self.client_lib_version, system=platform.platform(), python_version=platform.python_version()) self._http_client.session.headers.update({'User-Agent': user_agent}) self._http_client_for_token.session.headers.update( {'User-Agent': user_agent}) update_session_proxies(self._http_client.session, proxies) update_session_proxies(self._http_client_for_token.session, proxies) config_api_url = self.credentials.api_url_opt or self.credentials.token_origin_address # We don't need to be able to resolve Neptune host if we use proxy if proxies is None: self._verify_host_resolution(config_api_url, self.credentials.token_origin_address) # this backend client is used only for initial configuration and session re-creation backend_client = self._get_swagger_client( '{}/api/backend/swagger.json'.format(config_api_url), self._http_client_for_token) self._client_config = self._create_client_config( self.credentials.api_token, backend_client) self._verify_version() self._set_swagger_clients(self._client_config) self.authenticator = self._create_authenticator( self.credentials.api_token, ssl_verify, proxies, backend_client) self._http_client.authenticator = self.authenticator
def __init__(self, auth_tokens, ssl_verify, proxies): super(NeptuneAuthenticator, self).__init__(host='') decoded_json_token = jwt.decode(auth_tokens.accessToken, verify=False) expires_at = decoded_json_token.get(u'exp') client_name = decoded_json_token.get(u'azp') refresh_url = u'{realm_url}/protocol/openid-connect/token'.format( realm_url=decoded_json_token.get(u'iss')) token = { u'access_token': auth_tokens.accessToken, u'refresh_token': auth_tokens.refreshToken, u'expires_in': expires_at - time.time() } session = OAuth2Session(client_id=client_name, token=token, auto_refresh_url=refresh_url, auto_refresh_kwargs={'client_id': client_name}, token_updater=_no_token_updater) session.verify = ssl_verify update_session_proxies(session, proxies) self.auth = NeptuneAuth(session)
def __init__(self, api_token=None, proxies=None): self._old_leaderboard_client = None self._new_leaderboard_client = None self._api_token = api_token self._proxies = proxies # This is not a top-level import because of circular dependencies from neptune import __version__ self.client_lib_version = __version__ self.credentials = Credentials(api_token) ssl_verify = True if os.getenv("NEPTUNE_ALLOW_SELF_SIGNED_CERTIFICATE"): urllib3.disable_warnings() ssl_verify = False self._http_client = RequestsClient( ssl_verify=ssl_verify, response_adapter_class=NeptuneResponseAdapter ) # for session re-creation we need to keep an authenticator-free version of http client self._http_client_for_token = RequestsClient( ssl_verify=ssl_verify, response_adapter_class=NeptuneResponseAdapter ) user_agent = ( "neptune-client/{lib_version} ({system}, python {python_version})".format( lib_version=self.client_lib_version, system=platform.platform(), python_version=platform.python_version(), ) ) self.http_client.session.headers.update({"User-Agent": user_agent}) self._http_client_for_token.session.headers.update({"User-Agent": user_agent}) update_session_proxies(self.http_client.session, proxies) update_session_proxies(self._http_client_for_token.session, proxies) config_api_url = ( self.credentials.api_url_opt or self.credentials.token_origin_address ) # We don't need to be able to resolve Neptune host if we use proxy if proxies is None: self._verify_host_resolution( config_api_url, self.credentials.token_origin_address ) # this backend client is used only for initial configuration and session re-creation self.backend_client = self._get_swagger_client( "{}/api/backend/swagger.json".format(config_api_url), self._http_client_for_token, ) self._client_config = self._create_client_config( api_token=self.credentials.api_token, backend_client=self.backend_client ) self._verify_version() self.backend_swagger_client = self._get_swagger_client( "{}/api/backend/swagger.json".format(self._client_config.api_url), self.http_client, ) self.authenticator = self._create_authenticator( api_token=self.credentials.api_token, ssl_verify=ssl_verify, proxies=proxies, backend_client=self.backend_client, ) self.http_client.authenticator = self.authenticator if sys.version_info >= (3, 7): try: # pylint: disable=no-member os.register_at_fork(after_in_child=self._handle_fork_in_child) except AttributeError: pass