Ejemplo n.º 1
0
 def restore_endpoints(self, environ, start_response):
     self.service_dir_client.set_all_endpoints(
             environment=ENVIRONMENT,
             endpoints=self.original_endpoints)
     return http_response(
         start_response,
         body=json.dumps(self.original_endpoints))
Ejemplo n.º 2
0
 def wsgi_app_post_auth(self, environ, start_response):
     username = environ.get('REMOTE_USER', None)
     if username is not None:
         raw_requested_fib = self.parse_request(environ)
         status, body = self.controller_client.generate_response(
             raw_requested_fib=raw_requested_fib,
             username=username)
     else:
         status, body = ["401 UNAUTHENTICATED", "Please log in"]
     return http_response(start_response, status, body)
Ejemplo n.º 3
0
 def route_request(self, environ, start_response):
     """ overwrite host and port in environ
     before invoking wsgi proxy """
     requested_path = environ['PATH_INFO']
     if requested_path in self.routes:
         real_url = self.routes[requested_path][1]
         environ['HTTP_HOST'] = real_url.netloc
         response = self.recording_proxy(environ, start_response)
         log.info('proxied %s' % self.routes[requested_path][0])
         return response
     else:
         log.error('No souch route: %s' % requested_path)
         return http_response(start_response, "404 NOT FOUND")
Ejemplo n.º 4
0
 def route_request(self, environ, start_response):
     """ overwrite host and port in environ
     before invoking wsgi proxy """
     requested_path = environ['PATH_INFO']
     if requested_path in self.routes:
         real_url = self.routes[requested_path][1]
         environ['HTTP_HOST'] = real_url.netloc
         response = self.recording_proxy(environ, start_response)
         log.info('proxied %s' % self.routes[requested_path][0])
         return response
     else:
         log.error('No souch route: %s' % requested_path)
         return http_response(start_response, "404 NOT FOUND")
Ejemplo n.º 5
0
class Server(RPCBase):

    NAME = "unknown"
    SENTRY_DSN = DEFAULT_SENTRY_DSN

    def __init__(self,
                 environment=DEFAULT_ENVIRONMENT,
                 name=None,
                 service_dir_client=None,
                 register=True):
        self.environment = environment
        self.name = name or self.NAME
        self.set_environment(self.environment)
        self.set_server_name(self.name)
        self.set_service_dir_client(service_dir_client)
        self.server_init()
        if register:
            self.register_server()

    def server_init(self):
        pass

    def register_server(self):
        environment = dict_get(get_server_meta(), ["environment"])
        service = dict_get(get_server_meta(), ["name"])
        endpoint_parts = {
            'port': get_server_port(),
            'path': "api/%s" % self.name,
        }
        self.service_dir_client.set_endpoint(environment=environment,
                                             service=service,
                                             endpoint_parts=endpoint_parts)

    def wsgi_app(self, environ, start_response):
        self.set_environment(self.environment)
        self.set_server_name(self.name)

        method, args, request_meta = self.decode_arguments(environ)
        set_request_meta(request_meta)
        self.log_rpc(get_request_meta().get('source', 'unknown'), self.name,
                     method, args)
        try:
            result = getattr(self, method)(**args)
            body = self.encode_result(result)
        except Exception, e:
            body = self.encode_exception(traceback.format_exc())
        response = http_response(start_response, body=body)
        # clear request meta
        set_request_meta({})
        return response
Ejemplo n.º 6
0
 def restore_endpoints(self, environ, start_response):
     self.service_dir_client.set_all_endpoints(
         environment=ENVIRONMENT, endpoints=self.original_endpoints)
     return http_response(start_response,
                          body=json.dumps(self.original_endpoints))
Ejemplo n.º 7
0
 def dump_session(self, environ, start_response):
     return http_response(start_response, body=self.get_session_json())
Ejemplo n.º 8
0
 def dump_session(self, environ, start_response):
     return http_response(
         start_response,
         body=self.get_session_json())