ripgrep
datasette-configure-asgi/datasette_configure_asgi.py
6 def asgi_wrapper(datasette):
7 def wrap_with_classes(app):
8 configs = datasette.plugin_config("datasette-configure-asgi") or []
9 for config in configs:
10 module_path, class_name = config["class"].rsplit(".", 1)
datasette-cors/datasette_cors.py
5 @hookimpl
6 def asgi_wrapper(datasette):
7 config = datasette.plugin_config("datasette-cors") or {}
8 allow_all = config.get("allow_all") or False
9 hosts = config.get("hosts") or []
datasette-render-html/datasette_render_html.py
5 @hookimpl
6 def render_cell(value, column, table, database, datasette):
7 config = datasette.plugin_config(
8 "datasette-render-html", database=database, table=table
9 )
datasette-render-images/datasette_render_images.py
11 size_limit = DEFAULT_SIZE_LIMIT
12 if datasette:
13 plugin_config = datasette.plugin_config("datasette-render-images") or {}
14 size_limit = plugin_config.get("size_limit") or DEFAULT_SIZE_LIMIT
15 # Only act on byte columns
datasette-ripgrep/README.md
15
16 - [with.\*AsyncClient](https://ripgrep.datasette.io/-/ripgrep?pattern=with.*AsyncClient) - regular expression search for `with.*AsyncClient`
17 - [.plugin_config, literal=on](https://ripgrep.datasette.io/-/ripgrep?pattern=.plugin_config\(&literal=on) - a non-regular expression search for `.plugin_config(`
18 - [with.\*AsyncClient glob=datasette/\*\*](https://ripgrep.datasette.io/-/ripgrep?pattern=with.*AsyncClient&glob=datasette%2F%2A%2A) - search for that pattern only within the `datasette/` top folder
19 - ["sqlite-utils\[">\] glob=setup.py](https://ripgrep.datasette.io/-/ripgrep?pattern=%22sqlite-utils%5B%22%3E%5D&glob=setup.py) - a regular expression search for packages that depend on either `sqlite-utils` or `sqlite-utils>=some-version`
datasette-sentry/datasette_sentry.py
6 @hookimpl
7 def asgi_wrapper(datasette):
8 config = datasette.plugin_config("datasette-sentry") or {}
9 dsn = config.get("dsn")
10 if dsn is not None:
big-local-datasette/plugins/token_auth.py
29 @hookimpl(trylast=True)
30 def asgi_wrapper(datasette):
31 config = datasette.plugin_config("token-auth") or {}
32 secret = config.get("secret")
33 auth = config.get("auth")
datasette/docs/internals.rst
178 .. _datasette_plugin_config:
179
180 .plugin_config(plugin_name, database=None, table=None)
181 ------------------------------------------------------
182
datasette/docs/plugin_hooks.rst
34
35 ``datasette`` - :ref:`internals_datasette`
36 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``
37
38 This hook is called when a new SQLite database connection is created. You can
108
109 ``datasette`` - :ref:`internals_datasette`
110 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``
111
112 This hook can return one of three different types:
271 The ``template``, ``database``, ``table`` and ``view_name`` options can be used to return different code depending on which template is being rendered and which database or table are being processed.
272
273 The ``datasette`` instance is provided primarily so that you can consult any plugin configuration options that may have been set, using the ``datasette.plugin_config(plugin_name)`` method documented above.
274
275 This function can return a string containing JavaScript, or a dictionary as described below, or a function or awaitable function that returns a string or dictionary.
371
372 ``datasette`` - :ref:`internals_datasette`
373 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``
374
375 If your hook returns ``None``, it will be ignored. Use this to indicate that your hook is not able to custom render this particular value.
429
430 ``datasette`` - :ref:`internals_datasette`
431 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``
432
433 Registers a new output renderer, to output data in a custom format. The hook function should return a dictionary, or a list of dictionaries, of the following shape:
561
562 ``datasette`` - :ref:`internals_datasette`
563 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``, or to execute SQL queries.
564
565 ``request`` - Request object
705 @hookimpl
706 def startup(datasette):
707 config = datasette.plugin_config("my-plugin") or {}
708 assert "required-setting" in config, "my-plugin requires setting required-setting"
709
748
749 ``datasette`` - :ref:`internals_datasette`
750 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``, or to execute SQL queries.
751
752 ``database`` - string
817
818 ``datasette`` - :ref:`internals_datasette`
819 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``, or to execute SQL queries.
820
821 ``request`` - object
878
879 ``datasette`` - :ref:`internals_datasette`
880 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``, or to execute SQL queries.
881
882 ``actor`` - dictionary
937
938 ``datasette`` - :ref:`internals_datasette`
939 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``.
940
941 :ref:`canned_queries_magic_parameters` can be used to add automatic parameters to :ref:`canned queries <canned_queries>`. This plugin hook allows additional magic parameters to be defined by plugins.
976
977 ``datasette`` - :ref:`internals_datasette`
978 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``, or to execute SQL queries.
979
980 ``request`` - object
1019
1020 ``datasette`` - :ref:`internals_datasette`
1021 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``, or to execute SQL queries.
1022
1023 ``actor`` - dictionary or None
1052
1053 ``datasette`` - :ref:`internals_datasette`
1054 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``, or to execute SQL queries.
1055
1056 ``actor`` - dictionary or None
1087
1088 ``datasette`` - :ref:`internals_datasette`
1089 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``, or to execute SQL queries.
1090
1091 ``actor`` - dictionary or None
datasette/docs/writing_plugins.rst
168 When you are writing plugins, you can access plugin configuration like this using the ``datasette plugin_config()`` method. If you know you need plugin configuration for a specific table, you can access it like this::
169
170 plugin_config = datasette.plugin_config(
171 "datasette-cluster-map", database="sf-trees", table="Street_Tree_List"
172 )
datasette/tests/test_plugins.py
50 )
51 assert [
52 "database=fixtures, datasette.plugin_config(\"name-of-plugin\")={'depth': 'root'}"
53 ] == response.json
54
187
188 def test_plugin_config(app_client):
189 assert {"depth": "table"} == app_client.ds.plugin_config(
190 "name-of-plugin", database="fixtures", table="sortable"
191 )
192 assert {"depth": "database"} == app_client.ds.plugin_config(
193 "name-of-plugin", database="fixtures", table="unknown_table"
194 )
195 assert {"depth": "database"} == app_client.ds.plugin_config(
196 "name-of-plugin", database="fixtures"
197 )
198 assert {"depth": "root"} == app_client.ds.plugin_config(
199 "name-of-plugin", database="unknown_database"
200 )
201 assert {"depth": "root"} == app_client.ds.plugin_config("name-of-plugin")
202 assert None is app_client.ds.plugin_config("unknown-plugin")
203
204
205 def test_plugin_config_env(app_client):
206 os.environ["FOO_ENV"] = "FROM_ENVIRONMENT"
207 assert {"foo": "FROM_ENVIRONMENT"} == app_client.ds.plugin_config("env-plugin")
208 # Ensure secrets aren't visible in /-/metadata.json
209 metadata = app_client.get("/-/metadata.json")
214 def test_plugin_config_env_from_list(app_client):
215 os.environ["FOO_ENV"] = "FROM_ENVIRONMENT"
216 assert [{"in_a_list": "FROM_ENVIRONMENT"}] == app_client.ds.plugin_config(
217 "env-plugin-list"
218 )
227 def test_plugin_config_file(app_client):
228 open(TEMP_PLUGIN_SECRET_FILE, "w").write("FROM_FILE")
229 assert {"foo": "FROM_FILE"} == app_client.ds.plugin_config("file-plugin")
230 # Ensure secrets aren't visible in /-/metadata.json
231 metadata = app_client.get("/-/metadata.json")
datasette-atom/datasette_atom/__init__.py
51 if query_name:
52 # Check allow_unsafe_html_in_canned_queries
53 plugin_config = datasette.plugin_config("datasette-atom")
54 if plugin_config:
55 allow_unsafe_html_in_canned_queries = plugin_config.get(
datasette-auth-existing-cookies/datasette_auth_existing_cookies/__init__.py
10 @hookimpl(trylast=True)
11 def asgi_wrapper(datasette):
12 config = datasette.plugin_config("datasette-auth-existing-cookies") or {}
13 api_url = config["api_url"]
14 auth_redirect_url = config["auth_redirect_url"]
datasette-auth-github/datasette_auth_github/views.py
15
16 async def github_auth_start(datasette):
17 config = datasette.plugin_config("datasette-auth-github")
18 verify_config(config)
19 if config.get("load_teams") or config.get("load_orgs"):
39
40 async def github_auth_callback(datasette, request, scope, receive, send):
41 config = datasette.plugin_config("datasette-auth-github")
42 verify_config(config)
43 if not request.args.get("code"):
datasette-auth-passwords/datasette_auth_passwords/__init__.py
22
23 async def password_login(request, datasette):
24 config = datasette.plugin_config("datasette-auth-passwords") or {}
25 accounts = {
26 key.split("_password_hash")[0]: value
datasette-auth-tokens/datasette_auth_tokens/__init__.py
6 def actor_from_request(datasette, request):
7 async def inner():
8 config = datasette.plugin_config("datasette-auth-tokens") or {}
9 allowed_tokens = config.get("tokens") or []
10 authorization = request.headers.get("authorization")
datasette-block/datasette_block/__init__.py
5 @hookimpl
6 def asgi_wrapper(datasette):
7 config = datasette.plugin_config("datasette-block") or {}
8 prefixes = config.get("prefixes") or []
9
datasette-block-robots/datasette_block_robots/__init__.py
4
5 def robots_txt(datasette):
6 config = datasette.plugin_config("datasette-block-robots") or {}
7 literal = config.get("literal")
8 if literal:
26 @hookimpl
27 def startup(datasette):
28 config = datasette.plugin_config("datasette-block-robots") or {}
29 assert not (
30 config.get("disallow") and config.get("literal")
datasette-cluster-map/datasette_cluster_map/__init__.py
30 return []
31 config = (
32 datasette.plugin_config("datasette-cluster-map", database=database, table=table)
33 or {}
34 )
76 columns = [column.lower() for column in columns]
77 config = (
78 datasette.plugin_config("datasette-cluster-map", database=database, table=table)
79 or {}
80 )
datasette-edit-templates/datasette_edit_templates/__init__.py
50
51 def get_database(datasette):
52 plugin_config = datasette.plugin_config("datasette-edit-templates") or {}
53 return datasette.get_database(plugin_config.get("database"))
54
datasette-graphql/datasette_graphql/__init__.py
97 )
98
99 config = datasette.plugin_config("datasette-graphql") or {}
100 context = {
101 "time_started": time.monotonic(),
192 def startup(datasette):
193 # Validate configuration
194 config = datasette.plugin_config("datasette-graphql") or {}
195 if "databases" in config:
196 for database_name in config["databases"].keys():
datasette-graphql/datasette_graphql/utils.py
236 schema=graphene.Schema(
237 query=Query,
238 auto_camelcase=(datasette.plugin_config("datasette-graphql") or {}).get(
239 "auto_camelcase", False
240 ),
360 fks_by_column = {fk.column: fk for fk in meta.foreign_keys}
361
362 table_plugin_config = datasette.plugin_config(
363 "datasette-graphql", database=db.name, table=table
364 )
datasette-indieauth/datasette_indieauth/__init__.py
230 if action != "view-instance":
231 return None
232 plugin_config = datasette.plugin_config("datasette-indieauth") or {}
233 if plugin_config.get("restrict_access") is None:
234 return None
datasette-init/datasette_init/__init__.py
6 def startup(datasette):
7 async def inner():
8 config = datasette.plugin_config("datasette-init")
9 if not config:
10 return
datasette-insert/datasette_insert/__init__.py
84 if action != "insert:all":
85 return None
86 plugin_config = datasette.plugin_config("datasette-insert") or {}
87 if "allow" in plugin_config:
88 return actor_matches_allow(actor, plugin_config["allow"])
datasette-leaflet-geojson/datasette_leaflet_geojson/__init__.py
61 def extra_body_script(datasette, database, table):
62 config = (
63 datasette.plugin_config(
64 "datasette-leaflet-geojson", database=database, table=table
65 )
datasette-mask-columns/datasette_mask_columns/__init__.py
9 return sqlite3.SQLITE_OK
10 masks = (
11 datasette.plugin_config("datasette-mask-columns", database=database) or {}
12 )
13 columns_to_mask = masks.get(table) or None
29 @hookimpl()
30 def render_cell(column, table, database, datasette):
31 masks = datasette.plugin_config("datasette-mask-columns", database=database) or {}
32 columns_to_mask = masks.get(table) or set()
33 if column in columns_to_mask:
datasette-media/datasette_media/__init__.py
22 async def serve_media(datasette, request, send):
23 global transform_executor
24 plugin_config = datasette.plugin_config("datasette-media") or {}
25 pool_size = plugin_config.get("transform_threads") or 4
26 if transform_executor is None:
datasette-permissions-sql/datasette_permissions_sql/__init__.py
20 value = json.dumps(value, default=repr)
21 params["actor_{}".format(key)] = value
22 for rule in datasette.plugin_config("datasette-permissions-sql") or []:
23 sql = rule["sql"]
24 rule_action = rule.get("action")
datasette-render-markdown/datasette_render_markdown/__init__.py
13 should_convert = False
14 config = (
15 datasette.plugin_config(
16 "datasette-render-markdown", database=database, table=table
17 )
datasette-render-timestamps/datasette_render_timestamps/__init__.py
18 def render_cell(value, column, table, database, datasette):
19 config = (
20 datasette.plugin_config(
21 "datasette-render-timestamps", database=database, table=table
22 )
datasette-ripgrep/datasette_ripgrep/__init__.py
81 globs = [g.strip() for g in request.args.getlist("glob") if g.strip()]
82
83 config = datasette.plugin_config("datasette-ripgrep") or {}
84 time_limit = config.get("time_limit") or 1.0
85 max_lines = config.get("max_lines") or 2000
123 async def view_file(request, datasette):
124 await check_permission(request, datasette)
125 config = datasette.plugin_config("datasette-ripgrep") or {}
126 subpath = urllib.parse.unquote(request.url_vars["subpath"])
127 path = config.get("path")
datasette-seaborn/datasette_seaborn/__init__.py
28 }
29
30 plugin_config = datasette.plugin_config("datasette-seaborn") or {}
31 render_time_limit = plugin_config.get("render_time_limit") or DEFAULT_TIME_LIMIT
32
datasette-tiles/datasette_tiles/utils.py
32
33 async def tiles_stack_database_order(datasette):
34 config = datasette.plugin_config("datasette-tiles") or {}
35 stack_order = config.get("tiles-stack-order")
36 if not stack_order:
dogsheep-beta/dogsheep_beta/__init__.py
57 from datasette.utils import path_with_removed_args, path_with_replaced_args
58
59 config = datasette.plugin_config("dogsheep-beta") or {}
60 database_name = config.get("database") or datasette.get_database().name
61 dogsheep_beta_config_file = config["config_file"]
datasette/tests/plugins/my_plugin.py
19
20 def prepare_connection_args():
21 return 'database={}, datasette.plugin_config("name-of-plugin")={}'.format(
22 database, datasette.plugin_config("name-of-plugin")
23 )
24
77 "database": database,
78 "table": table,
79 "config": datasette.plugin_config(
80 "name-of-plugin",
81 database=database,
106 "table": table,
107 "database": database,
108 "config": datasette.plugin_config(
109 "name-of-plugin",
110 database=database,