def __call__(self, env, start_response): """ Handle incoming request. Transform. And send downstream. """ request = Request(env) if 'KEYSTONE_API_VERSION' in env and \ env['KEYSTONE_API_VERSION'] == '2.0': if request.path.startswith("/tokens"): is_d5_request = False if request.method == "POST": try: auth_with_credentials = \ utils.get_normalized_request_content( D5AuthWithPasswordCredentials, request) # Convert request body to Diablo syntax if request.content_type == "application/xml": request.body = auth_with_credentials.to_xml() else: request.body = auth_with_credentials.to_json() is_d5_request = True except: pass if is_d5_request: response = request.get_response(self.app) #Handle failures. if not str(response.status).startswith('20'): return response(env, start_response) auth_data = utils.get_normalized_request_content( D5toDiabloAuthData, response) resp = utils.send_result(response.status_int, request, auth_data) return resp(env, start_response) else: # Pass through return self.app(env, start_response) elif request.method == "GET": if request.path.endswith("/endpoints"): # Pass through return self.app(env, start_response) else: response = request.get_response(self.app) #Handle failures. if not str(response.status).startswith('20'): return response(env, start_response) validate_data = utils.get_normalized_request_content( D5ValidateData, response) resp = utils.send_result(response.status_int, request, validate_data) return resp(env, start_response) # All other calls pass to downstream WSGI component return self.app(env, start_response)
def __call__(self, env, start_response): """ Handle incoming request. Transform. And send downstream. """ request = Request(env) if 'KEYSTONE_API_VERSION' in env and \ env['KEYSTONE_API_VERSION'] == '2.0': if request.path.startswith("/tokens"): is_d5_request = False if request.method == "POST": try: auth_with_credentials = \ utils.get_normalized_request_content( D5AuthWithPasswordCredentials, request) # Convert request body to Diablo syntax if request.content_type == "application/xml": request.body = auth_with_credentials.to_xml() else: request.body = auth_with_credentials.to_json() is_d5_request = True except: pass if is_d5_request: response = request.get_response(self.app) #Handle failures. if not str(response.status).startswith('20'): return response(env, start_response) auth_data = utils.get_normalized_request_content( D5toDiabloAuthData, response) resp = utils.send_result(response.status_int, request, auth_data) return resp(env, start_response) else: # Pass through return self.app(env, start_response) elif request.method == "GET": if request.path.endswith("/endpoints"): # Pass through return self.app(env, start_response) else: response = request.get_response(self.app) #Handle failures. if not str(response.status).startswith('20'): return response(env, start_response) validate_data = utils.get_normalized_request_content( D5ValidateData, response) resp = utils.send_result(response.status_int, request, validate_data) return resp(env, start_response) # All other calls pass to downstream WSGI component return self.app(env, start_response)
def __call__(self, env, start_response): """ Handle incoming request. Transform. And send downstream. """ request = Request(env) if request.path == "/extensions": if env['KEYSTONE_API_VERSION'] == '2.0': request = Request(env) response = request.get_response(self.app) if response.status_int == 200: if response.content_type == 'application/json': #load json for this extension from file thisextension = open(os.path.join( os.path.dirname(__file__), "extension.json")).read() thisextensionjson = json.loads(thisextension) #load json in response body = json.loads(response.body) extensionsarray = body["extensions"]["values"] #add this extension and return the response extensionsarray.append(thisextensionjson) newresp = Response( content_type='application/json', body=json.dumps(body)) return newresp(env, start_response) elif response.content_type == 'application/xml': #load xml for this extension from file thisextensionxml = etree.parse(os.path.join( os.path.dirname(__file__), "extension.xml")).getroot() #load xml being returned in response body = etree.fromstring(response.body) #add this extension and return the response body.append(thisextensionxml) newresp = Response( content_type='application/xml', body=etree.tostring(body)) return newresp(env, start_response) # return the response return response(env, start_response) #default action, bypass return self.app(env, start_response)
def __call__(self, env, start_response): """ Handle incoming request. Transform. And send downstream. """ request = Request(env) if request.path == "/extensions": if env['KEYSTONE_API_VERSION'] == '2.0': request = Request(env) response = request.get_response(self.app) if response.status_int == 200: if response.content_type == 'application/json': #load json for this extension from file thisextension = open(os.path.join( os.path.dirname(__file__), "extension.json")).read() thisextensionjson = json.loads(thisextension) #load json in response body = json.loads(response.body) extensionsarray = body["extensions"]["values"] #add this extension and return the response extensionsarray.append(thisextensionjson) newresp = Response( content_type='application/json', body=json.dumps(body)) return newresp(env, start_response) elif response.content_type == 'application/xml': #load xml for this extension from file thisextensionxml = etree.parse(os.path.join( os.path.dirname(__file__), "extension.xml")).getroot() #load xml being returned in response body = etree.fromstring(response.body) #add this extension and return the response body.append(thisextensionxml) newresp = Response( content_type='application/xml', body=etree.tostring(body)) return newresp(env, start_response) # return the response return response(env, start_response) #default action, bypass return self.app(env, start_response)