Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datasette --get --actor option #2153

Closed
simonw opened this issue Aug 24, 2023 · 5 comments
Closed

Datasette --get --actor option #2153

simonw opened this issue Aug 24, 2023 · 5 comments

Comments

@simonw
Copy link
Owner

simonw commented Aug 24, 2023

I experimented with a prototype of this here:

Which lets me run requests as if they belonged to a specific actor like this:

datasette fixtures.db --get '/fixtures/facetable.json' --actor '{
    "_r": {
        "r": {
            "fixtures": {
                "facetable": [
                    "vt"
                ]
            }
        }
    },
    "a": "user"
}'

Really useful for testing actors an _r options. Is this worth adding as a feature?

@simonw simonw changed the title datasette --get --actor option Maybe add datasette --get --actor option Aug 24, 2023
@simonw
Copy link
Owner Author

simonw commented Aug 24, 2023

Building that "_r" array is the main reason this would be useful, but it's also fiddly to get right.

datasette create-token has a design for that already: https://docs.datasette.io/en/1.0a4/authentication.html#datasette-create-token

datasette create-token root \
    --secret mysecret \
    --all view-instance \
    --all view-table \
    --database docs view-query \
    --resource docs documents insert-row \
    --resource docs documents update-row

Adding imitations of those options (excluding --secret, not needed here) to datasette serve would add a LOT of extra options, but it would also make it really convenient to attempt a request with a specific set of restrictions. Not sure if that would be worth the extra --help output or not.

I feel like the names would have to have a common prefix though. Maybe something like this:

datasette serve data.db --get `/data/mytable.json' \
  --actor-id root \
  --r-all view-instance \
  --r-database data view-query \
  --r-resource data documents update-row

Other options could be the longer --restrict-all/--restrict-database/--restrict-resource.

@simonw
Copy link
Owner Author

simonw commented Aug 24, 2023

Another option: implement this as a plugin, providing a new command like datasette get ...

Or implement datasette client get ... as core commands or a plugin - except that clashes with the datasette client command that https://github.com/simonw/dclient adds (which is a tool for hitting remote Datasette instances, not running simulated queries through a local one).

@simonw
Copy link
Owner Author

simonw commented Aug 24, 2023

Annoying that datasette client ... makes a great name both for a plugin that executes simulated queries against a local database (thanks to its similarity to the existing datasette.client Python API) but is also the ideal name for a command for running commands as a client of an external Datasette instance!

@simonw simonw changed the title Maybe add datasette --get --actor option Maybe add datasette --get --actor option - or datasette client get --actor Aug 24, 2023
@simonw
Copy link
Owner Author

simonw commented Aug 24, 2023

datasette serve currently only has a --get - for this to be really useful it needs to grow --post and maybe other verbs too.

Which is a good argument for moving this functionality to datasette client get ... instead.

simonw added a commit that referenced this issue Aug 24, 2023
Also includes a prototype implementation of --actor option from #2153 which I'm using for testing this.
@simonw simonw changed the title Maybe add datasette --get --actor option - or datasette client get --actor Datasette --get --actor option Aug 28, 2023
@simonw simonw closed this as completed in d8351b0 Aug 28, 2023
simonw added a commit that referenced this issue Aug 28, 2023
@simonw
Copy link
Owner Author

simonw commented Aug 28, 2023

simonw added a commit that referenced this issue Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant