Add last_accessed information to User and expose for robot accounts

Fixes https://jira.coreos.com/browse/QUAY-848
This commit is contained in:
Joseph Schorr 2018-03-12 20:30:19 -04:00
parent f1da3c452f
commit 2ea13e86a0
13 changed files with 143 additions and 67 deletions

View file

@ -24,6 +24,7 @@ class RobotPreOCIModel(RobotInterface):
'name': robot_name,
'token': robot_tuple.get(FederatedLogin.service_ident),
'created': robot_tuple.get(User.creation_date),
'last_accessed': robot_tuple.get(User.last_accessed),
'description': robot_tuple.get(RobotAccountMetadata.description),
'unstructured_metadata': robot_tuple.get(RobotAccountMetadata.unstructured_json),
}
@ -35,7 +36,8 @@ class RobotPreOCIModel(RobotInterface):
})
robots[robot_name] = Robot(robot_dict['name'], robot_dict['token'], robot_dict['created'],
robot_dict['description'], robot_dict['unstructured_metadata'])
robot_dict['last_accessed'], robot_dict['description'],
robot_dict['unstructured_metadata'])
if include_permissions:
team_name = robot_tuple.get(TeamTable.name)
repository_name = robot_tuple.get(Repository.name)
@ -54,7 +56,9 @@ class RobotPreOCIModel(RobotInterface):
if repository_name not in robot_dict['repositories']:
robot_dict['repositories'].append(repository_name)
robots[robot_name] = RobotWithPermissions(robot_dict['name'], robot_dict['token'],
robot_dict['created'], robot_dict['teams'],
robot_dict['created'],
robot_dict['last_accessed'],
robot_dict['teams'],
robot_dict['repositories'],
robot_dict['description'])
@ -62,14 +66,14 @@ class RobotPreOCIModel(RobotInterface):
def regenerate_user_robot_token(self, robot_shortname, owning_user):
robot, password, metadata = model.user.regenerate_robot_token(robot_shortname, owning_user)
return Robot(robot.username, password, robot.creation_date, metadata.description,
metadata.unstructured_json)
return Robot(robot.username, password, robot.creation_date, robot.last_accessed,
metadata.description, metadata.unstructured_json)
def regenerate_org_robot_token(self, robot_shortname, orgname):
parent = model.organization.get_organization(orgname)
robot, password, metadata = model.user.regenerate_robot_token(robot_shortname, parent)
return Robot(robot.username, password, robot.creation_date, metadata.description,
metadata.unstructured_json)
return Robot(robot.username, password, robot.creation_date, robot.last_accessed,
metadata.description, metadata.unstructured_json)
def delete_robot(self, robot_username):
model.user.delete_robot(robot_username)
@ -77,26 +81,26 @@ class RobotPreOCIModel(RobotInterface):
def create_user_robot(self, robot_shortname, owning_user, description, unstructured_metadata):
robot, password = model.user.create_robot(robot_shortname, owning_user, description or '',
unstructured_metadata)
return Robot(robot.username, password, robot.creation_date, description or '',
unstructured_metadata)
return Robot(robot.username, password, robot.creation_date, robot.last_accessed,
description or '', unstructured_metadata)
def create_org_robot(self, robot_shortname, orgname, description, unstructured_metadata):
parent = model.organization.get_organization(orgname)
robot, password = model.user.create_robot(robot_shortname, parent, description or '',
unstructured_metadata)
return Robot(robot.username, password, robot.creation_date, description or '',
unstructured_metadata)
return Robot(robot.username, password, robot.creation_date, robot.last_accessed,
description or '', unstructured_metadata)
def get_org_robot(self, robot_shortname, orgname):
parent = model.organization.get_organization(orgname)
robot, password, metadata = model.user.get_robot_and_metadata(robot_shortname, parent)
return Robot(robot.username, password, robot.creation_date, metadata.description,
metadata.unstructured_json)
return Robot(robot.username, password, robot.creation_date, robot.last_accessed,
metadata.description, metadata.unstructured_json)
def get_user_robot(self, robot_shortname, owning_user):
robot, password, metadata = model.user.get_robot_and_metadata(robot_shortname, owning_user)
return Robot(robot.username, password, robot.creation_date, metadata.description,
metadata.unstructured_json)
return Robot(robot.username, password, robot.creation_date, robot.last_accessed,
metadata.description, metadata.unstructured_json)
pre_oci_model = RobotPreOCIModel()