doppler-secrets 0.1.0__tar.gz
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,30 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: doppler-secrets
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Dead simple Doppler client
|
|
5
|
+
Home-page: https://github.com/fedecalendino/doppler-secrets
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: doppler,secrets
|
|
8
|
+
Author: Fede Calendino
|
|
9
|
+
Author-email: fede@calendino.com
|
|
10
|
+
Requires-Python: >=3.10,<4.0
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Requires-Dist: cachetools (>=6.1.0,<7.0.0)
|
|
21
|
+
Requires-Dist: ddt (>=1.7.2,<2.0.0)
|
|
22
|
+
Requires-Dist: requests (>=2.32.4,<3.0.0)
|
|
23
|
+
Project-URL: Documentation, https://github.com/fedecalendino/doppler-secrets/blob/main/README.md
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
doppler-secrets
|
|
27
|
+
===============
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .client import Doppler
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import os
|
|
3
|
+
import re
|
|
4
|
+
import json
|
|
5
|
+
import uuid
|
|
6
|
+
from datetime import datetime
|
|
7
|
+
import requests
|
|
8
|
+
from cachetools.func import ttl_cache
|
|
9
|
+
|
|
10
|
+
logger = logging.getLogger(__name__)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Doppler:
|
|
14
|
+
def __init__(self, project: str, config: str, token: str = None, ttl: int = 60 * 60):
|
|
15
|
+
self.project: str = project
|
|
16
|
+
self.config: str = config
|
|
17
|
+
self.token: str = token or os.getenv("DOPPLER_TOKEN")
|
|
18
|
+
self.ttl: int = ttl
|
|
19
|
+
|
|
20
|
+
@property
|
|
21
|
+
def url(self):
|
|
22
|
+
return "https://api.doppler.com/v3/configs/config/secrets"
|
|
23
|
+
|
|
24
|
+
@property
|
|
25
|
+
def headers(self):
|
|
26
|
+
return {
|
|
27
|
+
"Authorization": f"Bearer {self.token}",
|
|
28
|
+
"Content-Type": "application/json",
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def params(self):
|
|
33
|
+
return {
|
|
34
|
+
"project": self.project,
|
|
35
|
+
"config": self.config,
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@ttl_cache(ttl=60 * 60)
|
|
39
|
+
def _get(self) -> dict:
|
|
40
|
+
logger.info("%s/%s > fetching secrets", self.project, self.config)
|
|
41
|
+
|
|
42
|
+
response = requests.get(
|
|
43
|
+
self.url,
|
|
44
|
+
headers=self.headers,
|
|
45
|
+
params=self.params,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
if response.status_code != 200:
|
|
49
|
+
logger.error("%s/%s > failed to fetch secrets: %s", self.project, self.config, response.text)
|
|
50
|
+
response.raise_for_status()
|
|
51
|
+
|
|
52
|
+
return response.json()
|
|
53
|
+
|
|
54
|
+
def get(self, name: str) -> object:
|
|
55
|
+
secrets = self._get()["secrets"]
|
|
56
|
+
|
|
57
|
+
try:
|
|
58
|
+
secret = secrets[name]
|
|
59
|
+
value = secret["computed"]
|
|
60
|
+
type = secret["computedValueType"]["type"]
|
|
61
|
+
|
|
62
|
+
if type == "boolean":
|
|
63
|
+
return value.lower() == "true"
|
|
64
|
+
elif type == "integer":
|
|
65
|
+
return int(value)
|
|
66
|
+
elif type == "decimal":
|
|
67
|
+
return float(value)
|
|
68
|
+
elif type == "date8601":
|
|
69
|
+
return datetime.strptime(value, "%Y-%m-%d").date()
|
|
70
|
+
elif type == "datetime8601":
|
|
71
|
+
return datetime.strptime(value, "%Y-%m-%d %H:%M:%S %z")
|
|
72
|
+
elif type.startswith("uuid"):
|
|
73
|
+
return uuid.UUID(value)
|
|
74
|
+
elif type.startswith("json"):
|
|
75
|
+
return json.loads(value)
|
|
76
|
+
else:
|
|
77
|
+
return value
|
|
78
|
+
except KeyError:
|
|
79
|
+
raise KeyError(f"{name} is not a valid secret")
|
|
80
|
+
|
|
81
|
+
def __getattribute__(self, name: str):
|
|
82
|
+
if bool(re.fullmatch(r"[A-Z_]+", name)):
|
|
83
|
+
return self.get(name)
|
|
84
|
+
|
|
85
|
+
return super().__getattribute__(name)
|
|
86
|
+
|
|
87
|
+
def __getitem__(self, name: str) -> object:
|
|
88
|
+
return self.get(name)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "doppler-secrets"
|
|
3
|
+
description = "Dead simple Doppler client"
|
|
4
|
+
documentation = "https://github.com/fedecalendino/doppler-secrets/blob/main/README.md"
|
|
5
|
+
homepage = "https://github.com/fedecalendino/doppler-secrets"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
version = "0.1.0"
|
|
9
|
+
|
|
10
|
+
authors = [
|
|
11
|
+
"Fede Calendino <fede@calendino.com>",
|
|
12
|
+
]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Intended Audience :: Developers",
|
|
15
|
+
"License :: OSI Approved :: MIT License",
|
|
16
|
+
"Programming Language :: Python :: 3.10",
|
|
17
|
+
"Programming Language :: Python :: 3.11",
|
|
18
|
+
"Programming Language :: Python :: 3.12",
|
|
19
|
+
"Programming Language :: Python :: 3.13",
|
|
20
|
+
]
|
|
21
|
+
keywords = [
|
|
22
|
+
"doppler",
|
|
23
|
+
"secrets",
|
|
24
|
+
]
|
|
25
|
+
packages = [
|
|
26
|
+
{ include = "doppler" },
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[tool.poetry.dependencies]
|
|
30
|
+
python = "^3.10"
|
|
31
|
+
requests = "^2.32.4"
|
|
32
|
+
ddt = "^1.7.2"
|
|
33
|
+
cachetools = "^6.1.0"
|
|
34
|
+
|
|
35
|
+
[tool.poetry.group.dev.dependencies]
|
|
36
|
+
black = "^24.10.0"
|
|
37
|
+
|
|
38
|
+
[tool.poetry.group.test.dependencies]
|
|
39
|
+
ddt = "^1.7.2"
|
|
40
|
+
|
|
41
|
+
[tool.black]
|
|
42
|
+
line-length = 120
|
|
43
|
+
|
|
44
|
+
[build-system]
|
|
45
|
+
requires = ["poetry-core"]
|
|
46
|
+
build-backend = "poetry.core.masonry.api"
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from setuptools import setup
|
|
3
|
+
|
|
4
|
+
packages = \
|
|
5
|
+
['doppler']
|
|
6
|
+
|
|
7
|
+
package_data = \
|
|
8
|
+
{'': ['*']}
|
|
9
|
+
|
|
10
|
+
install_requires = \
|
|
11
|
+
['cachetools>=6.1.0,<7.0.0', 'ddt>=1.7.2,<2.0.0', 'requests>=2.32.4,<3.0.0']
|
|
12
|
+
|
|
13
|
+
setup_kwargs = {
|
|
14
|
+
'name': 'doppler-secrets',
|
|
15
|
+
'version': '0.1.0',
|
|
16
|
+
'description': 'Dead simple Doppler client',
|
|
17
|
+
'long_description': 'doppler-secrets\n===============\n\n\n',
|
|
18
|
+
'author': 'Fede Calendino',
|
|
19
|
+
'author_email': 'fede@calendino.com',
|
|
20
|
+
'maintainer': 'None',
|
|
21
|
+
'maintainer_email': 'None',
|
|
22
|
+
'url': 'https://github.com/fedecalendino/doppler-secrets',
|
|
23
|
+
'packages': packages,
|
|
24
|
+
'package_data': package_data,
|
|
25
|
+
'install_requires': install_requires,
|
|
26
|
+
'python_requires': '>=3.10,<4.0',
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
setup(**setup_kwargs)
|