Browse Source

[2641] Handle /users-exist API call in cmdctl

Note: There are no tests for any HTTP API calls in cmdctl. Adding this
framework as part of this bug would go way beyond the estimate.
I suggest creating another bug to go through cmdctl and add missing
unittests for the HTTP API.
Mukund Sivaraman 12 years ago
parent
commit
10c4a13810
1 changed files with 9 additions and 1 deletions
  1. 9 1
      src/bin/cmdctl/cmdctl.py.in

+ 9 - 1
src/bin/cmdctl/cmdctl.py.in

@@ -152,7 +152,9 @@ class SecureHTTPRequestHandler(http.server.BaseHTTPRequestHandler):
         self.session_id = self.headers.get('cookie')
         self.session_id = self.headers.get('cookie')
         rcode, reply = http.client.OK, []
         rcode, reply = http.client.OK, []
         if self._is_session_valid():
         if self._is_session_valid():
-            if self.path == '/login':
+            if self.path == '/users-exist':
+                rcode, reply = self._handle_users_exist()
+            elif self.path == '/login':
                 rcode, reply = self._handle_login()
                 rcode, reply = self._handle_login()
             elif self._is_user_logged_in():
             elif self._is_user_logged_in():
                 rcode, reply = self._handle_post_request()
                 rcode, reply = self._handle_post_request()
@@ -175,6 +177,12 @@ class SecureHTTPRequestHandler(http.server.BaseHTTPRequestHandler):
         else:
         else:
             return http.client.UNAUTHORIZED, error_info
             return http.client.UNAUTHORIZED, error_info
 
 
+    def _handle_users_exist(self):
+        if self.server.get_num_users() > 0:
+            return http.client.OK, True
+        else:
+            return http.client.OK, False
+
     def _check_user_name_and_pwd(self):
     def _check_user_name_and_pwd(self):
         '''Check user name and its password '''
         '''Check user name and its password '''
         length = self.headers.get('Content-Length')
         length = self.headers.get('Content-Length')