def log_action( self, kind_name, namespace_name=None, performer=None, ip=None, metadata=None, repository=None, repository_name=None, timestamp=None, is_free_namespace=False, ): timestamp = timestamp or datetime.today() if not repository and repository_name and namespace_name: repository = model.repository.get_repository(namespace_name, repository_name) account = None account_id = None performer_id = None repository_id = None if namespace_name is not None: account = model.user.get_namespace_user(namespace_name) account_id = account.id if performer is not None: performer_id = performer.id if repository is not None: repository_id = repository.id metadata_json = json.dumps(metadata or {}) kind_id = model.log.get_log_entry_kinds()[kind_name] stored_log = StoredLog( kind_id, account_id, performer_id, ip, metadata_json, repository_id, timestamp ) log = Log( metadata_json=metadata, ip=ip, datetime=timestamp, performer_email=performer.email if performer else None, performer_username=performer.username if performer else None, performer_robot=performer.robot if performer else None, account_organization=account.organization if account else None, account_username=account.username if account else None, account_email=account.email if account else None, account_robot=account.robot if account else None, kind_id=kind_id, ) self.logs.append(LogAndRepository(log, stored_log, repository))
"repository_id": 1, "ip": "192.168.1.2", "metadata_json": '{"\\ud83d\\ude02": "\\ud83d\\ude02\\ud83d\\udc4c\\ud83d\\udc4c\\ud83d\\udc4c\\ud83d\\udc4c", "key": "value", "time": 1522639800}', "datetime": "2018-04-02T03:30", }, "sort": [1522639800000, 233], } _log1 = Log( '{"\\ud83d\\ude02": "\\ud83d\\ude02\\ud83d\\udc4c\\ud83d\\udc4c\\ud83d\\udc4c\\ud83d\\udc4c", "key": "value", "time": 1520479800}', "192.168.1.1", parse("2018-03-08T03:30"), "user1.email", "user1.username", "user1.robot", "user1.organization", "user1.username", "user1.email", "user1.robot", 1, ) _log2 = Log( '{"\\ud83d\\ude02": "\\ud83d\\ude02\\ud83d\\udc4c\\ud83d\\udc4c\\ud83d\\udc4c\\ud83d\\udc4c", "key": "value", "time": 1522639800}', "192.168.1.2", parse("2018-04-02T03:30"), "user1.email", "user1.username", "user1.robot", "user1.organization", "user1.username",
"repository_id": 1, "ip": "192.168.1.2", "metadata_json": '{"\\ud83d\\ude02": "\\ud83d\\ude02\\ud83d\\udc4c\\ud83d\\udc4c\\ud83d\\udc4c\\ud83d\\udc4c", "key": "value", "time": 1522639800}', "datetime": "2018-04-02T03:30", }, "sort": [1522639800000, 233], } _log1 = Log( "{}", "192.168.1.1", parse("2018-03-08T03:30"), "user1.email", "user1.username", "user1.robot", "user1.organization", "user1.username", "user1.email", "user1.robot", 1, ) _log2 = Log( "{}", "192.168.1.2", parse("2018-04-02T03:30"), "user1.email", "user1.username", "user1.robot", "user1.organization", "user1.username",
"random_id": 233, "kind_id": 2, "account_id": 1, "performer_id": 1, "repository_id": 1, "ip": "192.168.1.2", "metadata_json": "{\"\\ud83d\\ude02\": \"\\ud83d\\ude02\\ud83d\\udc4c\\ud83d\\udc4c\\ud83d\\udc4c\\ud83d\\udc4c\", \"key\": \"value\", \"time\": 1522639800}", "datetime": "2018-04-02T03:30", }, "sort": [1522639800000, 233] } _log1 = Log( "{\"\\ud83d\\ude02\": \"\\ud83d\\ude02\\ud83d\\udc4c\\ud83d\\udc4c\\ud83d\\udc4c\\ud83d\\udc4c\", \"key\": \"value\", \"time\": 1520479800}", "192.168.1.1", parse("2018-03-08T03:30"), "user1.email", "user1.username", "user1.robot", "user1.organization", "user1.username", "user1.email", "user1.robot", 1) _log2 = Log( "{\"\\ud83d\\ude02\": \"\\ud83d\\ude02\\ud83d\\udc4c\\ud83d\\udc4c\\ud83d\\udc4c\\ud83d\\udc4c\", \"key\": \"value\", \"time\": 1522639800}", "192.168.1.2", parse("2018-04-02T03:30"), "user1.email", "user1.username", "user1.robot", "user1.organization", "user1.username", "user1.email", "user1.robot", 2) SEARCH_RESPONSE_START = _status(_shards(_hits([_hit1, _hit2]))) SEARCH_RESPONSE_END = _status(_shards(_hits([_hit2]))) SEARCH_REQUEST_START = { "sort": [{ "datetime": "desc" }, { "random_id.keyword": "desc"