def __call__(self, env, start_response):
     """ Handle incoming request. Transform. And send downstream. """
     request = Request(env)
     if env['KEYSTONE_API_VERSION'] in ['1.0', '1.1']:
         params = {
             "auth": {
                 "passwordCredentials": {
                     "username": utils.get_auth_user(request),
                     "password": utils.get_auth_key(request)
                 }
             }
         }
         #Make request to keystone
         new_request = Request.blank('/tokens')
         new_request.method = 'POST'
         new_request.headers['Content-type'] = 'application/json'
         new_request.accept = 'text/json'
         new_request.body = json.dumps(params)
         response = new_request.get_response(self.app)
         #Handle failures.
         if not str(response.status).startswith('20'):
             return response(env, start_response)
         headers = self.__transform_headers(json.loads(response.body))
         resp = utils.send_legacy_result(204, headers)
         return resp(env, start_response)
     else:
         # Other calls pass to downstream WSGI component
         return self.app(env, start_response)
Example #2
0
 def __call__(self, env, start_response):
     """ Handle incoming request. Transform. And send downstream. """
     self.start_response = start_response
     self.env = env
     self.request = Request(env)
     if self.request.path.startswith('/v1.0'
             ) or self.request.path.startswith('/v1.1'):
         params = {"passwordCredentials":
             {"username": utils.get_auth_user(self.request),
                 "password": utils.get_auth_key(self.request)}}
         #Make request to keystone
         new_request = Request.blank('/v2.0/tokens')
         new_request.method = 'POST'
         new_request.headers['Content-type'] = 'application/json'
         new_request.accept = 'text/json'
         new_request.body = json.dumps(params)
         response = new_request.get_response(self.app)
         #Handle failures.
         if not str(response.status).startswith('20'):
             return response(env, start_response)
         headers = self.__transform_headers(
             json.loads(response.body))
         resp = utils.send_legacy_result(204, headers)
         return resp(env, start_response)
     else:
         # Other calls pass to downstream WSGI component
         return self.app(self.env, self.start_response)
 def __call__(self, env, start_response):
     """ Handle incoming request. Transform. And send downstream. """
     logger.debug("Entering AuthProtocol.__call__")
     request = Request(env)
     if env.get('KEYSTONE_API_VERSION') in ['1.0', '1.1']:
         logger.debug("This is a v%s call, so taking over" %
                      env.get('KEYSTONE_API_VERSION'))
         params = {"auth": {"passwordCredentials":
             {"username": utils.get_auth_user(request),
                 "password": utils.get_auth_key(request)}}}
         #Make request to keystone
         new_request = Request.blank('/tokens')
         new_request.method = 'POST'
         new_request.headers['Content-type'] = 'application/json'
         new_request.accept = 'application/json'
         new_request.body = json.dumps(params)
         logger.debug("Sending v2.0-formatted request downstream")
         response = new_request.get_response(self.app)
         logger.debug("Got back %s" % response.status)
         #Handle failures.
         if not str(response.status).startswith('20'):
             return response(env, start_response)
         headers = self.__transform_headers(
             json.loads(response.body))
         logger.debug("Transformed the response. Responding to v1.x client")
         resp = utils.send_legacy_result(204, headers)
         return resp(env, start_response)
     else:
         logger.debug("Not a v1.0/v1.1 call, so passing downstream")
         return self.app(env, start_response)
Example #4
0
 def __call__(self, env, start_response):
     """ Handle incoming request. Transform. And send downstream. """
     logger.debug("Entering AuthProtocol.__call__")
     request = Request(env)
     if env.get('KEYSTONE_API_VERSION') in ['1.0', '1.1']:
         logger.debug("This is a v%s call, so taking over" %
                      env.get('KEYSTONE_API_VERSION'))
         params = {"auth": {"passwordCredentials":
             {"username": utils.get_auth_user(request),
                 "password": utils.get_auth_key(request)}}}
         #Make request to keystone
         new_request = Request.blank('/tokens')
         new_request.method = 'POST'
         new_request.headers['Content-type'] = 'application/json'
         new_request.accept = 'application/json'
         new_request.body = json.dumps(params)
         logger.debug("Sending v2.0-formatted request downstream")
         response = new_request.get_response(self.app)
         logger.debug("Got back %s" % response.status)
         #Handle failures.
         if not str(response.status).startswith('20'):
             return response(env, start_response)
         headers = self.__transform_headers(
             json.loads(response.body))
         logger.debug("Transformed the response. Responding to v1.x client")
         resp = utils.send_legacy_result(204, headers)
         return resp(env, start_response)
     else:
         logger.debug("Not a v1.0/v1.1 call, so passing downstream")
         return self.app(env, start_response)
Example #5
0
    def authenticate(self, req):
        self.request = req

        creds = auth.PasswordCredentials(utils.get_auth_user(req), utils.get_auth_key(req), None)

        """HTTP/1.1 204 No Content
        Date: Mon, 12 Nov 2007 15:32:21 GMT
        X-Storage-Url: https://storage.clouddrive.com/v1/CF_xer7_34
        X-CDN-Management-Url: https://cdn.clouddrive.com/v1/CF_xer7_34
        X-Auth-Token: eaaafd18-0fed-4b3a-81b4-663c99ec1cbb
        Content-Length: 0
        Content-Type: text/plain; charset=UTF-8"""

        result = service.authenticate(creds)
        headers = {"X-Auth-Token": result.token.token_id}
        return utils.send_legacy_result(204, headers)