automizor 0.3.0__py3-none-any.whl → 0.3.1__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.
automizor/__init__.py CHANGED
@@ -1 +1 @@
1
- version = "0.3.0"
1
+ version = "0.3.1"
@@ -1,7 +1,7 @@
1
1
  from functools import lru_cache
2
2
 
3
+ from ._container import SecretContainer
3
4
  from ._exceptions import AutomizorVaultError
4
- from ._secret import Secret
5
5
 
6
6
 
7
7
  @lru_cache
@@ -11,7 +11,7 @@ def _get_vault():
11
11
  return Vault()
12
12
 
13
13
 
14
- def get_secret(name: str) -> Secret:
14
+ def get_secret(name: str) -> SecretContainer:
15
15
  """
16
16
  Retrieves a secret by its name. Fetches from a local file or queries the
17
17
  `Automizor API`, based on configuration.
@@ -30,7 +30,7 @@ def get_secret(name: str) -> Secret:
30
30
  return vault.get_secret(name)
31
31
 
32
32
 
33
- def set_secret(secret: Secret) -> Secret:
33
+ def set_secret(secret: SecretContainer) -> SecretContainer:
34
34
  """
35
35
  Updates an existing secret. Updates to a local file or to the
36
36
  `Automizor API`, based on configuration.
@@ -51,7 +51,7 @@ def set_secret(secret: Secret) -> Secret:
51
51
 
52
52
  __all__ = [
53
53
  "AutomizorVaultError",
54
- "Secret",
54
+ "SecretContainer",
55
55
  "get_secret",
56
56
  "set_secret",
57
57
  ]
@@ -0,0 +1,68 @@
1
+ from dataclasses import dataclass, fields
2
+
3
+
4
+ def ignore_extra_fields(cls):
5
+ original_post_init = getattr(cls, "__post_init__", None)
6
+
7
+ def __init__(self, **kwargs):
8
+ cls_fields = {field.name: field for field in fields(cls)}
9
+ for name, value in kwargs.items():
10
+ if name in cls_fields:
11
+ setattr(self, name, value)
12
+ if original_post_init:
13
+ original_post_init(self)
14
+
15
+ setattr(cls, "__init__", __init__)
16
+ return cls
17
+
18
+
19
+ @ignore_extra_fields
20
+ @dataclass
21
+ class SecretContainer:
22
+ """
23
+ Represents a secret, comprising a name and its associated values.
24
+
25
+ Attributes:
26
+ description: A description of the secret.
27
+ name: The name of the secret.
28
+ value: The secret's values, stored in a dictionary as key-value pairs.
29
+ """
30
+
31
+ name: str
32
+ value: dict
33
+ description: str = ""
34
+
35
+ def get(self, key, default=None):
36
+ """Return the value for key if key is in the dictionary, else default."""
37
+ return self.value.get(key, default)
38
+
39
+ def items(self):
40
+ """Secret.items() -> a set-like object providing a view on secret's items."""
41
+ return self.value.items()
42
+
43
+ def keys(self):
44
+ """Secret.keys() -> a set-like object providing a view on secret's keys."""
45
+ return self.value.keys()
46
+
47
+ def update(self, pairs: dict) -> None:
48
+ """Update the secret's dictionary with the key-value pairs from pairs."""
49
+ self.value.update(pairs)
50
+
51
+ def __getitem__(self, key):
52
+ return self.value[key]
53
+
54
+ def __setitem__(self, key, value):
55
+ self.value[key] = value
56
+
57
+ def __contains__(self, key):
58
+ return key in self.value
59
+
60
+ def __iter__(self):
61
+ return iter(self.value)
62
+
63
+ def __len__(self):
64
+ return len(self.value)
65
+
66
+ def __repr__(self):
67
+ keys = ", ".join(self.keys())
68
+ return f"Secret(name={self.name}, keys=[{keys}])"
automizor/vault/_vault.py CHANGED
@@ -4,8 +4,8 @@ from dataclasses import asdict
4
4
 
5
5
  import requests
6
6
 
7
+ from ._container import SecretContainer
7
8
  from ._exceptions import AutomizorVaultError
8
- from ._secret import Secret
9
9
 
10
10
 
11
11
  class Vault:
@@ -67,7 +67,7 @@ class Vault:
67
67
  }
68
68
  )
69
69
 
70
- def get_secret(self, name) -> Secret:
70
+ def get_secret(self, name) -> SecretContainer:
71
71
  """
72
72
  Retrieves a secret by its name. Fetches from a local file or queries the
73
73
  `Automizor API`, based on configuration.
@@ -86,7 +86,7 @@ class Vault:
86
86
  return self._read_file_secret(name)
87
87
  return self._read_vault_secret(name)
88
88
 
89
- def set_secret(self, secret: Secret) -> Secret:
89
+ def set_secret(self, secret: SecretContainer) -> SecretContainer:
90
90
  """
91
91
  Updates an existing secret. Updates to a local file or to the
92
92
  `Automizor API`, based on configuration.
@@ -105,22 +105,22 @@ class Vault:
105
105
  return self._write_file_secret(secret)
106
106
  return self._write_vault_secret(secret)
107
107
 
108
- def _read_file_secret(self, name: str) -> Secret:
108
+ def _read_file_secret(self, name: str) -> SecretContainer:
109
109
  with open(self._secret_file, "r", encoding="utf-8") as file:
110
110
  secrets = json.load(file)
