Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@hookimpl
def prepare_connection(conn):
conn.create_function("regexp", 2, regexp)
@hookimpl
def asgi_wrapper(datasette):
config = datasette.plugin_config("datasette-auth-github") or {}
client_id = config.get("client_id")
client_secret = config.get("client_secret")
disable_auto_login = bool(config.get("disable_auto_login"))
allow_users = config.get("allow_users")
allow_orgs = config.get("allow_orgs")
allow_teams = config.get("allow_teams")
cookie_ttl = config.get("cookie_ttl") or 60 * 60
cookie_version = config.get("cookie_version")
# require_auth defaults to True unless set otherwise
require_auth = True
if "require_auth" in config:
require_auth = config["require_auth"]
@hookimpl(trylast=True)
def render_cell(value):
if not isinstance(value, str):
return None
stripped = value.strip()
if not (
(stripped.startswith("{") and stripped.endswith("}"))
or (stripped.startswith("[") and stripped.endswith("]"))
):
return None
try:
data = json.loads(value)
except ValueError:
return None
return jinja2.Markup(
'<pre>{data}</pre>'.format(
data=jinja2.escape(json.dumps(data, indent=4))
@hookimpl
def table_filter():
async def inner(view, name, table, request):
# Hacky thing for ?_regexp=
try:
regexp = request.args["_regexp"][0]
except (KeyError, IndexError):
return None
return TableFilter(
human_description_extras=[
'regexp matches "{}"'.format(regexp),
],
where_clauses=[
"text regexp :regexp"
],
params={
"regexp": regexp
@hookimpl
def publish_subcommand(publish):
@publish.command()
@add_common_publish_arguments_and_options
@click.option(
"-n",
"--name",
default="datasette",
help="Application name to use when deploying",
)
def heroku(
files,
metadata,
extra_options,
branch,
template_dir,
plugins_dir,
@hookimpl
def publish_subcommand(publish):
@publish.command()
@add_common_publish_arguments_and_options
@click.option(
"-n",
"--name",
default="datasette",
help="Application name to use when deploying",
)
@click.option("--spatialite", is_flag=True, help="Enable SpatialLite extension")
def cloudrun(
files,
metadata,
extra_options,
branch,
template_dir,
@hookimpl
def publish_subcommand(publish):
@publish.command()
@add_common_publish_arguments_and_options
@click.option(
"-n",
"--name",
default="datasette",
help="Application name to use when deploying",
)
@click.option("--force", is_flag=True, help="Pass --force option to now")
@click.option("--token", help="Auth token to use for deploy")
@click.option("--alias", help="Desired alias e.g. yoursite.now.sh")
@click.option("--spatialite", is_flag=True, help="Enable SpatialLite extension")
def now(
files,
metadata,
@hookimpl
def extra_template_vars(request):
return {"auth": request.scope.get("auth") if request else None}