fix(n8n-webhook): auto-load local gog automation env

This commit is contained in:
zap
2026-03-12 19:16:24 +00:00
parent afa48a3aa6
commit 044e36f385
4 changed files with 39 additions and 3 deletions
@@ -12,6 +12,7 @@ from pathlib import Path
DEFAULT_BASE_URL = os.environ.get('N8N_BASE_URL', 'http://192.168.153.113:18808').rstrip('/')
DEFAULT_ACTION_PATH = os.environ.get('N8N_ACTION_PATH', 'openclaw-action').strip('/')
DEFAULT_SECRET_HEADER = os.environ.get('N8N_SECRET_HEADER', 'x-openclaw-secret')
DEFAULT_GOG_ENV_FILE = Path(os.environ.get('GOG_ENV_FILE', '/home/openclaw/.openclaw/credentials/gog.env'))
def fail(msg: str, code: int = 1):
@@ -24,6 +25,30 @@ def run(cmd, *, env=None):
return proc.returncode, proc.stdout, proc.stderr
def load_env_file(path: Path) -> dict:
if not path.exists():
return {}
try:
st = path.stat()
if (st.st_mode & 0o077) != 0:
fail(f'insecure permissions on {path}; expected mode 600-ish')
except FileNotFoundError:
return {}
loaded = {}
for raw_line in path.read_text(encoding='utf-8').splitlines():
line = raw_line.strip()
if not line or line.startswith('#') or '=' not in line:
continue
key, value = line.split('=', 1)
key = key.strip()
value = value.strip()
if len(value) >= 2 and value[0] == value[-1] and value[0] in {'"', "'"}:
value = value[1:-1]
loaded[key] = value
return loaded
def gog_account(args_account: str | None) -> str:
account = args_account or os.environ.get('GOG_ACCOUNT', '').strip()
if not account:
@@ -155,6 +180,9 @@ def main():
ap.add_argument('--secret-header', default=DEFAULT_SECRET_HEADER)
args = ap.parse_args()
file_env = load_env_file(DEFAULT_GOG_ENV_FILE)
os.environ.update({k: v for k, v in file_env.items() if k not in os.environ or not os.environ.get(k)})
secret = webhook_secret()
resolved = call_action(
{