-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: schema for persistence provenance and function to store the dat…
…aflow graph (#75) Co-authored-by: Sam Grayson <[email protected]>
- Loading branch information
1 parent
b13c3e9
commit 86c3dce
Showing
3 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
probe_src/python/probe_py/manual/persistent_provenance_db.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from sqlalchemy import create_engine, DateTime | ||
from sqlalchemy.orm import DeclarativeBase, mapped_column, Mapped | ||
from sqlalchemy.engine import Engine | ||
import xdg_base_dirs | ||
import pathlib | ||
from datetime import datetime | ||
|
||
class Base(DeclarativeBase): | ||
pass | ||
|
||
_engine = None | ||
def get_engine()->Engine: | ||
global _engine | ||
if _engine is None: | ||
home = pathlib.Path(xdg_base_dirs.xdg_data_home()) | ||
home.mkdir(parents=True, exist_ok=True) | ||
database_path = home / "probe_log.db" | ||
|
||
_engine = create_engine(f'sqlite:///{database_path}', echo=True) | ||
Base.metadata.create_all(_engine) | ||
return _engine | ||
|
||
class ProcessThatWrites(Base): | ||
__tablename__ = 'process_that_writes' | ||
|
||
id: Mapped[int] = mapped_column(primary_key=True, auto_increment=True) | ||
inode: Mapped[int] | ||
process_id: Mapped[int] | ||
device_major: Mapped[int] | ||
device_minor: Mapped[int] | ||
host: Mapped[int] | ||
path: Mapped[str] | ||
mtime_sec: Mapped[int] | ||
mtime_nsec: Mapped[int] | ||
size: Mapped[int] | ||
|
||
|
||
class Process(Base): | ||
__tablename__ = 'process' | ||
|
||
process_id: Mapped[int] = mapped_column(primary_key=True) | ||
parent_process_id: Mapped[int] | ||
cmd: Mapped[str] | ||
time: Mapped[datetime] = mapped_column(DateTime) | ||
|
||
|
||
class ProcessInputs(Base): | ||
__tablename__ = 'process_inputs' | ||
|
||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True) | ||
inode: Mapped[int] | ||
process_id: Mapped[int] | ||
device_major: Mapped[int] | ||
device_minor: Mapped[int] | ||
host: Mapped[int] | ||
path: Mapped[str] | ||
mtime_sec: Mapped[int] | ||
mtime_nsec: Mapped[int] | ||
size: Mapped[int] |