mirror of
https://github.com/Mic92/sops-nix.git
synced 2025-12-26 22:24:59 +08:00
Adds an extra check to determine if the placeholder ocurrs in template content before actually reading the corresponding secret file. In terms of performance, this adds an extra string search, but removes possibly unneceassary file reading if the secret is not used in the template, though both of them should be negligible in most cases. Fixes Mic92/sops-nix#496.
26 lines
532 B
Python
26 lines
532 B
Python
from sys import argv
|
|
|
|
|
|
def substitute(target: str, subst: str) -> str:
|
|
with open(target) as f:
|
|
content = f.read()
|
|
|
|
with open(subst) as f:
|
|
subst_pairs = f.read().splitlines()
|
|
|
|
for pair in subst_pairs:
|
|
placeholder, path = pair.split()
|
|
if placeholder in content:
|
|
with open(path) as f:
|
|
content = content.replace(placeholder, f.read())
|
|
|
|
return content
|
|
|
|
|
|
def main() -> None:
|
|
target = argv[1]
|
|
subst = argv[2]
|
|
print(substitute(target, subst))
|
|
|
|
|
|
main()
|