Exemplo n.º 1
0
def get_user_id_from_hatohol_server(session_id):
    server = hatoholserver.get_address()
    port = hatoholserver.get_port()
    path = '/user/me'
    url = 'http://%s:%d%s' % (server, port, path)
    hdrs = {hatohol_def.FACE_REST_SESSION_ID_HEADER_NAME: session_id}
    req = urllib2.Request(url, headers=hdrs)
    response = urllib2.urlopen(req)
    body = response.read()    
    user_info = json.loads(body)
    user_id = user_info['users'][0]['userId']
    return user_id
Exemplo n.º 2
0
def get_user_id_from_hatohol_server(session_id):
    server = hatoholserver.get_address()
    port = hatoholserver.get_port()
    path = '/user/me'
    url = 'http://%s:%d%s' % (server, port, path)
    hdrs = {hatohol_def.FACE_REST_SESSION_ID_HEADER_NAME: session_id}
    req = urllib2.Request(url, headers=hdrs)
    response = urllib2.urlopen(req)
    body = response.read()    
    user_info = json.loads(body)
    user_id = user_info['users'][0]['userId']
    return user_id
Exemplo n.º 3
0
def get_user_id_from_hatohol_server(request):
    if hatoholserver.SESSION_NAME_META not in request.META:
        raise NoHatoholSession
    session_id = request.META[hatoholserver.SESSION_NAME_META]
    server = hatoholserver.get_address()
    port = hatoholserver.get_port()
    path = '/user/me'
    url = 'http://%s:%d%s' % (server, port, path)
    hdrs = {hatohol_def.FACE_REST_SESSION_ID_HEADER_NAME: session_id}
    req = urllib2.Request(url, headers=hdrs)
    response = urllib2.urlopen(req)
    body = response.read()
    user_info = json.loads(body)
    user_id = user_info['users'][0]['userId']
    if user_id is None:
        raise NoHatoholUser
    return user_id
Exemplo n.º 4
0
 def run(self):
     addr = hatoholserver.get_address()
     port = hatoholserver.get_port()
     self._server = HTTPServer((addr, port), self._emulation_handler)
     self._setup_done_evt.set()
     self._server.serve_forever()
Exemplo n.º 5
0
 def test_get_address_with_env(self):
     os.environ[hatoholserver.SERVER_ADDR_ENV_NAME] = 'foo.example.com'
     hatoholserver._setup()  # Update the internal information
     addr = self.assertEqual(hatoholserver.get_address(), 'foo.example.com')
Exemplo n.º 6
0
 def test_get_default_address(self):
     if os.getenv(hatoholserver.SERVER_ADDR_ENV_NAME):
         del os.environ[hatoholserver.SERVER_ADDR_ENV_NAME]
     hatoholserver._setup()  # Update the internal information
     addr = self.assertEqual(hatoholserver.get_address(), 'localhost')
 def run(self):
     addr = hatoholserver.get_address()
     port = hatoholserver.get_port()
     self._server = HTTPServer((addr, port), self._emulation_handler)
     self._setup_done_evt.set()
     self._server.serve_forever()
Exemplo n.º 8
0
 def test_get_address_with_env(self):
     os.environ[hatoholserver.SERVER_ADDR_ENV_NAME] = 'foo.example.com'
     hatoholserver._setup() # Update the internal information
     addr = self.assertEqual(hatoholserver.get_address(), 'foo.example.com')
Exemplo n.º 9
0
 def test_get_default_address(self):
     if os.getenv(hatoholserver.SERVER_ADDR_ENV_NAME):
         del os.environ[hatoholserver.SERVER_ADDR_ENV_NAME]
     hatoholserver._setup() # Update the internal information
     addr = self.assertEqual(hatoholserver.get_address(), 'localhost')