Exemple #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
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
Exemple #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
Exemple #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()
Exemple #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')
Exemple #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()
 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')
 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')