Skip to content

Commit f4fca43

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 476ac81 commit f4fca43

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

generate_env.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
import os
2+
23
import hvac
34

45
# Configuration for Vault
5-
VAULT_ADDR = 'http://localhost:8200'
6-
VAULT_OIDC_CLIENT_ID = 'your_oidc_client_id'
7-
VAULT_OIDC_ISSUER_URL = 'https://your-oidc-issuer-url'
6+
VAULT_ADDR = "http://localhost:8200"
7+
VAULT_OIDC_CLIENT_ID = "your_oidc_client_id"
8+
VAULT_OIDC_ISSUER_URL = "https://your-oidc-issuer-url"
89

910
# Static variables
10-
STATIC_VARIABLES = {
11-
'API_KEY': 'static_api_key',
12-
'DATABASE_URL': 'static_database_url'
13-
}
11+
STATIC_VARIABLES = {"API_KEY": "static_api_key", "DATABASE_URL": "static_database_url"}
12+
1413

1514
def get_secret_from_vault(path):
1615
client = hvac.Client(url=VAULT_ADDR)
17-
token = client.auth.oidc.login(
18-
role='your_oidc_role',
19-
jwt=os.environ['JWT']
20-
)['auth']['client_token']
21-
16+
token = client.auth.oidc.login(role="your_oidc_role", jwt=os.environ["JWT"])[
17+
"auth"
18+
]["client_token"]
19+
2220
client.token = token
23-
secret = client.secrets.kv.v2.read_secret_version(path=path)['data']['data']
21+
secret = client.secrets.kv.v2.read_secret_version(path=path)["data"]["data"]
2422
return secret
2523

24+
2625
def generate_env_file(env_path):
27-
with open(env_path, 'w') as env_file:
26+
with open(env_path, "w") as env_file:
2827
for key, value in STATIC_VARIABLES.items():
2928
env_file.write(f"{key}={value}\n")
30-
29+
3130
# Add secrets from Vault
3231
vault_secrets = {
33-
'SECRET_KEY': get_secret_from_vault('secret/key'),
34-
'PASSWORD': get_secret_from_vault('secret/password')
32+
"SECRET_KEY": get_secret_from_vault("secret/key"),
33+
"PASSWORD": get_secret_from_vault("secret/password"),
3534
}
36-
35+
3736
for key, value in vault_secrets.items():
3837
env_file.write(f"{key}={value}\n")
3938

40-
if __name__ == '__main__':
41-
env_path = '.env'
39+
40+
if __name__ == "__main__":
41+
env_path = ".env"
4242
generate_env_file(env_path)
4343
print(f"Environment file generated at {env_path}")

0 commit comments

Comments
 (0)