def main(): eventlog = EventLog(allowed_schemas=["hub.jupyter.org/server-action"], handlers=[logging.StreamHandler(sys.stdout)]) hmac_key = secrets.token_bytes(32) for dirname, _, files in os.walk( pathlib.Path(__file__).parent / "event-schemas"): for file in files: if not file.endswith('.yaml'): continue eventlog.register_schema_file(os.path.join(dirname, file)) for l in sys.stdin: if 'seconds to' not in l: continue timestamp, user, action = parse_activity_line(l) eventlog.record_event( "hub.jupyter.org/server-action", 1, { "action": action, "username": hmac.new(key=hmac_key, msg=user.encode(), digestmod='sha256').hexdigest(), "servername": "" }, timestamp_override=timestamp)
def test_register_schema_file_object(tmp_path): """ Register schema from a file """ schema = { '$id': 'test/test', 'version': 1, 'properties': { 'something': { 'type': 'string', 'categories': ['unrestricted'] }, }, } el = EventLog() yaml = YAML(typ='safe') schema_file = tmp_path.joinpath("schema.yml") yaml.dump(schema, schema_file) with open(str(schema_file), 'r') as f: el.register_schema_file(f) assert schema in el.schemas.values()
def test_register_schema_file(): """ Register schema from a file """ schema = { '$id': 'test/test', 'version': 1, 'properties': { 'something': { 'type': 'string' }, }, } el = EventLog() yaml = YAML(typ='safe') with tempfile.NamedTemporaryFile(mode='w') as f: yaml.dump(schema, f) f.flush() f.seek(0) el.register_schema_file(f.name) assert schema in el.schemas.values()
def main(): eventlog = EventLog( allowed_schemas=[ "hub.jupyter.org/server-action" ], handlers=[ logging.StreamHandler() ] ) for dirname, _, files in os.walk(pathlib.Path(__file__).parent / "event-schemas"): for file in files: if not file.endswith('.yaml'): continue eventlog.register_schema_file(os.path.join(dirname, file)) for l in sys.stdin: if 'seconds to' not in l: continue timestamp, user, action = parse_activity_line(l) eventlog.record_event( "hub.jupyter.org/server-action", 1, { "action": action, "username": user, "servername": "" }, timestamp_override=timestamp )