Interface out all action log data model operations
This will allow us to reimplement the logs data model against a non-database system in the near future
This commit is contained in:
parent
a156c91962
commit
b773a18ed8
26 changed files with 714 additions and 902 deletions
|
@ -7,37 +7,8 @@ from auth.permissions import ReadRepositoryPermission, ModifyRepositoryPermissio
|
|||
from data import model, database
|
||||
from endpoints.api.build import get_job_config, _get_build_status
|
||||
from endpoints.api.superuser_models_interface import BuildTrigger
|
||||
from endpoints.api.superuser_models_interface import SuperuserDataInterface, LogEntryPage, LogEntry, Organization, User, \
|
||||
ServiceKey, Approval, RepositoryBuild, AggregatedLogEntry
|
||||
|
||||
|
||||
def _create_log(log, log_kind):
|
||||
account_organization = None
|
||||
account_username = None
|
||||
account_email = None
|
||||
account_robot = None
|
||||
try:
|
||||
account_organization = log.account.organization
|
||||
account_username = log.account.username
|
||||
account_email = log.account.email
|
||||
account_robot = log.account.robot
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
performer_robot = None
|
||||
performer_username = None
|
||||
performer_email = None
|
||||
|
||||
try:
|
||||
performer_robot = log.performer.robot
|
||||
performer_username = log.performer.username
|
||||
performer_email = log.performer.email
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
return LogEntry(log.metadata_json, log.ip, log.datetime, performer_email, performer_username,
|
||||
performer_robot, account_organization, account_username,
|
||||
account_email, account_robot, log_kind[log.kind_id])
|
||||
from endpoints.api.superuser_models_interface import SuperuserDataInterface, Organization, User, \
|
||||
ServiceKey, Approval, RepositoryBuild
|
||||
|
||||
|
||||
def _create_user(user):
|
||||
|
@ -205,16 +176,5 @@ class PreOCIModel(SuperuserDataInterface):
|
|||
def get_organizations(self):
|
||||
return [Organization(org.username, org.email) for org in model.organization.get_organizations()]
|
||||
|
||||
def get_aggregated_logs(self, start_time, end_time):
|
||||
aggregated_logs = model.log.get_aggregated_logs(start_time, end_time)
|
||||
return [AggregatedLogEntry(log.count, log.kind_id, log.day, start_time) for log in aggregated_logs]
|
||||
|
||||
def get_logs_query(self, start_time, end_time, page_token=None):
|
||||
logs_query = model.log.get_logs_query(start_time, end_time)
|
||||
logs, next_page_token = model.modelutil.paginate(logs_query, database.LogEntry, descending=True,
|
||||
page_token=page_token, limit=20)
|
||||
kinds = model.log.get_log_entry_kinds()
|
||||
return LogEntryPage([_create_log(log, kinds) for log in logs], next_page_token)
|
||||
|
||||
|
||||
pre_oci_model = PreOCIModel()
|
||||
|
|
Reference in a new issue