kopia lustrzana https://github.com/simonw/datasette
Added /-/actor.json - refs #699
Also added JSON highlighting to introspection documentation.pull/703/head
rodzic
9315bacf6f
commit
1fc6ceefb9
|
@ -586,6 +586,9 @@ class Datasette:
|
|||
)
|
||||
return d
|
||||
|
||||
def _actor(self, request):
|
||||
return {"actor": request.scope.get("actor", None)}
|
||||
|
||||
def table_metadata(self, database, table):
|
||||
"Fetch table-specific metadata."
|
||||
return (
|
||||
|
@ -762,6 +765,10 @@ class Datasette:
|
|||
JsonDataView.as_asgi(self, "databases.json", self._connected_databases),
|
||||
r"/-/databases(?P<as_format>(\.json)?)$",
|
||||
)
|
||||
add_route(
|
||||
JsonDataView.as_asgi(self, "actor.json", self._actor, needs_request=True),
|
||||
r"/-/actor(?P<as_format>(\.json)?)$",
|
||||
)
|
||||
add_route(
|
||||
PatternPortfolioView.as_asgi(self), r"/-/patterns$",
|
||||
)
|
||||
|
|
|
@ -6,12 +6,16 @@ from .base import BaseView
|
|||
class JsonDataView(BaseView):
|
||||
name = "json_data"
|
||||
|
||||
def __init__(self, datasette, filename, data_callback):
|
||||
def __init__(self, datasette, filename, data_callback, needs_request=False):
|
||||
self.ds = datasette
|
||||
self.filename = filename
|
||||
self.data_callback = data_callback
|
||||
self.needs_request = needs_request
|
||||
|
||||
async def get(self, request, as_format):
|
||||
if self.needs_request:
|
||||
data = self.data_callback(request)
|
||||
else:
|
||||
data = self.data_callback()
|
||||
if as_format:
|
||||
headers = {}
|
||||
|
|
|
@ -10,7 +10,9 @@ Each of these pages can be viewed in your browser. Add ``.json`` to the URL to g
|
|||
/-/metadata
|
||||
-----------
|
||||
|
||||
Shows the contents of the ``metadata.json`` file that was passed to ``datasette serve``, if any. `Metadata example <https://fivethirtyeight.datasettes.com/-/metadata>`_::
|
||||
Shows the contents of the ``metadata.json`` file that was passed to ``datasette serve``, if any. `Metadata example <https://fivethirtyeight.datasettes.com/-/metadata>`_:
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"license": "CC Attribution 4.0 License",
|
||||
|
@ -18,7 +20,9 @@ Shows the contents of the ``metadata.json`` file that was passed to ``datasette
|
|||
"source": "fivethirtyeight/data on GitHub",
|
||||
"source_url": "https://github.com/fivethirtyeight/data",
|
||||
"title": "Five Thirty Eight",
|
||||
"databases": {...}
|
||||
"databases": {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
.. _JsonDataView_versions:
|
||||
|
@ -26,7 +30,9 @@ Shows the contents of the ``metadata.json`` file that was passed to ``datasette
|
|||
/-/versions
|
||||
-----------
|
||||
|
||||
Shows the version of Datasette, Python and SQLite. `Versions example <https://latest.datasette.io/-/versions>`_::
|
||||
Shows the version of Datasette, Python and SQLite. `Versions example <https://latest.datasette.io/-/versions>`_:
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"datasette": {
|
||||
|
@ -63,7 +69,9 @@ Shows the version of Datasette, Python and SQLite. `Versions example <https://la
|
|||
/-/plugins
|
||||
----------
|
||||
|
||||
Shows a list of currently installed plugins and their versions. `Plugins example <https://san-francisco.datasettes.com/-/plugins>`_::
|
||||
Shows a list of currently installed plugins and their versions. `Plugins example <https://san-francisco.datasettes.com/-/plugins>`_:
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
[
|
||||
{
|
||||
|
@ -79,7 +87,9 @@ Shows a list of currently installed plugins and their versions. `Plugins example
|
|||
/-/config
|
||||
---------
|
||||
|
||||
Shows the :ref:`config` options for this instance of Datasette. `Config example <https://fivethirtyeight.datasettes.com/-/config>`_::
|
||||
Shows the :ref:`config` options for this instance of Datasette. `Config example <https://fivethirtyeight.datasettes.com/-/config>`_:
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"default_facet_size": 30,
|
||||
|
@ -95,7 +105,9 @@ Shows the :ref:`config` options for this instance of Datasette. `Config example
|
|||
/-/databases
|
||||
------------
|
||||
|
||||
Shows currently attached databases. `Databases example <https://latest.datasette.io/-/config>`_::
|
||||
Shows currently attached databases. `Databases example <https://latest.datasette.io/-/config>`_:
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
[
|
||||
{
|
||||
|
@ -113,7 +125,9 @@ Shows currently attached databases. `Databases example <https://latest.datasette
|
|||
/-/threads
|
||||
----------
|
||||
|
||||
Shows details of threads and ``asyncio`` tasks. `Threads example <https://latest.datasette.io/-/threads>`_::
|
||||
Shows details of threads and ``asyncio`` tasks. `Threads example <https://latest.datasette.io/-/threads>`_:
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"num_threads": 2,
|
||||
|
@ -136,3 +150,19 @@ Shows details of threads and ``asyncio`` tasks. `Threads example <https://latest
|
|||
"<Task pending coro=<LifespanOn.main() running at uvicorn/lifespan/on.py:48> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x10364f050>()]>>"
|
||||
]
|
||||
}
|
||||
|
||||
.. _JsonDataView_actor:
|
||||
|
||||
/-/actor
|
||||
--------
|
||||
|
||||
Shows the currently authenticated actor. Useful for debugging Datasette authentication plugins.
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"actor": {
|
||||
"id": 1,
|
||||
"username": "some-user"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -539,3 +539,10 @@ async def test_permission_allowed(app_client, action, expected):
|
|||
{"id": "actor"}, action, default=None
|
||||
)
|
||||
assert expected == actual
|
||||
|
||||
|
||||
def test_actor_json(app_client):
|
||||
assert {"actor": None} == app_client.get("/-/actor.json").json
|
||||
assert {"actor": {"id": "bot2", "1+1": 2}} == app_client.get(
|
||||
"/-/actor.json/?_bot2=1"
|
||||
).json
|
||||
|
|
Ładowanie…
Reference in New Issue