def log_action( kind_name, user_or_organization_name, performer=None, repository=None, ip=None, metadata={}, timestamp=None, ): """ Logs an entry in the LogEntry table. """ if not timestamp: timestamp = datetime.today() account = None if user_or_organization_name is not None: account = User.get(User.username == user_or_organization_name).id else: account = config.app_config.get("SERVICE_LOG_ACCOUNT_ID") if account is None: account = user.get_minimum_user_id() if performer is not None: performer = performer.id if repository is not None: repository = repository.id kind = _get_log_entry_kind(kind_name) metadata_json = json.dumps(metadata, default=_json_serialize) log_data = { "kind": kind, "account": account, "performer": performer, "repository": repository, "ip": ip, "metadata_json": metadata_json, "datetime": timestamp, } try: LogEntry3.create(**log_data) except PeeweeException as ex: strict_logging_disabled = config.app_config.get( "ALLOW_PULLS_WITHOUT_STRICT_LOGGING") if strict_logging_disabled and kind_name in ACTIONS_ALLOWED_WITHOUT_AUDIT_LOGGING: logger.exception("log_action failed", extra=({ "exception": ex }).update(log_data)) else: raise
def log_action(kind_name, user_or_organization_name, performer=None, repository=None, ip=None, metadata={}, timestamp=None): """ Logs an entry in the LogEntry table. """ if not timestamp: timestamp = datetime.today() account = None if user_or_organization_name is not None: account = User.get(User.username == user_or_organization_name).id else: account = config.app_config.get('SERVICE_LOG_ACCOUNT_ID') if account is None: account = user.get_minimum_user_id() if performer is not None: performer = performer.id if repository is not None: repository = repository.id kind = _get_log_entry_kind(kind_name) metadata_json = json.dumps(metadata, default=_json_serialize) log_data = { 'kind': kind, 'account': account, 'performer': performer, 'repository': repository, 'ip': ip, 'metadata_json': metadata_json, 'datetime': timestamp } try: LogEntry3.create(**log_data) except PeeweeException as ex: strict_logging_disabled = config.app_config.get( 'ALLOW_PULLS_WITHOUT_STRICT_LOGGING') if strict_logging_disabled and kind_name in ACTIONS_ALLOWED_WITHOUT_AUDIT_LOGGING: logger.exception('log_action failed', extra=({ 'exception': ex }).update(log_data)) else: raise
def clear_db_logs(initialized_db): LogEntry.delete().execute() LogEntry2.delete().execute() LogEntry3.delete().execute()
def _get_log_count(self): return (LogEntry3.select().where(LogEntry3.kind == LogEntryKind.get( name=self.log_kind)).count())