Skip to content

Commit

Permalink
database.py: add init error context
Browse files Browse the repository at this point in the history
  • Loading branch information
aiooss-anssi committed Jan 8, 2024
1 parent b954a33 commit ce108ef
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ using:
kill -USR2 $(pidof suricata)
```

### How can I start the webapp in read-only mode?

A SQLite database is generated in `webapp/database/database.db` on the first run
of the uvicorn webapp.
If you want to host a read-only Shovel instance (e.g. after the end of a CTF
event for further analysis), you may run the webapp in immutable mode using the
following environment variable:
```
DATABASE_URL=file:database/database.db?immutable=1
```

## Licensing

Copyright (C) 2023 ANSSI
Expand Down
7 changes: 6 additions & 1 deletion webapp/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ async def connect(self):
# WAL journal mode allows multiple concurrent readers
await self.con.execute("PRAGMA journal_mode=wal")
await self.con.execute("PRAGMA synchronous=normal")
await self.init_database_structure()
try:
await self.init_database_structure()
except aiosqlite.OperationalError as e:
raise RuntimeError(
f"unable to create database '{self.database_uri}'"
) from e

async def is_readonly(self) -> bool:
assert self.con is not None, "database connection closed"
Expand Down

0 comments on commit ce108ef

Please sign in to comment.