datasette-current-actor
Adds a current_actor() function to SQLite that show's the current actor's ID.
Installation
Install this plugin in the same environment as Datasette.
datasette install datasette-current-actor
Usage
current_actor()returns the current actor's ID, orNULLif no actor.current_actor('attrs', 'name')navigates the actor object, returning the value of thenamekey stored in theattrskey, orNULLif any of the intermediate values are absent.current_actor_ip()returns the current actor's IP addresscurrent_actor_user_agent()returns the current actor's HTTP user agent
Default values, views and triggers
SQLite is flexible. It turns out you can refer to functions that don't exist when issuing DDL statements. As long as they exist when they're needed, it all works out.
Auditing
Track who added a row:
CREATE TABLE notes(
created_by text not null default (current_actor()),
created_by_ip text not null default (current_actor_ip()),
note text not null
);
Or create an UPDATE trigger on a table that sets the last_edited_by column to
current_actor().
Row-level security
Restrict the rows that users see:
CREATE VIEW rls AS
SELECT * FROM sensitive_data WHERE owner = current_actor()
You can see a live example at https://dux.fly.dev/cooking/my_questions, which should show you 0 rows.
That instance permits "logging in" by passing a _whoami query parameter. If you visit https://dux.fly.dev/cooking/my_questions?_whoami=15, you'll see all of user 15's questions.
Development
To set up this plugin locally, first checkout the code. Then create a new virtual environment:
cd datasette-current-actor
python3 -m venv venv
source venv/bin/activate
Now install the dependencies and test dependencies:
pip install -e '.[test]'
To run the tests:
pytest
Metadata
Release files for datasette-current-actor 0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| datasette-current-actor-0.3.tar.gz | 7.5 kB | Without provenance | Details for datasette-current-actor-0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| datasette_current_actor-0.3-py3-none-any.whl | Python 3 | none | any | Details for datasette_current_actor-0.3-py3-none-any.whl |
Total release size: 15.4 kB
Release files / datasette-current-actor-0.3.tar.gz
| Download URL | datasette-current-actor-0.3.tar.gz |
|---|---|
| Size | 7.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b8063c1b04079420ae35bb9fd04a6914b44a45d3305db6ec9497298d12efb5ad
|
|
BLAKE2b-256 checksum How to use checksums |
d724e8fe96695060fc2fc6a3d0f8bc5f820932d80bba8c277072fa39efc69c02
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.1
|
Release files / datasette_current_actor-0.3-py3-none-any.whl
| Download URL | datasette_current_actor-0.3-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8b23f56ff674420ce97176a775b11a1ff52e33874d10713bd2768efda5adec9a
|
|
BLAKE2b-256 checksum How to use checksums |
82895d1b614aaa04cf31374d539726ba3df5fca2dffa9e09ca70eafa58424471
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.1
|
Security for datasette-current-actor 0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.