Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def service_instance_status_error(context, error_code, job_id):
(service, instance, _, __) = decompose_job_id(job_id)
response = None
try:
response = context.paasta_api_client.service.status_instance(
instance=instance, service=service
).result()
except bexception.HTTPError as exc:
assert exc.status_code == int(error_code)
assert not response
http_client.set_realm_basic_auth(
host=url_info.netloc,
username=user,
password=pw,
realm=realm,
)
loader = Loader(http_client, request_headers=None)
try:
spec_url = _SPEC_URL.format(url)
LOG.debug(f'Loading schema from: {spec_url}')
spec_dict = loader.load_spec(spec_url)
except bravado.exception.HTTPForbidden as forb:
LOG.error('Could not authenticate with provided credentials')
raise forb
except (
bravado.exception.HTTPBadGateway,
bravado.exception.BravadoConnectionError
) as bgwe:
LOG.error('Server Unavailable')
raise bgwe
else:
LOG.debug(f'getting OIDC session on realm {realm}')
http_client = OauthClient()
http_client.set_oauth(
url_info.netloc,
keycloak_url or f'{server}/auth', realm,
user, pw, offline_token, endpoint_name)
spec_url = _SPEC_URL.format(f'{server}/{realm}/{endpoint_name}')
spec_dict = http_client.authenticator.get_spec(spec_url)
# We take this from the from_url class method of SwaggerClient
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,
bravado.exception.BravadoConnectionError
]
self.swagger_spec = swagger_spec
super(AetherDecorator, self).__init__(
resource, also_return_response)
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,
bravado.exception.BravadoConnectionError
]
self.swagger_spec = swagger_spec
super(AetherDecorator, self).__init__(
resource, also_return_response)
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,
bravado.exception.BravadoConnectionError
]
self.swagger_spec = swagger_spec
super(AetherDecorator, self).__init__(
resource, also_return_response)
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,
bravado.exception.BravadoConnectionError
]
self.swagger_spec = swagger_spec
super(AetherDecorator, self).__init__(
resource, also_return_response)
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,
bravado.exception.BravadoConnectionError
]
self.swagger_spec = swagger_spec
super(AetherDecorator, self).__init__(
resource, also_return_response)
resp_data = self._unmarshal_response(http_resp)
if self.model_response:
# if the caller wants the response data returned as a schema-object,
# then first get the class; and if one exists, then use the http response
# data to create the model object.
resp_cls = self.client.build.resp_class(
request=self, status_code=http_resp.status_code)
if resp_cls:
resp_data = resp_cls(**resp_data)
return resp_data, True
except bravado.exception.HTTPClientError as exc:
http_resp = exc.response
return (http_resp, str(http_resp), http_resp.text), False
all_buckets = retrieve_bucket_names(client)
if not bucket in all_buckets:
raise ValueError('bucket does not exist')
# check that dataset_key exists in bucket
# JEA comment:
# this is not going to scale well to millions of keys
# and an exception will already be thrown if the dataset key is not found
# I think this should be removed
#all_dataset_keys = client.ds_datasets.get_dataset_distinct_dataset_keys(bucket_name=bucket).result()
#if not dataset_key in all_dataset_keys:
# raise ValueError('dataset_key {0} does not exist in bucket {1}'.format(dataset_key, bucket))
try :
all_metadata = client.ds_datasets.get_bucket_dataset (bucket_name=bucket, dataset_key=dataset_key).result()
except bravado.exception.HTTPNotFound:
return None
file_type = all_metadata['distribution']['dataType']
if print_metadata:
pprint.pprint(all_metadata)
if return_metadata:
return all_metadata
if file_type == 'bz2':
# bz2. Read bz2 file in binary mode, then decompress to text. Return as dataframe.
fp = client.open_bucket_dataset (bucket, dataset_key, mode='b')
fp = bz2.open (fp, mode='rt')
dict_reader = csv.DictReader (fp)
table = []
i_row = 1