cora-vault 0.1.0__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.
cora_vault/__init__.py ADDED
@@ -0,0 +1,6 @@
1
+ """Cora Vault Python client — fetch scoped secrets into your services."""
2
+
3
+ from .client import Vault, VaultError
4
+
5
+ __all__ = ["Vault", "VaultError"]
6
+ __version__ = "0.1.0"
cora_vault/client.py ADDED
@@ -0,0 +1,70 @@
1
+ import json
2
+ import os
3
+ import ssl
4
+ import urllib.error
5
+ import urllib.parse
6
+ import urllib.request
7
+
8
+
9
+ class VaultError(RuntimeError):
10
+ """Base exception for Vault operations."""
11
+
12
+
13
+ class Vault:
14
+ def __init__(self, endpoint: str = "http://localhost:3000", verify_ssl: bool = True) -> None:
15
+ self.endpoint = endpoint.rstrip("/")
16
+ self.verify_ssl = verify_ssl
17
+
18
+ def _get_ssl_context(self) -> ssl.SSLContext:
19
+ if not self.verify_ssl:
20
+ ctx = ssl.create_default_context()
21
+ ctx.check_hostname = False
22
+ ctx.verify_mode = ssl.CERT_NONE
23
+ return ctx
24
+ return ssl.create_default_context()
25
+
26
+ def load_cluster(self, vault_cluster: str, api_key: str | None = None) -> dict[str, str]:
27
+ """Fetch the active secret for a cluster.
28
+
29
+ Returns {"token_value": ..., "label": ..., ...} and mirrors the
30
+ fields into os.environ (upper-cased) for drop-in config use.
31
+ """
32
+ url = f"{self.endpoint}/api/embed/{urllib.parse.quote(vault_cluster, safe='')}"
33
+
34
+ headers = {}
35
+ if api_key:
36
+ headers["x-api-key"] = api_key
37
+
38
+ req = urllib.request.Request(url, headers=headers)
39
+
40
+ try:
41
+ context = self._get_ssl_context()
42
+ with urllib.request.urlopen(req, timeout=10, context=context) as res:
43
+ data = json.load(res)
44
+ except urllib.error.HTTPError as e:
45
+ try:
46
+ detail = json.load(e).get("error", "")
47
+ except Exception:
48
+ detail = ""
49
+
50
+ if e.code == 401:
51
+ raise VaultError("missing service key (set VAULT_API_KEY)") from None
52
+ if e.code == 403:
53
+ raise VaultError(f"forbidden: {detail or 'key rejected / IP not allowlisted'}") from None
54
+ if e.code == 404:
55
+ raise VaultError(f'no active secret for "{vault_cluster}"') from None
56
+ if e.code == 429:
57
+ raise VaultError("rate limited — back off and retry") from None
58
+ raise VaultError(f"unexpected status {e.code}: {detail}") from None
59
+ except urllib.error.URLError as e:
60
+ raise VaultError(f"failed to reach Vault server: {e.reason}") from None
61
+
62
+ injected: dict[str, str] = {}
63
+ if isinstance(data, dict):
64
+ for key, value in data.items():
65
+ if value is not None:
66
+ env_key = str(key).upper()
67
+ env_val = str(value)
68
+ os.environ[env_key] = env_val
69
+ injected[str(key)] = env_val
70
+ return injected
@@ -0,0 +1,54 @@
1
+ Metadata-Version: 2.4
2
+ Name: cora-vault
3
+ Version: 0.1.0
4
+ Summary: Minimal Python client for Cora Vault secret engines
5
+ Author: mentor
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/kenmentor/cora-vault
8
+ Project-URL: Repository, https://github.com/kenmentor/cora-vault
9
+ Keywords: vault,secrets,key-management,devops
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Security
20
+ Classifier: Topic :: System :: Systems Administration
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Dynamic: license-file
25
+
26
+ # cora-vault-client
27
+
28
+ Minimal Python client for [Cora Vault](https://github.com/kenmentor/cora-vault)
29
+ secret engines. Stdlib only — no dependencies.
30
+
31
+ ## Install
32
+
33
+ ```bash
34
+ pip install cora-vault-client
35
+ ```
36
+
37
+ ## Use
38
+
39
+ ```python
40
+ import os
41
+ from cora_vault import Vault
42
+
43
+ vault = Vault(endpoint="http://localhost:3000") # https in production
44
+ secret = vault.load_cluster("shop/prod", api_key="cv_...")
45
+ print(secret["token_value"]) # or os.environ["TOKEN_VALUE"]
46
+ ```
47
+
48
+ `load_cluster` returns `{"token_value", "label", "cluster", "expires_at"}`
49
+ and mirrors the fields into `os.environ` (upper-cased) for drop-in config
50
+ use. Raises `VaultError` with a plain-English reason on 401/403/404/429.
51
+
52
+ Generate the per-engine API key in the vault dashboard
53
+ (engine → Settings → API keys). Service keys are presented as the
54
+ `x-api-key` header.
@@ -0,0 +1,7 @@
1
+ cora_vault/__init__.py,sha256=PdkGfCZxyWKQClnxsAdVs6zEBUyp46mbjQxrNrdxlQU,172
2
+ cora_vault/client.py,sha256=eu6htsyffLD7HQ4qpdoFadVF466Ptb0zHPH8EDGq2k4,2592
3
+ cora_vault-0.1.0.dist-info/licenses/LICENSE,sha256=LBa4710cb-uXCK9L2vsLaobvod-dunlaicTpNx6WX-Y,1063
4
+ cora_vault-0.1.0.dist-info/METADATA,sha256=WlNaRVX4f04D0oMH_QB12HdBrSqVN_B9x2ZMgVV1fM0,1830
5
+ cora_vault-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
6
+ cora_vault-0.1.0.dist-info/top_level.txt,sha256=01zp3johfrs1HUTXy-l-tqMcVSDYiqJ4C2Hb1fpc9Mw,11
7
+ cora_vault-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 mentor
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.
@@ -0,0 +1 @@
1
+ cora_vault