Limit robots displayed in entity search
Before, we'd load *all* the robots, which can be a huge issue in namespaces with a large number of robots. Now, we only load the top-20 robots (as per recency in login), and we also limit the information returned to the entity search to save some bandwidth. Fixes https://jira.coreos.com/browse/QUAY-927
This commit is contained in:
parent
7878435805
commit
5c50161d85
7 changed files with 121 additions and 26 deletions
|
@ -31,9 +31,11 @@ CREATE_ROBOT_SCHEMA = {
|
|||
ROBOT_MAX_SIZE = 1024 * 1024 # 1 KB.
|
||||
|
||||
|
||||
def robots_list(prefix, include_permissions=False):
|
||||
robots = model.list_entity_robot_permission_teams(prefix, include_permissions=include_permissions)
|
||||
return {'robots': [robot.to_dict() for robot in robots]}
|
||||
def robots_list(prefix, include_permissions=False, include_token=False, limit=None):
|
||||
robots = model.list_entity_robot_permission_teams(prefix, limit=limit,
|
||||
include_token=include_token,
|
||||
include_permissions=include_permissions)
|
||||
return {'robots': [robot.to_dict(include_token=include_token) for robot in robots]}
|
||||
|
||||
|
||||
@resource('/v1/user/robots')
|
||||
|
@ -46,10 +48,18 @@ class UserRobotList(ApiResource):
|
|||
@query_param('permissions',
|
||||
'Whether to include repositories and teams in which the robots have permission.',
|
||||
type=truthy_bool, default=False)
|
||||
@query_param('token',
|
||||
'If false, the robot\'s token is not returned.',
|
||||
type=truthy_bool, default=True)
|
||||
@query_param('limit',
|
||||
'If specified, the number of robots to return.',
|
||||
type=int, default=None)
|
||||
def get(self, parsed_args):
|
||||
""" List the available robots for the user. """
|
||||
user = get_authenticated_user()
|
||||
return robots_list(user.username, include_permissions=parsed_args.get('permissions', False))
|
||||
return robots_list(user.username, include_token=parsed_args.get('token', True),
|
||||
include_permissions=parsed_args.get('permissions', False),
|
||||
limit=parsed_args.get('limit'))
|
||||
|
||||
|
||||
@resource('/v1/user/robots/<robot_shortname>')
|
||||
|
@ -67,7 +77,7 @@ class UserRobot(ApiResource):
|
|||
""" Returns the user's robot with the specified name. """
|
||||
parent = get_authenticated_user()
|
||||
robot = model.get_user_robot(robot_shortname, parent)
|
||||
return robot.to_dict(include_metadata=True)
|
||||
return robot.to_dict(include_metadata=True, include_token=True)
|
||||
|
||||
@require_user_admin
|
||||
@nickname('createUserRobot')
|
||||
|
@ -84,7 +94,7 @@ class UserRobot(ApiResource):
|
|||
'description': create_data.get('description'),
|
||||
'unstructured_metadata': create_data.get('unstructured_metadata'),
|
||||
})
|
||||
return robot.to_dict(include_metadata=True), 201
|
||||
return robot.to_dict(include_metadata=True, include_token=True), 201
|
||||
|
||||
@require_user_admin
|
||||
@nickname('deleteUserRobot')
|
||||
|
@ -108,11 +118,23 @@ class OrgRobotList(ApiResource):
|
|||
@query_param('permissions',
|
||||
'Whether to include repostories and teams in which the robots have permission.',
|
||||
type=truthy_bool, default=False)
|
||||
@query_param('token',
|
||||
'If false, the robot\'s token is not returned.',
|
||||
type=truthy_bool, default=True)
|
||||
@query_param('limit',
|
||||
'If specified, the number of robots to return.',
|
||||
type=int, default=None)
|
||||
def get(self, orgname, parsed_args):
|
||||
""" List the organization's robots. """
|
||||
permission = OrganizationMemberPermission(orgname)
|
||||
if permission.can():
|
||||
return robots_list(orgname, include_permissions=parsed_args.get('permissions', False))
|
||||
include_token = (AdministerOrganizationPermission(orgname).can() and
|
||||
parsed_args.get('token', True))
|
||||
include_permissions = (AdministerOrganizationPermission(orgname).can() and
|
||||
parsed_args.get('permissions', False))
|
||||
return robots_list(orgname, include_permissions=include_permissions,
|
||||
include_token=include_token,
|
||||
limit=parsed_args.get('limit'))
|
||||
|
||||
raise Unauthorized()
|
||||
|
||||
|
@ -135,7 +157,7 @@ class OrgRobot(ApiResource):
|
|||
permission = AdministerOrganizationPermission(orgname)
|
||||
if permission.can():
|
||||
robot = model.get_org_robot(robot_shortname, orgname)
|
||||
return robot.to_dict(include_metadata=True)
|
||||
return robot.to_dict(include_metadata=True, include_token=True)
|
||||
|
||||
raise Unauthorized()
|
||||
|
||||
|
@ -155,7 +177,7 @@ class OrgRobot(ApiResource):
|
|||
'description': create_data.get('description'),
|
||||
'unstructured_metadata': create_data.get('unstructured_metadata'),
|
||||
})
|
||||
return robot.to_dict(include_metadata=True), 201
|
||||
return robot.to_dict(include_metadata=True, include_token=True), 201
|
||||
|
||||
raise Unauthorized()
|
||||
|
||||
|
@ -228,7 +250,7 @@ class RegenerateUserRobot(ApiResource):
|
|||
parent = get_authenticated_user()
|
||||
robot = model.regenerate_user_robot_token(robot_shortname, parent)
|
||||
log_action('regenerate_robot_token', parent.username, {'robot': robot_shortname})
|
||||
return robot.to_dict()
|
||||
return robot.to_dict(include_token=True)
|
||||
|
||||
|
||||
@resource('/v1/organization/<orgname>/robots/<robot_shortname>/regenerate')
|
||||
|
@ -247,6 +269,6 @@ class RegenerateOrgRobot(ApiResource):
|
|||
if permission.can():
|
||||
robot = model.regenerate_org_robot_token(robot_shortname, orgname)
|
||||
log_action('regenerate_robot_token', orgname, {'robot': robot_shortname})
|
||||
return robot.to_dict()
|
||||
return robot.to_dict(include_token=True)
|
||||
|
||||
raise Unauthorized()
|
||||
|
|
Reference in a new issue