Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _get_resource(self, item):
"""
:param item: name of the resource to return
:return: :class:`Resource`
"""
resource = self.swagger_spec.resources.get(item)
if not resource:
raise AttributeError(
'Resource {0} not found. Available resources: {1}'
.format(item, ', '.join(dir(self))))
# Wrap bravado-core's Resource and Operation objects in order to
# execute a service call via the http_client.
return ResourceDecorator(resource, self.__also_return_response)def __getattr__(self, attr):
return RequestFactory.Resource(
self._factory.client,
ResourceDecorator(self._factory.resources[attr]))Returns
-------
Resource
instance that has attributes for methods available.
"""
path_spec = self.client.origin_spec['paths'].get(path)
if not path_spec:
raise RuntimeError("no path found for: %s" % path)
get_for_meth = self.client.swagger_spec.get_op_for_request
rsrc = BravadoResource(name=path, ops={
method: get_for_meth(method, path)
for method in path_spec.keys()})
return RequestFactory.Resource(self.client, ResourceDecorator(rsrc))
def _get_resource(self, item):
"""
:param item: name of the resource to return
:return: :class:`Resource`
"""
resource = self.swagger_spec.resources.get(item)
if not resource:
raise AttributeError(
'Resource {0} not found. Available resources: {1}'
.format(item, ', '.join(dir(self))))
# Wrap bravado-core's Resource and Operation objects in order to
# execute a service call via the http_client.
return ResourceDecorator(resource, self.__also_return_response)def cache(self, cache):
self.http_client.cache = cache
def __getattr__(self, item):
resource = self.swagger_spec.resources.get(item)
if not resource:
raise AttributeError('Resource {0} not found. Available '
'resources: {1}'.format(item,
', '.join(dir(self))))
# Wrap bravado-core's Resource and Operation objects in order to
# execute a service call via the http_client.
return ESIResourceDecorator(resource)
class ESIResourceDecorator(ResourceDecorator):
"""
Extends ResourceDecorator to wrap operations with ESICallableOperation
"""
def __getattr__(self, name):
"""
:rtype: :class:`CallableOperation`
"""
return ESICallableOperation(getattr(self.resource, name))
def __eq__(self, other):
"""
:param other: instance to compare to
:type other: ESIResourceDecorator
:return: equality of instances
:rtype: bool'''
Some arguments don't properly display in the swagger specification so we have
to add them at runtime for the client to support them. This includes all payload
filters like payload__name=John. Normally payload__name wouldn't be found in the
spec and an error would be produced.
'''
def mockParam(name, op, swagger_spec):
param_spec = {'name': name, 'in': 'query',
'description': '', 'required': False, 'type': 'string'}
return bravado_core.param.Param(swagger_spec, op, param_spec)
class AetherDecorator(ResourceDecorator):
def __init__(self, resource, also_return_response=True, swagger_spec=None):
self.name = resource.name
# The only way to be able to form coherent exceptions is to catch these
# common types and wrap them in our own, exposing the status and error
# feeback from the API.
self.handled_exceptions = [
bravado.exception.HTTPBadRequest,
bravado.exception.HTTPBadGateway,
bravado.exception.HTTPNotFound,
bravado.exception.HTTPForbidden,
oauth2.rfc6749.errors.InvalidGrantError
]
# Errors in connection worthy of a retry
self.retry_exceptions = [
bravado.exception.BravadoTimeoutError,