mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-08 17:56:33 +00:00
Clean env on subprocess (#2819)
* Clean env on subprocess * use new format
This commit is contained in:
parent
9db95c188a
commit
092d526749
@ -2,10 +2,11 @@
|
||||
import asyncio
|
||||
from ipaddress import IPv4Address
|
||||
import logging
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import socket
|
||||
from typing import Any
|
||||
from typing import Any, Dict
|
||||
|
||||
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
||||
|
||||
@ -96,3 +97,12 @@ async def remove_folder(folder: Path, content_only: bool = False) -> None:
|
||||
return
|
||||
|
||||
_LOGGER.error("Can't remove folder %s: %s", folder, error_msg)
|
||||
|
||||
|
||||
def clean_env() -> Dict[str, str]:
|
||||
"""Return a clean env from system."""
|
||||
new_env = {}
|
||||
for key in ("HOME", "PATH", "PWD", "CWD", "SHLVL"):
|
||||
if value := os.environ.get(key):
|
||||
new_env[key] = value
|
||||
return new_env
|
||||
|
@ -9,6 +9,7 @@ from typing import Optional, Set, Tuple, Union
|
||||
|
||||
import async_timeout
|
||||
|
||||
from . import clean_env
|
||||
from ..exceptions import CodeNotaryBackendError, CodeNotaryError, CodeNotaryUntrusted
|
||||
|
||||
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
||||
@ -64,6 +65,7 @@ async def vcn_validate(
|
||||
stdin=asyncio.subprocess.DEVNULL,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.DEVNULL,
|
||||
env=clean_env(),
|
||||
)
|
||||
|
||||
async with async_timeout.timeout(10):
|
||||
|
@ -12,6 +12,7 @@ import xml.etree.ElementTree as ET
|
||||
|
||||
import sentry_sdk
|
||||
|
||||
from . import clean_env
|
||||
from ..exceptions import (
|
||||
DBusFatalError,
|
||||
DBusInterfaceError,
|
||||
@ -234,6 +235,7 @@ class DBus:
|
||||
stdin=asyncio.subprocess.DEVNULL,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE,
|
||||
env=clean_env(),
|
||||
)
|
||||
|
||||
data, error = await proc.communicate()
|
||||
@ -320,6 +322,7 @@ class DBusSignalWrapper:
|
||||
stdin=asyncio.subprocess.DEVNULL,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE,
|
||||
env=clean_env(),
|
||||
)
|
||||
|
||||
return self
|
||||
|
Loading…
x
Reference in New Issue
Block a user