Auto-update: Thu Aug 8 18:20:19 PDT 2024
This commit is contained in:
parent
93bae55f31
commit
57b54218ba
1 changed files with 22 additions and 9 deletions
|
@ -262,21 +262,34 @@ class DirConfig(BaseModel):
|
||||||
else:
|
else:
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def resolve_string_placeholders(self, value: str) -> Path:
|
def resolve_string_placeholders(self, value: str, secrets_data: Dict[str, Any], home_dir: Path) -> Any:
|
||||||
pattern = r'\{\{\s*([^}]+)\s*\}\}'
|
pattern = r'\{\{\s*([^}]+)\s*\}\}'
|
||||||
matches = re.findall(pattern, value)
|
matches = re.findall(pattern, value)
|
||||||
|
|
||||||
for match in matches:
|
for match in matches:
|
||||||
if match == 'HOME':
|
parts = match.split('.')
|
||||||
replacement = str(self.HOME)
|
if len(parts) == 1: # Internal reference
|
||||||
elif hasattr(self, match):
|
replacement = str(home_dir / parts[0].lower())
|
||||||
replacement = str(getattr(self, match))
|
elif len(parts) == 2 and parts[0] == 'Dir':
|
||||||
|
replacement = str(home_dir / parts[1].lower())
|
||||||
|
elif len(parts) == 2 and parts[0] == 'ENV':
|
||||||
|
replacement = os.getenv(parts[1], '')
|
||||||
|
elif len(parts) == 2 and parts[0] == 'SECRET':
|
||||||
|
secret_key = parts[1].strip() # Remove any leading/trailing whitespace
|
||||||
|
replacement = secrets_data.get(secret_key)
|
||||||
|
if replacement is None:
|
||||||
|
warn(f"Secret '{secret_key}' not found in secrets file")
|
||||||
|
replacement = ''
|
||||||
else:
|
else:
|
||||||
replacement = value
|
replacement = value
|
||||||
|
|
||||||
value = value.replace('{{' + match + '}}', replacement)
|
value = value.replace('{{' + match + '}}', str(replacement))
|
||||||
|
|
||||||
|
# Convert to Path if it looks like a file path
|
||||||
|
if isinstance(value, str) and (value.startswith(('/', '~')) or (':' in value and value[1] == ':')):
|
||||||
return Path(value).expanduser()
|
return Path(value).expanduser()
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_dynamic_model(cls, **data):
|
def create_dynamic_model(cls, **data):
|
||||||
|
|
Loading…
Reference in a new issue