rewrap vault output two two whitespaces

This commit is contained in:
2025-05-13 21:06:30 +02:00
parent 1a27b50fb2
commit 7b184700c4

View File

@@ -9,6 +9,7 @@
import argparse import argparse
import json import json
import os import os
import re
import subprocess import subprocess
import sys import sys
@@ -119,6 +120,11 @@ def format_data(data: dict) -> str:
return "\n".join(formatted_strings) return "\n".join(formatted_strings)
def rewrap_text(text: str) -> str:
"""Replace lines starting with exactly 8 spaces with 2 spaces"""
return re.sub(r"(?m)^ {8}", "", text)
def encrypt_string(password: str) -> str: def encrypt_string(password: str) -> str:
"""Encrypt string with ansible-vault""" """Encrypt string with ansible-vault"""
result = subprocess.run( result = subprocess.run(
@@ -128,7 +134,7 @@ def encrypt_string(password: str) -> str:
capture_output=True, capture_output=True,
check=False, check=False,
) )
return result.stdout.strip() return rewrap_text(result.stdout.strip())
def encrypt_file(filename: str) -> str: def encrypt_file(filename: str) -> str: