datadouble-vault 0.0.3__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.
@@ -0,0 +1,130 @@
1
+ # Copyright (c) 2026- Tight Line LLC
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ """The Vault announce adapter for Datadouble.
5
+
6
+ Spec settings::
7
+
8
+ announce:
9
+ - vault:
10
+ address: https://vault.internal.example:8200
11
+ mount: secret # a KV version 2 mount
12
+ path: datadouble/clones # entries go under <path>/<copy id>
13
+
14
+ Each copy gets one KV v2 secret with its labels, location and credentials.
15
+ Releasing a copy deletes the secret and its history. The token comes from
16
+ ``VAULT_TOKEN`` (and ``VAULT_NAMESPACE`` is honoured); it never appears in the
17
+ spec. Works with HashiCorp Vault and OpenBao.
18
+ """
19
+
20
+ import http.client
21
+ import json
22
+ import os
23
+ import urllib.error
24
+ import urllib.request
25
+ from collections.abc import Mapping
26
+ from urllib.parse import quote
27
+
28
+ from pydantic import BaseModel, ConfigDict, Field, JsonValue
29
+
30
+ from datadouble.announce import Announced, AnnounceError, Announcer
31
+ from datadouble.settings import parse_settings, remote
32
+
33
+ _TIMEOUT_SECONDS = 30
34
+
35
+
36
+ class VaultSettings(BaseModel):
37
+ """Settings for the ``vault`` announce adapter."""
38
+
39
+ model_config = ConfigDict(strict=True, frozen=True, extra="forbid")
40
+
41
+ address: str = Field(pattern=r"^https?://")
42
+ mount: str = "secret"
43
+ path: str = "datadouble"
44
+
45
+
46
+ class VaultAnnouncer:
47
+ """One KV v2 secret per copy."""
48
+
49
+ def __init__(self, settings: VaultSettings, environ: Mapping[str, str]) -> None:
50
+ """Talk to ``settings.address`` with the token in ``environ``."""
51
+ self.settings = settings
52
+ token = environ.get("VAULT_TOKEN")
53
+ if not token:
54
+ message = "VAULT_TOKEN is not set"
55
+ raise AnnounceError(message)
56
+ self.headers = {"X-Vault-Token": token, "Content-Type": "application/json"}
57
+ if namespace := environ.get("VAULT_NAMESPACE"):
58
+ self.headers["X-Vault-Namespace"] = namespace
59
+
60
+ def _url(self, kind: str, copy_id: str) -> str:
61
+ path = "/".join(quote(part, safe="") for part in (*self.settings.path.split("/"), copy_id))
62
+ mount = quote(self.settings.mount, safe="")
63
+ return f"{self.settings.address.rstrip('/')}/v1/{mount}/{kind}/{path}"
64
+
65
+ def _request(self, method: str, url: str, body: bytes | None, action: str) -> None:
66
+ request = urllib.request.Request(url, data=body, method=method, headers=self.headers) # noqa: S310 - the address must be http(s), checked in settings
67
+ try:
68
+ with urllib.request.urlopen(request, timeout=_TIMEOUT_SECONDS): # noqa: S310 - as above
69
+ pass
70
+ except urllib.error.HTTPError as error:
71
+ message = f"{action} failed: Vault answered {error.code}"
72
+ raise AnnounceError(message) from None
73
+ except urllib.error.URLError as error:
74
+ message = f"{action} failed: {error.reason}"
75
+ raise AnnounceError(message) from None
76
+ except (OSError, http.client.HTTPException) as error:
77
+ message = f"{action} failed: {type(error).__name__}"
78
+ raise AnnounceError(message) from None
79
+
80
+ def announce(self, copies: tuple[Announced, ...]) -> tuple[str, ...]:
81
+ """Write one secret per copy."""
82
+ written: list[str] = []
83
+ for copy in copies:
84
+ data: dict[str, JsonValue] = {
85
+ "copy_id": copy.copy_id,
86
+ "kind": copy.kind,
87
+ **{f"label_{key.replace('-', '_')}": value for key, value in copy.labels.items()},
88
+ **copy.location,
89
+ **copy.secrets,
90
+ }
91
+ url = self._url("data", copy.copy_id)
92
+ try:
93
+ self._request(
94
+ "POST", url, json.dumps({"data": data}).encode(), f"writing {copy.copy_id}"
95
+ )
96
+ except AnnounceError as error:
97
+ raise AnnounceError(str(error), written=tuple(written)) from None
98
+ written.append(f"vault:{self.settings.mount}/{self.settings.path}/{copy.copy_id}")
99
+ return tuple(written)
100
+
101
+ def withdraw(
102
+ self, copy_ids: tuple[str, ...], _announced: tuple[str, ...], /
103
+ ) -> tuple[str, ...]:
104
+ """Delete each copy's secret and its versions, trying every one.
105
+
106
+ Then one :class:`AnnounceError` names each secret left behind.
107
+ """
108
+ removed: list[str] = []
109
+ failures: list[str] = []
110
+ for copy_id in copy_ids:
111
+ target = f"vault:{self.settings.mount}/{self.settings.path}/{copy_id}"
112
+ try:
113
+ self._request("DELETE", self._url("metadata", copy_id), None, f"deleting {copy_id}")
114
+ except AnnounceError as error:
115
+ failures.append(f"{target} ({error})")
116
+ else:
117
+ removed.append(target)
118
+ if failures:
119
+ message = "left behind: " + "; ".join(failures)
120
+ raise AnnounceError(message)
121
+ return tuple(removed)
122
+
123
+
124
+ @remote("mount", "path")
125
+ def vault_announcer(settings: Mapping[str, JsonValue]) -> Announcer:
126
+ """The entry point named in ``datadouble.announcers``.
127
+
128
+ ``mount`` and ``path`` are inside Vault, not on the job's machine.
129
+ """
130
+ return VaultAnnouncer(parse_settings(VaultSettings, settings, "vault announce"), os.environ)
File without changes
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.5
2
+ Name: datadouble-vault
3
+ Version: 0.0.3
4
+ Summary: Vault announce adapter for Datadouble
5
+ Project-URL: Homepage, https://datadouble.tightlinesoftware.com/
6
+ Project-URL: Source, https://github.com/datadouble/datadouble
7
+ Author: Tight Line LLC
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 2 - Pre-Alpha
11
+ Classifier: Programming Language :: Python :: 3 :: Only
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Classifier: Programming Language :: Python :: 3.15
15
+ Classifier: Topic :: Security
16
+ Classifier: Typing :: Typed
17
+ Requires-Python: >=3.13
18
+ Requires-Dist: datadouble
19
+ Description-Content-Type: text/markdown
20
+
21
+ # datadouble-vault
22
+
23
+ The Vault announce adapter for [Datadouble](https://datadouble.tightlinesoftware.com/):
24
+ one KV version 2 secret per copy, holding where the copy is and its
25
+ credentials. It works with HashiCorp Vault and OpenBao.
26
+
27
+ ```yaml
28
+ announce:
29
+ - vault:
30
+ address: https://vault.internal.example:8200
31
+ mount: secret # the KV v2 mount (default: secret)
32
+ path: datadouble/clones # entries go under <path>/<copy id>
33
+ ```
34
+
35
+ The token comes from `VAULT_TOKEN`; it never appears in the spec.
36
+
37
+ `mount` and `path` are inside Vault, not on the job's machine, so `ci init`
38
+ never mounts them into a job, even when they start with `/`
39
+ ([which settings become mounts](../../docs/ci-cd.md#which-settings-become-mounts)).
@@ -0,0 +1,7 @@
1
+ datadouble_vault/__init__.py,sha256=1t70YvqJDZMD1tIfeLyLE2MyJlviUo3qaihAyQT-LH0,5176
2
+ datadouble_vault/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ datadouble_vault-0.0.3.dist-info/METADATA,sha256=JDisKihHHQAnUNO2M2hw5_Xv5NR8FL8TF0vLx6gKZcM,1446
4
+ datadouble_vault-0.0.3.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
5
+ datadouble_vault-0.0.3.dist-info/entry_points.txt,sha256=0L3kZ3mwDGSGdZHhVvBVsgflG9r-c-uK7vLE3O3ZwFs,65
6
+ datadouble_vault-0.0.3.dist-info/licenses/LICENSE,sha256=2LcT-SSMiSa7vrHsdC41sUWNmkcwZqIYdYBaSVmqqT8,1072
7
+ datadouble_vault-0.0.3.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [datadouble.announcers]
2
+ vault = datadouble_vault:vault_announcer
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026- Tight Line LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.