def handle_get_user(self, req):
        """Handles the GET v2/<account>/<user> call for getting user information.
        Can only be called by an account .admin.

        On success, a JSON dict will be returned as described::

            {"groups": [  # List of groups the user is a member of
                {"name": "<act>:<usr>"},
                    # The first group is a unique user identifier
                {"name": "<account>"},
                    # The second group is the auth account name
                {"name": "<additional-group>"}
                    # There may be additional groups, .admin being a special
                    # group indicating an account admin and .reseller_admin
                    # indicating a reseller admin.
             ],
             "auth": "plaintext:<key>"
             # The auth-type and key for the user; currently only plaintext is
             # implemented.
            }

        For example::

            {"groups": [{"name": "test:tester"}, {"name": "test"},
                        {"name": ".admin"}],
             "auth": "plaintext:testing"}

        If the <user> in the request is the special user `.groups`, the JSON
        dict will contain a single key of `groups` whose value is a list of
        dicts representing the active groups within the account. Each dict
        currently has the single key `name`. For example::

            {"groups": [{"name": ".admin"}, {"name": "test"},
                        {"name": "test:tester"}, {"name": "test:tester3"}]}

        :param req: The swob.Request to process.
        :returns: swob.Response, 2xx on success with a JSON dictionary as
                  explained above.
        """
        account = req.path_info_pop()
        user = req.path_info_pop()
        if req.path_info or not account or account[0] == '.' or not user or \
                (user[0] == '.' and user != '.groups'):
            return HTTPBadRequest(request=req)
        if not self.is_account_admin(req, account):
            return self.denied_response(req)

        # get information for each user for the specified
        # account and create a list of all groups that the users
        # are part of
        if user == '.groups':
            # TODO(gholt): This could be very slow for accounts with a really
            # large number of users. Speed could be improved by concurrently
            # requesting user group information. Then again, I don't *know*
            # it's slow for `normal` use cases, so testing should be done.
            groups = set()
            marker = ''
            while True:
                path = '/v1/%s?format=json&marker=%s' % (quote('%s/%s' %
                    (self.auth_account, account)), quote(marker))
                resp = self.make_pre_authed_request(
                    req.environ, 'GET', path).get_response(self.app)
                if resp.status_int == 404:
                    return HTTPNotFound(request=req)
                if resp.status_int // 100 != 2:
                    raise Exception('Could not list in main auth account: '
                                    '%s %s' % (path, resp.status))
                sublisting = json.loads(resp.body)
                if not sublisting:
                    break
                for obj in sublisting:
                    if obj['name'][0] != '.':

                        # get list of groups for each user
                        user_json = self.get_user_detail(req, account,
                                                         obj['name'])
                        if user_json is None:
                            raise Exception('Could not retrieve user object: '
                                            '%s:%s %s' % (account, user, 404))
                        groups.update(
                            g['name'] for g in json.loads(user_json)['groups'])
                marker = sublisting[-1]['name'].encode('utf-8')
            body = json.dumps(
                {'groups': [{'name': g} for g in sorted(groups)]})
        else:
            # get information for specific user,
            # if user doesn't exist, return HTTPNotFound
            body = self.get_user_detail(req, account, user)
            if body is None:
                return HTTPNotFound(request=req)

            display_groups = [g['name'] for g in json.loads(body)['groups']]
            if ('.admin' in display_groups and
                not self.is_reseller_admin(req)) or \
               ('.reseller_admin' in display_groups and
                    not self.is_super_admin(req)):
                    return self.denied_response(req)
        return Response(body=body, content_type=CONTENT_TYPE_JSON)
def handle_get_user ( self , req ) : account = req . path_info_pop ( ) user = req . path_info_pop ( ) if req . path_info or not account or account [ 0 ] == '.' or not user or ( user [ 0 ] == '.' and user != '.groups' ) : return HTTPBadRequest ( request = req ) if not self . is_account_admin ( req , account ) : return self . denied_response ( req ) if user == '.groups' : groups = set ( ) marker = '' while True : path = '/v1/%s?format=json&marker=%s' % ( quote ( '%s/%s' % ( self . auth_account , account ) ) , quote ( marker ) ) resp = self . make_pre_authed_request ( req . environ , 'GET' , path ) . get_response ( self . app ) if resp . status_int == 404 : return HTTPNotFound ( request = req ) if resp . status_int // 100 != 2 : raise Exception ( 'Could not list in main auth account: ' '%s %s' % ( path , resp . status ) ) sublisting = json . loads ( resp . body ) if not sublisting : break for obj in sublisting : if obj [ 'name' ] [ 0 ] != '.' : user_json = self . get_user_detail ( req , account , obj [ 'name' ] ) if user_json is None : raise Exception ( 'Could not retrieve user object: ' '%s:%s %s' % ( account , user , 404 ) ) groups . update ( g [ 'name' ] for g in json . loads ( user_json ) [ 'groups' ] ) marker = sublisting [ - 1 ] [ 'name' ] . encode ( 'utf-8' ) body = json . dumps ( { 'groups' : [ { 'name' : g } for g in sorted ( groups ) ] } ) else : body = self . get_user_detail ( req , account , user ) if body is None : return HTTPNotFound ( request = req ) display_groups = [ g [ 'name' ] for g in json . loads ( body ) [ 'groups' ] ] if ( '.admin' in display_groups and not self . is_reseller_admin ( req ) ) or ( '.reseller_admin' in display_groups and not self . is_super_admin ( req ) ) : return self . denied_response ( req ) return Response ( body = body , content_type = CONTENT_TYPE_JSON )
Handles the GET v2/<account>/<user> call for getting user information.
        Can only be called by an account .admin.

        On success, a JSON dict will be returned as described::

            {"groups": [  # List of groups the user is a member of
                {"name": "<act>:<usr>"},
                    # The first group is a unique user identifier
                {"name": "<account>"},
                    # The second group is the auth account name
                {"name": "<additional-group>"}
                    # There may be additional groups, .admin being a special
                    # group indicating an account admin and .reseller_admin
                    # indicating a reseller admin.
             ],
             "auth": "plaintext:<key>"
             # The auth-type and key for the user; currently only plaintext is
             # implemented.
            }

        For example::

            {"groups": [{"name": "test:tester"}, {"name": "test"},
                        {"name": ".admin"}],
             "auth": "plaintext:testing"}

        If the <user> in the request is the special user `.groups`, the JSON
        dict will contain a single key of `groups` whose value is a list of
        dicts representing the active groups within the account. Each dict
        currently has the single key `name`. For example::

            {"groups": [{"name": ".admin"}, {"name": "test"},
                        {"name": "test:tester"}, {"name": "test:tester3"}]}

        :param req: The swob.Request to process.
        :returns: swob.Response, 2xx on success with a JSON dictionary as
                  explained above.