111
111
  value = secrets.get(name, {})
112
- return Secret(name=name, value=value)
112
+ return SecretContainer(name=name, value=value)
113
113
 
114
- def _read_vault_secret(self, name: str) -> Secret:
114
+ def _read_vault_secret(self, name: str) -> SecretContainer:
115
115
  url = f"https://{self._api_host}/api/v1/vault/secret/{name}/"
116
116
  try:
117
117
  response = self.session.get(url, timeout=10)
118
118
  response.raise_for_status()
119
- return Secret(**response.json())
119
+ return SecretContainer(**response.json())
120
120
  except Exception as exc:
121
121
  raise AutomizorVaultError(f"Failed to get secret: {exc}") from exc
122
122
 
123
- def _write_file_secret(self, secret: Secret):
123
+ def _write_file_secret(self, secret: SecretContainer):
124
124
  with open(self._secret_file, "r+", encoding="utf-8") as file:
125
125
  secrets = json.load(file)
126
126
  secrets[secret.name] = secret.value
@@ -129,11 +129,11 @@ class Vault:
129
129
  file.truncate()
130
130
  return secret
131
131
 
132
- def _write_vault_secret(self, secret: Secret) -> Secret:
132
+ def _write_vault_secret(self, secret: SecretContainer) -> SecretContainer:
133
133
  url = f"https://{self._api_host}/api/v1/vault/secret/{secret.name}/"
134
134
  try:
135
135
  response = self.session.put(url, timeout=10, json=asdict(secret))
136
136
  response.raise_for_status()
137
- return Secret(**response.json())
137
+ return SecretContainer(**response.json())
138
138
  except Exception as exc:
139
139
  raise AutomizorVaultError(f"Failed to set secret: {exc}") from exc
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: automizor
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: Python Automizor framework
5
5
  Home-page: https://github.com/automizor/automizor
6
6
  Author: Christian Fischer
@@ -1,4 +1,4 @@
1
- automizor/__init__.py,sha256=EqIccytbgmIh3EOfv7QIiksdjJSlB-o2LbyXxRtoMGs,18
1
+ automizor/__init__.py,sha256=sEAhGxRzEBE5t0VjAcJ-336II62pGIQ0eLrs42I-sGU,18
2
2
  automizor/job.py,sha256=L2NkM-BkvJpeO_SH0BMgternD9M83K_Yv_ANhf1k3FI,4354
3
3
  automizor/storage.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  automizor/vault.py,sha256=mluaCcJCMxu2g0iTBJ6ntoZATn8eotfZb4rdzWsBslU,5845
@@ -8,12 +8,13 @@ automizor/job/_job.py,sha256=NkoNnJxmdkqdF-Qxm4taal-Go0COVFo57tZAaWM1ihI,5365
8
8
  automizor/storage/__init__.py,sha256=KuWO-Pb4FQXj68Ewv8QZR9XeKsROCR-wusdWf0osaLw,1674
9
9
  automizor/storage/_exceptions.py,sha256=LOtgshWg3gOFhDZlcMWhXLT_q11zpTBEA85NqKnSi4A,129
10
10
  automizor/storage/_storage.py,sha256=IwTw6PYYNwJtGI4ZfiqY0-SkgCoaYnykkP_hHVuy9IU,5777
11
- automizor/vault/__init__.py,sha256=37KiP4K9y6rphpzW7xAlnQiLjubRBfxzkH_kNRSNg2k,1092
11
+ automizor/vault/__init__.py,sha256=Y3FsdG5cdksVO8nBzIPt8Wwxg8VkFtkpu-kn1xWxrGo,1140
12
+ automizor/vault/_container.py,sha256=QgTZtBQrX8wZSEjJqTkn2_S-rwIRxukdBQYIRd7md_g,1904
12
13
  automizor/vault/_exceptions.py,sha256=Wblvmaj6F0pIiTAH7X3JuxqTprUA5tvuuRAs9YgbiBI,125
13
14
  automizor/vault/_secret.py,sha256=pks_3uvD1IhYirOaZ2cAOxX2r9vzvXqLa-aDzJysreE,1136
14
- automizor/vault/_vault.py,sha256=d8ymE-qSHY31GDEToql9KHUQNLpMzb469MCzvtpie_U,4714
15
- automizor-0.3.0.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
16
- automizor-0.3.0.dist-info/METADATA,sha256=olJvbx__hqQFXHeaXPlSkOzcd4vBKuFAY8Nu1lLyARg,661
17
- automizor-0.3.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
18
- automizor-0.3.0.dist-info/top_level.txt,sha256=gScDy4I3tP6BMYAsTAlBXrxVh3E00zV0UioxwXJOI3Y,10
19
- automizor-0.3.0.dist-info/RECORD,,
15
+ automizor/vault/_vault.py,sha256=G1IryuPfXeMUMoAFmGgPibD70zn307KQLNcNitd3D1A,4825
16
+ automizor-0.3.1.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
17
+ automizor-0.3.1.dist-info/METADATA,sha256=SkNNe2kHyA9aGX2275j7RFOy6GqKb9eN3WwQBT3sRpM,661
18
+ automizor-0.3.1.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
19
+ automizor-0.3.1.dist-info/top_level.txt,sha256=gScDy4I3tP6BMYAsTAlBXrxVh3E00zV0UioxwXJOI3Y,10
20
+ automizor-0.3.1.dist-info/RECORD,,