berryworld 1.0.0.192942__py3-none-any.whl → 1.0.0.193968__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.
- berryworld/generate_env.py +83 -1
- {berryworld-1.0.0.192942.dist-info → berryworld-1.0.0.193968.dist-info}/METADATA +3 -1
- {berryworld-1.0.0.192942.dist-info → berryworld-1.0.0.193968.dist-info}/RECORD +6 -6
- {berryworld-1.0.0.192942.dist-info → berryworld-1.0.0.193968.dist-info}/WHEEL +0 -0
- {berryworld-1.0.0.192942.dist-info → berryworld-1.0.0.193968.dist-info}/licenses/LICENSE +0 -0
- {berryworld-1.0.0.192942.dist-info → berryworld-1.0.0.193968.dist-info}/top_level.txt +0 -0
berryworld/generate_env.py
CHANGED
|
@@ -1,10 +1,92 @@
|
|
|
1
|
-
|
|
1
|
+
import ast
|
|
2
2
|
import yaml
|
|
3
|
+
from .handy_mix import HandyMix
|
|
4
|
+
from azure.identity import ClientSecretCredential
|
|
5
|
+
from azure.keyvault.secrets import SecretClient
|
|
3
6
|
|
|
4
7
|
|
|
5
8
|
class EnvVariables:
|
|
6
9
|
""" Generate the environmental variables to be used by kubernetes """
|
|
7
10
|
|
|
11
|
+
def extract_akv_config_from_tf(self, config_path):
|
|
12
|
+
""" Extract the AKV configuration from the Terraform file
|
|
13
|
+
:param config_path: Path to the Terraform file
|
|
14
|
+
"""
|
|
15
|
+
with open(config_path, "r") as f:
|
|
16
|
+
lines = f.readlines()
|
|
17
|
+
|
|
18
|
+
start, end = None, None
|
|
19
|
+
for idx, line in enumerate(lines):
|
|
20
|
+
if "akv_config" in line and "=" in line and "{" in line:
|
|
21
|
+
start = idx + 1
|
|
22
|
+
if start and "}" in line:
|
|
23
|
+
end = idx
|
|
24
|
+
break
|
|
25
|
+
|
|
26
|
+
if start is None or end is None:
|
|
27
|
+
raise ValueError("akv_config block not found in the tf file")
|
|
28
|
+
|
|
29
|
+
kv_lines = lines[start:end]
|
|
30
|
+
config = {}
|
|
31
|
+
for line in kv_lines:
|
|
32
|
+
if "=" in line:
|
|
33
|
+
key, value = line.strip().split("=", 1)
|
|
34
|
+
key = key.strip()
|
|
35
|
+
value = value.strip()
|
|
36
|
+
|
|
37
|
+
# Use ast.literal_eval to safely evaluate lists or strings
|
|
38
|
+
try:
|
|
39
|
+
parsed_value = ast.literal_eval(value)
|
|
40
|
+
except:
|
|
41
|
+
# fallback if parsing fails
|
|
42
|
+
parsed_value = value.strip('"')
|
|
43
|
+
|
|
44
|
+
config[key] = parsed_value
|
|
45
|
+
|
|
46
|
+
return config
|
|
47
|
+
|
|
48
|
+
def fetch_secrets_by_tag(self, config):
|
|
49
|
+
""" Fetch secrets from Azure Key Vault based on tags
|
|
50
|
+
:param config: Dictionary containing Azure Key Vault configuration
|
|
51
|
+
"""
|
|
52
|
+
tenant_id = config["AZURE-TENANT-ID"]
|
|
53
|
+
client_id = config["AZURE-CLIENT-ID"]
|
|
54
|
+
client_secret = config["AZURE-CLIENT-SECRET"]
|
|
55
|
+
vault_url = f"https://{config['AZURE-KEY-VAULT-NAME']}.vault.azure.net/"
|
|
56
|
+
project_tags = config["AZURE-KEY-VAULT-PROJECT-TAGS"]
|
|
57
|
+
|
|
58
|
+
credential = ClientSecretCredential(tenant_id, client_id, client_secret)
|
|
59
|
+
client = SecretClient(vault_url=vault_url, credential=credential)
|
|
60
|
+
|
|
61
|
+
secrets = {}
|
|
62
|
+
for prop in client.list_properties_of_secrets():
|
|
63
|
+
if prop.tags:
|
|
64
|
+
if any("project" in key and value in project_tags for key, value in prop.tags.items()):
|
|
65
|
+
secret = client.get_secret(prop.name)
|
|
66
|
+
key = str(prop.name)
|
|
67
|
+
secrets[key] = secret.value
|
|
68
|
+
return secrets
|
|
69
|
+
|
|
70
|
+
def generate_akv_env_file(self, config_path=None, env_path=None):
|
|
71
|
+
""" Generate the environment variables file from Azure Key Vault secrets
|
|
72
|
+
:param config_path: Path to the Terraform configuration file (optional)
|
|
73
|
+
:param env_path: Path to the destination .env file (optional)
|
|
74
|
+
"""
|
|
75
|
+
config = self.extract_akv_config_from_tf(config_path)
|
|
76
|
+
secrets = self.fetch_secrets_by_tag(config)
|
|
77
|
+
|
|
78
|
+
# Create .env file for UnitTest
|
|
79
|
+
with open(env_path, "w") as f:
|
|
80
|
+
for key, value in secrets.items():
|
|
81
|
+
f.write(f"{key}={value}\n")
|
|
82
|
+
|
|
83
|
+
def generate_env_tf(self, config_path='./environments/prod/step01.tf', env_path='.env'):
|
|
84
|
+
""" Main function to parse arguments and generate AKV environment variables file.
|
|
85
|
+
:param config_path: Path to the Terraform configuration file
|
|
86
|
+
:param env_path: Path to the destination .env file
|
|
87
|
+
"""
|
|
88
|
+
self.generate_akv_env_file(config_path=config_path, env_path=env_path)
|
|
89
|
+
|
|
8
90
|
@staticmethod
|
|
9
91
|
def generate_env_file(yaml_path='./environments/prd1/step01.yaml', env_path='./.env'):
|
|
10
92
|
""" Save the data from the yaml file into a .env file to be used by decouple
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: berryworld
|
|
3
|
-
Version: 1.0.0.
|
|
3
|
+
Version: 1.0.0.193968
|
|
4
4
|
Summary: Handy classes to improve ETL processes
|
|
5
5
|
Home-page: https://www.berryworld.com
|
|
6
6
|
Author: BerryWorld ltd
|
|
@@ -11,6 +11,8 @@ Classifier: Operating System :: OS Independent
|
|
|
11
11
|
Requires-Python: >=3.11
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
|
+
Requires-Dist: azure-identity>=1.15.0
|
|
15
|
+
Requires-Dist: azure-keyvault-secrets>=4.8.0
|
|
14
16
|
Requires-Dist: cryptography>=3.4.8
|
|
15
17
|
Requires-Dist: msal>=1.14.0
|
|
16
18
|
Requires-Dist: numpy>=1.25.2
|
|
@@ -8,7 +8,7 @@ berryworld/credentials.py,sha256=jJENjLE-qxR0yBtZPMPEOJ6H83bZeo4hI265AerwcUI,954
|
|
|
8
8
|
berryworld/devops.py,sha256=7mRbyZPGzk5ox-6J2etv3NxCcfP4cprG0_Xelh7prn8,9776
|
|
9
9
|
berryworld/email_con.py,sha256=uSBzs_Ijz9pUPWt9e7U3TCB7i6q7hU1bB5vhsTB_tmw,14448
|
|
10
10
|
berryworld/email_logging.py,sha256=LeSrTExhQhar49gJR2wGC1dS0lqsNpFl9pS3eYWqnuo,4936
|
|
11
|
-
berryworld/generate_env.py,sha256=
|
|
11
|
+
berryworld/generate_env.py,sha256=B-d4Tu5M69j4CFfQjby3kNXxndIJhb4O9H-v94L6iwI,11204
|
|
12
12
|
berryworld/handy_mix.py,sha256=ZPr5Z4l5TfyXQjhuLjttGi90whBooTQhB7M-Lq5L1DQ,10683
|
|
13
13
|
berryworld/logging.py,sha256=tOxzaFALQm3aVVEc3I7t8MU6PwgUI9VSnzNCH9yRryo,1013
|
|
14
14
|
berryworld/logic_apps.py,sha256=a0uU4tNO3v2w7grdBv-OOx4hUf7VBIerJpwZ9U-29dQ,14591
|
|
@@ -26,12 +26,12 @@ berryworld/verify_keys.py,sha256=X4Nuz3o0XbRDYofbJGvxIDeN5gfWj19PN7lhO6T3hR8,435
|
|
|
26
26
|
berryworld/vivantio.py,sha256=QfZo0UKqkzVRg_LyiwivNd3aEup4TH57x4KxLZkCJwc,10627
|
|
27
27
|
berryworld/vivantio_logging.py,sha256=ciy7gA4u3FrgUIpEBnMgocbNPp6jcu9TPoy-kLcrTZU,5736
|
|
28
28
|
berryworld/xml_parser.py,sha256=HWD71NaTN3DaIOGT6Wzxs4CEsroFhGQwe9iPLIL80Co,957
|
|
29
|
-
berryworld-1.0.0.
|
|
29
|
+
berryworld-1.0.0.193968.dist-info/licenses/LICENSE,sha256=vtkVCJM6E2af2gnsi2XxKPr4WY-uIbvzVLXieFND0UU,1074
|
|
30
30
|
tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
31
31
|
tests/test_allocation_config.py,sha256=e12l6fE9U57eSPS35g6ekJ_hol7-RHg89JV60_m1BlE,4633
|
|
32
32
|
tests/test_handy_mix_config.py,sha256=Un56mz9KJmdn4K4OwzHAHLSRzDU1Xv2nFrONNuzOG04,2594
|
|
33
33
|
tests/test_xml_parser.py,sha256=3QTlhFEd6KbK6nRFKZnc35tad6wqukTbe4QrFi8mr_8,859
|
|
34
|
-
berryworld-1.0.0.
|
|
35
|
-
berryworld-1.0.0.
|
|
36
|
-
berryworld-1.0.0.
|
|
37
|
-
berryworld-1.0.0.
|
|
34
|
+
berryworld-1.0.0.193968.dist-info/METADATA,sha256=wwolMjQBxtyUn1NAmEF6jipmUumebMCqM2kwBfqNg_I,1445
|
|
35
|
+
berryworld-1.0.0.193968.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
36
|
+
berryworld-1.0.0.193968.dist-info/top_level.txt,sha256=GIZ5qy-P5oxfEH755vA1IMFeTVdX3-40JxMe6nOe5I8,17
|
|
37
|
+
berryworld-1.0.0.193968.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|