datasette-secrets 0.1a0__py3-none-any.whl → 0.1a1__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.

@@ -13,7 +13,7 @@ MAX_NOTE_LENGTH = 100
13
13
  pm.add_hookspecs(hookspecs)
14
14
 
15
15
 
16
- async def get_secret(datasette, secret_name):
16
+ async def get_secret(datasette, secret_name, actor_id=None):
17
17
  secrets_by_name = {secret.name: secret for secret in await get_secrets(datasette)}
18
18
  if secret_name not in secrets_by_name:
19
19
  return None
@@ -24,16 +24,31 @@ async def get_secret(datasette, secret_name):
24
24
  # Now look it up in the database
25
25
  config = get_config(datasette)
26
26
  db = get_database(datasette)
27
- encrypted = (
27
+ db_secret = (
28
28
  await db.execute(
29
- "select encrypted from datasette_secrets where name = ? order by version desc limit 1",
29
+ "select id, encrypted from datasette_secrets where name = ? order by version desc limit 1",
30
30
  (secret_name,),
31
31
  )
32
32
  ).first()
33
- if not encrypted:
33
+ if not db_secret:
34
34
  return None
35
35
  key = Fernet(config["encryption_key"].encode("utf-8"))
36
- decrypted = key.decrypt(encrypted["encrypted"])
36
+ decrypted = key.decrypt(db_secret["encrypted"])
37
+ # Update the last used timestamp and actor_id
38
+ params = (actor_id, db_secret["id"])
39
+ if not actor_id:
40
+ params = (db_secret["id"],)
41
+ await db.execute_write(
42
+ """
43
+ update datasette_secrets
44
+ set last_used_at = datetime('now'),
45
+ last_used_by = {}
46
+ where id = ?
47
+ """.format(
48
+ "?" if actor_id else "null"
49
+ ),
50
+ params,
51
+ )
37
52
  return decrypted.decode("utf-8")
38
53
 
39
54
 
@@ -51,7 +66,6 @@ create table if not exists datasette_secrets (
51
66
  version integer not null default 1,
52
67
  encrypted blob,
53
68
  encryption_key_name text not null,
54
- redacted text,
55
69
  created_at text,
56
70
  created_by text,
57
71
  updated_at text,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: datasette-secrets
3
- Version: 0.1a0
3
+ Version: 0.1a1
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
@@ -135,12 +135,14 @@ To obtain the current value of the secret, use the `await get_secret()` method:
135
135
  ```python
136
136
  from datasette_secrets import get_secret
137
137
 
138
- secret = await get_secret(datasette, "OPENAI_API_KEY")
138
+ # Third argument is the actor_id, optional
139
+ secret = await get_secret(datasette, "OPENAI_API_KEY", "root")
139
140
  ```
140
141
  If the Datasette administrator set a `DATASETTE_SECRETS_OPENAI_API_KEY` environment variable, that will be returned.
141
142
 
142
143
  Otherwise the encrypted value in the database table will be decrypted and returned - or `None` if there is no configured secret.
143
144
 
145
+ The `last_used_at` column is updated every time a secret is accessed. The `last_used_by` column will be set to the actor ID passed to `get_secret()`, or `null` if no actor ID was passed.
144
146
 
145
147
  ## Development
146
148
 
@@ -0,0 +1,10 @@
1
+ datasette_secrets/__init__.py,sha256=u5Hu7mYtbszNmzTyBmsQoyg2V0aS9rJs_NdanZQmgGg,9923
2
+ datasette_secrets/hookspecs.py,sha256=57v14e2Y4o5eZyAgCLpuzp1KZn7CjwLXeKwfq6Zvux8,205
3
+ datasette_secrets/templates/secrets_index.html,sha256=Zr8wmVngxzABB69hM052W8IOHgGIlJLM9KKnDxAYmQI,1510
4
+ datasette_secrets/templates/secrets_update.html,sha256=SQs_TmrCw-eanePGiEnRiqH6OKy_G5iJJcEfg_z6RFg,1463
5
+ datasette_secrets-0.1a1.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
6
+ datasette_secrets-0.1a1.dist-info/METADATA,sha256=UneJmupjhs_jQAB20WaCsQvAWqfH0YIMombKkjQXN50,6417
7
+ datasette_secrets-0.1a1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
8
+ datasette_secrets-0.1a1.dist-info/entry_points.txt,sha256=2083uWbPpGntxRulh8_hVaelQO-xdtjedG6rGzwPUH0,40
9
+ datasette_secrets-0.1a1.dist-info/top_level.txt,sha256=ZBJKQk-DdDU9Vnwu4x79X9aaEulwGJMoLx62IZJPDaQ,18
10
+ datasette_secrets-0.1a1.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- datasette_secrets/__init__.py,sha256=0hepqbZLfwETYcTA6fU2raP3F1igb_Z5OaqwdjByCYY,9514
2
- datasette_secrets/hookspecs.py,sha256=57v14e2Y4o5eZyAgCLpuzp1KZn7CjwLXeKwfq6Zvux8,205
3
- datasette_secrets/templates/secrets_index.html,sha256=Zr8wmVngxzABB69hM052W8IOHgGIlJLM9KKnDxAYmQI,1510
4
- datasette_secrets/templates/secrets_update.html,sha256=SQs_TmrCw-eanePGiEnRiqH6OKy_G5iJJcEfg_z6RFg,1463
5
- datasette_secrets-0.1a0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
6
- datasette_secrets-0.1a0.dist-info/METADATA,sha256=s_AUhTHJOv70M7vKmu-FzEy37FA5DwNpFW76Y7vs0rA,6179
7
- datasette_secrets-0.1a0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
8
- datasette_secrets-0.1a0.dist-info/entry_points.txt,sha256=2083uWbPpGntxRulh8_hVaelQO-xdtjedG6rGzwPUH0,40
9
- datasette_secrets-0.1a0.dist-info/top_level.txt,sha256=ZBJKQk-DdDU9Vnwu4x79X9aaEulwGJMoLx62IZJPDaQ,18
10
- datasette_secrets-0.1a0.dist-info/RECORD,,