Skip to content

Commit 3f188bf

Browse files
authored
Merge pull request #7 from dotenv-org/specifiy-path
add feature to specify vault file path
2 parents 4cb2659 + e9ed1fb commit 3f188bf

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/dotenv_vault/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def load_dotenv(
2727
dotenv_vault = DotEnvVault()
2828
if dotenv_vault.dotenv_key:
2929
logger.info('Loading env from encrypted .env.vault')
30-
vault_stream = dotenv_vault.parsed_vault()
30+
vault_stream = dotenv_vault.parsed_vault(dotenv_path=dotenv_path)
3131
# we're going to override the .vault to any existing keys in local
3232
return load_dotenv_file(stream=vault_stream, override=True)
3333
else:

src/dotenv_vault/vault.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from cryptography.exceptions import InvalidTag
88
from base64 import b64decode
99
from urllib.parse import urlparse, parse_qsl
10-
1110
from dotenv.main import DotEnv, find_dotenv
1211

1312

@@ -20,18 +19,19 @@ def __init__(self) -> None:
2019
self.dotenv_key = os.environ.get('DOTENV_KEY')
2120

2221

23-
def parsed_vault(self) -> bytes:
22+
def parsed_vault(self, dotenv_path: str) -> bytes:
2423
"""
2524
Parse information from DOTENV_KEY, and decrypt vault key.
2625
"""
2726
if self.dotenv_key is None: raise DotEnvVaultError("NOT_FOUND_DOTENV_KEY: Cannot find ENV['DOTENV_KEY']")
2827

29-
# .env.vault needs to be present.
30-
env_vault_path = find_dotenv(filename='.env.vault', usecwd=True)
31-
keys = []
32-
if env_vault_path == '':
28+
# if dotenv_path is not present, then it will try to find default .env.vault file
29+
env_vault_path = dotenv_path if dotenv_path else find_dotenv(filename='.env.vault', usecwd=True)
30+
31+
if not env_vault_path:
3332
raise DotEnvVaultError("ENV_VAULT_NOT_FOUND: .env.vault is not present.")
3433

34+
keys = []
3535
dotenv_keys = [i.strip() for i in self.dotenv_key.split(',')]
3636
for _key in dotenv_keys:
3737
# parse DOTENV_KEY, format is a URI

0 commit comments

Comments
 (0)