Skip to content

Commit

Permalink
Ref secrets loading method
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik4949 committed Dec 28, 2024
1 parent 35a83d4 commit b3c14c5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add postprocess in apibase model.
- Fallback for ibis drop table
- Add create events waiting on db apply.
- Refactor secrets loading method.

#### New Features & Functionality

Expand Down
37 changes: 23 additions & 14 deletions superduper/misc/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,31 @@


def load_secrets():
"""Help method to load secrets from directory."""
"""Load secrets directory into env vars."""
secrets_dir = CFG.secrets_volume

if not os.path.isdir(secrets_dir):
raise ValueError(f"The path '{secrets_dir}' is not a valid directory.")

for root, _, files in os.walk(secrets_dir):
for file_name in files:
file_path = os.path.join(root, file_name)
try:
with open(file_path, 'r') as file:
content = file.read().strip()

key = file_name
os.environ[key] = content
except Exception as e:
print(f"Error reading file {file_path}: {e}")
raise ValueError(f"The path '{secrets_dir}' is not a valid secrets directory.")

for key_dir in os.listdir(secrets_dir):
key_path = os.path.join(secrets_dir, key_dir)

if not os.path.isdir(key_path):
continue

secret_file_path = os.path.join(key_path, 'secret_string')

if not os.path.isfile(secret_file_path):
print(f"Warning: No 'secret_string' file found in {key_path}.")
continue

try:
with open(secret_file_path, 'r') as file:
content = file.read().strip()

os.environ[key_dir] = content
except Exception as e:
print(f"Error reading file {secret_file_path}: {e}")


def get_file_from_uri(uri):
Expand Down

0 comments on commit b3c14c5

Please sign in to comment.