def _make_bravado_client(self): http_client = requests_client.RequestsClient() server_hostname = urlsplit(self._base_url).netloc http_client.authenticator = GssapiAuthenticator( server_hostname, principal=self._principal) try: api = SwaggerClient.from_url( self._spec_url, http_client=http_client, config=self._bravado_config, ) except (HTTPError, RequestException) as e: data = { "exc": e, "message": str(e), } if getattr(e, "status_code", None): data["status_code"] = e.status_code raise ClientError("error loading remote spec", errno.ECONNABORTED, data=data) except SwaggerValidationError as e: raise ClientError("schema validation failed", errno.EPROTO, data={"exc": e}) except ValueError as e: raise ClientError("remote data validation failed", errno.EPROTO, data={"exc": e}) return api
def esi_client_factory(token=None, datasource=None, spec_file=None, version=None, **kwargs): """ Generates an ESI client. :param token: :class:`esi.Token` used to access authenticated endpoints. :param datasource: Name of the ESI datasource to access. :param spec_file: Absolute path to a swagger spec file to load. :param version: Base ESI API version. Accepted values are 'legacy', 'latest', 'dev', or 'vX' where X is a number. :param kwargs: Explicit resource versions to build, in the form Character='v4'. Same values accepted as version. :return: :class:`bravado.client.SwaggerClient` If a spec_file is specified, specific versioning is not available. Meaning the version and resource version kwargs are ignored in favour of the versions available in the spec_file. """ client = requests_client.RequestsClient() if token or datasource: client.authenticator = TokenAuthenticator(token=token, datasource=datasource) api_version = version or app_settings.ESI_API_VERSION if spec_file: return read_spec(spec_file, http_client=client) else: spec = build_spec(api_version, http_client=client, **kwargs) return SwaggerClient(spec)
def get_spec(name, http_client=None, config=None): """ :param name: Name of the revision of spec, eg latest or v4 :param http_client: Requests client used for retrieving specs :param config: Spec configuration - see Spec.CONFIG_DEFAULTS :return: :class:`bravado_core.spec.Spec` """ http_client = http_client or requests_client.RequestsClient() def load_spec(): loader = Loader(http_client) return loader.load_spec(build_spec_url(name)) spec_dict = cache.get_or_set(build_cache_name(name), load_spec, app_settings.ESI_SPEC_CACHE_DURATION) config = dict(CONFIG_DEFAULTS, **(config or {})) return Spec.from_dict(spec_dict, build_spec_url(name), http_client, config)
def esi_client_factory( token=None, datasource=None, spec_file=None, version=None, **kwargs ): """ Generates an ESI client. :param token: :class:`esi.Token` used to access authenticated endpoints. :param datasource: Name of the ESI datasource to access. :param spec_file: Absolute path to a swagger spec file to load. :param version: Base ESI API version. Accepted values are 'legacy', 'latest', 'dev', or 'vX' where X is a number. :param kwargs: Explicit resource versions to build, in the form Character='v4'. Same values accepted as version. :return: :class:`bravado.client.SwaggerClient` If a spec_file is specified, specific versioning is not available. Meaning the version and resource version kwargs are ignored in favour of the versions available in the spec_file. """ if app_settings.ESI_INFO_LOGGING_ENABLED: logger.info('Generating an ESI client...') client = requests_client.RequestsClient() my_http_adapter = HTTPAdapter( pool_maxsize=app_settings.ESI_CONNECTION_POOL_MAXSIZE, max_retries=app_settings.ESI_CONNECTION_ERROR_MAX_RETRIES ) client.session.mount('https://', my_http_adapter) if token or datasource: client.authenticator = TokenAuthenticator(token=token, datasource=datasource) api_version = version or app_settings.ESI_API_VERSION if spec_file: return read_spec(spec_file, http_client=client) else: spec = build_spec(api_version, http_client=client, **kwargs) return SwaggerClient(spec)