def get_api_version(self): if self.__api_version is not None: return self.__api_version with Querier.__lock: if self.__api_version is not None: return self.__api_version def f(url): return requests.get(url, headers={API_KEY_HEADER: self.__api_key}) response = self.__send_request_helper(API_VERSION, 'GET', f, len(self.__hosts)) cdi_supported_by_server = response['versions'] api_version = find_max_version(cdi_supported_by_server, SUPPORTED_CDI_VERSIONS) if api_version is None: raise_general_exception( 'The running SuperTokens core version is not compatible with this Flask SDK. ' 'Please visit https://supertokens.io/docs/community/compatibility to find the ' 'right versions') self.__api_version = api_version return self.__api_version
def __send_request_helper(self, path, method, http_function, no_of_tries): if no_of_tries == 0: raise_general_exception('No SuperTokens core available to query') try: current_host = self.__hosts[self.__last_tried_index] self.__last_tried_index += 1 self.__last_tried_index %= len(self.__hosts) url = current_host + path response = http_function(url) if ('SUPERTOKENS_ENV' in environ) and (environ['SUPERTOKENS_ENV'] == 'testing'): self.__hosts_alive_for_testing.add(current_host) if is_4xx_error(response.status_code) or is_5xx_error( response.status_code): raise_general_exception( 'SuperTokens core threw an error for a ' + method + ' request to path: ' + path + ' with status code: ' + str(response.status_code) + ' and message: ' + response.text) try: return response.json() except JSONDecodeError: return response.text except requests.exceptions.ConnectionError: return self.__send_request_helper(path, method, http_function, no_of_tries - 1) except Exception as e: raise_general_exception(e)
def reset(): if ('SUPERTOKENS_ENV' not in environ) or (environ['SUPERTOKENS_ENV'] != 'testing'): raise_general_exception( 'calling testing function in non testing env') CookieConfig.__instance = None
def get_hosts_alive_for_testing(self): if ('SUPERTOKENS_ENV' not in environ) or (environ['SUPERTOKENS_ENV'] != 'testing'): raise_general_exception( 'calling testing function in non testing env') return self.__hosts_alive_for_testing