mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-09 18:26:30 +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
|
import asyncio
|
||||||
from ipaddress import IPv4Address
|
from ipaddress import IPv4Address
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import re
|
import re
|
||||||
import socket
|
import socket
|
||||||
from typing import Any
|
from typing import Any, Dict
|
||||||
|
|
||||||
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -96,3 +97,12 @@ async def remove_folder(folder: Path, content_only: bool = False) -> None:
|
|||||||
return
|
return
|
||||||
|
|
||||||
_LOGGER.error("Can't remove folder %s: %s", folder, error_msg)
|
_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
|
import async_timeout
|
||||||
|
|
||||||
|
from . import clean_env
|
||||||
from ..exceptions import CodeNotaryBackendError, CodeNotaryError, CodeNotaryUntrusted
|
from ..exceptions import CodeNotaryBackendError, CodeNotaryError, CodeNotaryUntrusted
|
||||||
|
|
||||||
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
||||||
@ -64,6 +65,7 @@ async def vcn_validate(
|
|||||||
stdin=asyncio.subprocess.DEVNULL,
|
stdin=asyncio.subprocess.DEVNULL,
|
||||||
stdout=asyncio.subprocess.PIPE,
|
stdout=asyncio.subprocess.PIPE,
|
||||||
stderr=asyncio.subprocess.DEVNULL,
|
stderr=asyncio.subprocess.DEVNULL,
|
||||||
|
env=clean_env(),
|
||||||
)
|
)
|
||||||
|
|
||||||
async with async_timeout.timeout(10):
|
async with async_timeout.timeout(10):
|
||||||
|
@ -12,6 +12,7 @@ import xml.etree.ElementTree as ET
|
|||||||
|
|
||||||
import sentry_sdk
|
import sentry_sdk
|
||||||
|
|
||||||
|
from . import clean_env
|
||||||
from ..exceptions import (
|
from ..exceptions import (
|
||||||
DBusFatalError,
|
DBusFatalError,
|
||||||
DBusInterfaceError,
|
DBusInterfaceError,
|
||||||
@ -234,6 +235,7 @@ class DBus:
|
|||||||
stdin=asyncio.subprocess.DEVNULL,
|
stdin=asyncio.subprocess.DEVNULL,
|
||||||
stdout=asyncio.subprocess.PIPE,
|
stdout=asyncio.subprocess.PIPE,
|
||||||
stderr=asyncio.subprocess.PIPE,
|
stderr=asyncio.subprocess.PIPE,
|
||||||
|
env=clean_env(),
|
||||||
)
|
)
|
||||||
|
|
||||||
data, error = await proc.communicate()
|
data, error = await proc.communicate()
|
||||||
@ -320,6 +322,7 @@ class DBusSignalWrapper:
|
|||||||
stdin=asyncio.subprocess.DEVNULL,
|
stdin=asyncio.subprocess.DEVNULL,
|
||||||
stdout=asyncio.subprocess.PIPE,
|
stdout=asyncio.subprocess.PIPE,
|
||||||
stderr=asyncio.subprocess.PIPE,
|
stderr=asyncio.subprocess.PIPE,
|
||||||
|
env=clean_env(),
|
||||||
)
|
)
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
Loading…
x
Reference in New Issue
Block a user