allow multi-line interactive secrets
All checks were successful
checks / check-links (pull_request) Successful in 20s
checks / checks-impure (pull_request) Successful in 1m52s
checks / checks (pull_request) Successful in 4m15s

This commit is contained in:
Jörg Thalheim 2024-03-13 10:06:10 +01:00
parent c2e43a4e65
commit a9fc8de2d0

View File

@ -2,6 +2,7 @@ import argparse
import importlib
import logging
import os
import subprocess
from collections.abc import Callable
from pathlib import Path
from tempfile import TemporaryDirectory
@ -19,6 +20,15 @@ from .modules import SecretStoreBase
log = logging.getLogger(__name__)
def read_multiline_input(prompt: str = "Finish with Ctrl-D") -> str:
"""
Read multi-line input from stdin.
"""
print(prompt, flush=True)
proc = subprocess.run(["cat"], stdout=subprocess.PIPE, text=True)
return proc.stdout
def generate_service_secrets(
machine: Machine,
service: str,
@ -128,7 +138,12 @@ def generate_secrets(
fact_store = facts_module.FactStore(machine=machine)
if prompt is None:
prompt = lambda text: input(f"{text}: ")
def prompt_func(text: str) -> str:
print(f"{text}: ")
return read_multiline_input()
prompt = prompt_func
with TemporaryDirectory() as tmp:
tmpdir = Path(tmp)