datasette-secrets 0.1a3__py3-none-any.whl → 0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of datasette-secrets might be problematic. Click here for more details.
- datasette_secrets/__init__.py +24 -12
- {datasette_secrets-0.1a3.dist-info → datasette_secrets-0.2.dist-info}/METADATA +3 -2
- datasette_secrets-0.2.dist-info/RECORD +10 -0
- datasette_secrets-0.1a3.dist-info/RECORD +0 -10
- {datasette_secrets-0.1a3.dist-info → datasette_secrets-0.2.dist-info}/LICENSE +0 -0
- {datasette_secrets-0.1a3.dist-info → datasette_secrets-0.2.dist-info}/WHEEL +0 -0
- {datasette_secrets-0.1a3.dist-info → datasette_secrets-0.2.dist-info}/entry_points.txt +0 -0
- {datasette_secrets-0.1a3.dist-info → datasette_secrets-0.2.dist-info}/top_level.txt +0 -0
datasette_secrets/__init__.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import click
|
|
2
2
|
from cryptography.fernet import Fernet
|
|
3
3
|
import dataclasses
|
|
4
|
-
from datasette import hookimpl, Forbidden,
|
|
4
|
+
from datasette import hookimpl, Forbidden, Response
|
|
5
5
|
from datasette.plugins import pm
|
|
6
6
|
from datasette.utils import await_me_maybe, sqlite3
|
|
7
7
|
import os
|
|
@@ -23,6 +23,9 @@ async def get_secret(datasette, secret_name, actor_id=None):
|
|
|
23
23
|
return os.environ[env_var]
|
|
24
24
|
# Now look it up in the database
|
|
25
25
|
config = get_config(datasette)
|
|
26
|
+
if config is None:
|
|
27
|
+
return None
|
|
28
|
+
encryption_key = config["encryption_key"]
|
|
26
29
|
db = get_database(datasette)
|
|
27
30
|
try:
|
|
28
31
|
db_secret = (
|
|
@@ -35,7 +38,7 @@ async def get_secret(datasette, secret_name, actor_id=None):
|
|
|
35
38
|
return None
|
|
36
39
|
if not db_secret:
|
|
37
40
|
return None
|
|
38
|
-
key = Fernet(
|
|
41
|
+
key = Fernet(encryption_key.encode("utf-8"))
|
|
39
42
|
decrypted = key.decrypt(db_secret["encrypted"])
|
|
40
43
|
# Update the last used timestamp and actor_id
|
|
41
44
|
params = (actor_id, db_secret["id"])
|
|
@@ -86,7 +89,7 @@ create table if not exists datasette_secrets (
|
|
|
86
89
|
def get_database(datasette):
|
|
87
90
|
plugin_config = datasette.plugin_config("datasette-secrets") or {}
|
|
88
91
|
database = plugin_config.get("database") or "_internal"
|
|
89
|
-
if database == "_internal":
|
|
92
|
+
if database == "_internal" and hasattr(datasette, "get_internal_database"):
|
|
90
93
|
return datasette.get_internal_database()
|
|
91
94
|
return datasette.get_database(database)
|
|
92
95
|
|
|
@@ -105,6 +108,8 @@ def get_config(datasette):
|
|
|
105
108
|
|
|
106
109
|
@hookimpl
|
|
107
110
|
def register_permissions(datasette):
|
|
111
|
+
from datasette import Permission
|
|
112
|
+
|
|
108
113
|
return [
|
|
109
114
|
Permission(
|
|
110
115
|
name="manage-secrets",
|
|
@@ -184,15 +189,22 @@ async def secrets_index(datasette, request):
|
|
|
184
189
|
)
|
|
185
190
|
existing_secrets = {row["name"]: dict(row) for row in existing_secrets_result.rows}
|
|
186
191
|
# Try to turn updated_by into actors
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
192
|
+
if hasattr(datasette, "actors_from_ids"):
|
|
193
|
+
actors = await datasette.actors_from_ids(
|
|
194
|
+
{
|
|
195
|
+
row["updated_by"]
|
|
196
|
+
for row in existing_secrets.values()
|
|
197
|
+
if row["updated_by"]
|
|
198
|
+
}
|
|
199
|
+
)
|
|
200
|
+
for secret in existing_secrets.values():
|
|
201
|
+
if secret["updated_by"]:
|
|
202
|
+
actor = actors.get(secret["updated_by"])
|
|
203
|
+
if actor:
|
|
204
|
+
display = (
|
|
205
|
+
actor.get("username") or actor.get("name") or actor.get("id")
|
|
206
|
+
)
|
|
207
|
+
secret["updated_by"] = display
|
|
196
208
|
unset_secrets = [
|
|
197
209
|
secret
|
|
198
210
|
for secret in all_secrets
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: datasette-secrets
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2
|
|
4
4
|
Summary: Manage secrets such as API keys for use with other Datasette plugins
|
|
5
5
|
Author: Datasette
|
|
6
6
|
License: Apache-2.0
|
|
@@ -13,11 +13,12 @@ Classifier: License :: OSI Approved :: Apache Software License
|
|
|
13
13
|
Requires-Python: >=3.8
|
|
14
14
|
Description-Content-Type: text/markdown
|
|
15
15
|
License-File: LICENSE
|
|
16
|
-
Requires-Dist: datasette
|
|
16
|
+
Requires-Dist: datasette
|
|
17
17
|
Requires-Dist: cryptography
|
|
18
18
|
Provides-Extra: test
|
|
19
19
|
Requires-Dist: pytest ; extra == 'test'
|
|
20
20
|
Requires-Dist: pytest-asyncio ; extra == 'test'
|
|
21
|
+
Requires-Dist: datasette-test >=0.3.2 ; extra == 'test'
|
|
21
22
|
|
|
22
23
|
# datasette-secrets
|
|
23
24
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
datasette_secrets/__init__.py,sha256=lPC5NMPvLUrwjiloohdZfdz75prGz8TEkxlIw5kyy4Q,10853
|
|
2
|
+
datasette_secrets/hookspecs.py,sha256=57v14e2Y4o5eZyAgCLpuzp1KZn7CjwLXeKwfq6Zvux8,205
|
|
3
|
+
datasette_secrets/templates/secrets_index.html,sha256=ZgIy_huFZQfnI6GjO0qauWEkTWhkBCM5WrT73Nqq4BY,1737
|
|
4
|
+
datasette_secrets/templates/secrets_update.html,sha256=qMPLVCuKKslqw_In0aSCVobB3maPw9oaYZDQQImdRIU,1678
|
|
5
|
+
datasette_secrets-0.2.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
6
|
+
datasette_secrets-0.2.dist-info/METADATA,sha256=BghKi7npKjiv7dvf5fojZU7AwbMKOv3WNjtrQZ6Re8c,7085
|
|
7
|
+
datasette_secrets-0.2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
8
|
+
datasette_secrets-0.2.dist-info/entry_points.txt,sha256=2083uWbPpGntxRulh8_hVaelQO-xdtjedG6rGzwPUH0,40
|
|
9
|
+
datasette_secrets-0.2.dist-info/top_level.txt,sha256=ZBJKQk-DdDU9Vnwu4x79X9aaEulwGJMoLx62IZJPDaQ,18
|
|
10
|
+
datasette_secrets-0.2.dist-info/RECORD,,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
datasette_secrets/__init__.py,sha256=9OBdUnpRpA6nQOoh-gerQO4vpGclFwTevyprvSDaPn8,10508
|
|
2
|
-
datasette_secrets/hookspecs.py,sha256=57v14e2Y4o5eZyAgCLpuzp1KZn7CjwLXeKwfq6Zvux8,205
|
|
3
|
-
datasette_secrets/templates/secrets_index.html,sha256=ZgIy_huFZQfnI6GjO0qauWEkTWhkBCM5WrT73Nqq4BY,1737
|
|
4
|
-
datasette_secrets/templates/secrets_update.html,sha256=qMPLVCuKKslqw_In0aSCVobB3maPw9oaYZDQQImdRIU,1678
|
|
5
|
-
datasette_secrets-0.1a3.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
6
|
-
datasette_secrets-0.1a3.dist-info/METADATA,sha256=pVAqjHANB1qUe6ltVsV0-JEqFeTGbKsLO_jx17z7xlU,7040
|
|
7
|
-
datasette_secrets-0.1a3.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
8
|
-
datasette_secrets-0.1a3.dist-info/entry_points.txt,sha256=2083uWbPpGntxRulh8_hVaelQO-xdtjedG6rGzwPUH0,40
|
|
9
|
-
datasette_secrets-0.1a3.dist-info/top_level.txt,sha256=ZBJKQk-DdDU9Vnwu4x79X9aaEulwGJMoLx62IZJPDaQ,18
|
|
10
|
-
datasette_secrets-0.1a3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|