Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions homeassistant/components/stream/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@

_LOGGER = logging.getLogger(__name__)

STREAM_SOURCE_RE = re.compile("//(.*):(.*)@")
STREAM_SOURCE_RE = re.compile("//.*:.*@")


def redact_credentials(data):
"""Redact credentials from string data."""
return STREAM_SOURCE_RE.sub("//****:****@", data)


def create_stream(hass, stream_source, options=None):
Expand Down Expand Up @@ -176,9 +181,7 @@ def start(self):
target=self._run_worker,
)
self._thread.start()
_LOGGER.info(
"Started stream: %s", STREAM_SOURCE_RE.sub("//", str(self.source))
)
_LOGGER.info("Started stream: %s", redact_credentials(str(self.source)))

def update_source(self, new_source):
"""Restart the stream with a new stream source."""
Expand Down Expand Up @@ -244,9 +247,7 @@ def _stop(self):
self._thread_quit.set()
self._thread.join()
self._thread = None
_LOGGER.info(
"Stopped stream: %s", STREAM_SOURCE_RE.sub("//", str(self.source))
)
_LOGGER.info("Stopped stream: %s", redact_credentials(str(self.source)))

async def async_record(self, video_path, duration=30, lookback=5):
"""Make a .mp4 recording from a provided stream."""
Expand Down
6 changes: 2 additions & 4 deletions homeassistant/components/stream/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import av

from . import STREAM_SOURCE_RE
from . import redact_credentials
from .const import (
AUDIO_CODECS,
MAX_MISSING_DTS,
Expand Down Expand Up @@ -128,9 +128,7 @@ def stream_worker(source, options, segment_buffer, quit_event):
try:
container = av.open(source, options=options, timeout=STREAM_TIMEOUT)
except av.AVError:
_LOGGER.error(
"Error opening stream %s", STREAM_SOURCE_RE.sub("//", str(source))
)
_LOGGER.error("Error opening stream %s", redact_credentials(str(source)))
return
try:
video_stream = container.streams.video[0]
Expand Down
2 changes: 1 addition & 1 deletion tests/components/stream/test_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,4 @@ async def test_recorder_log(hass, caplog):
with patch.object(hass.config, "is_allowed_path", return_value=True):
await stream.async_record("/example/path")
assert "https://abcd:efgh@foo.bar" not in caplog.text
assert "https://foo.bar" in caplog.text
assert "https://****:****@foo.bar" in caplog.text
2 changes: 1 addition & 1 deletion tests/components/stream/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,4 +588,4 @@ async def test_worker_log(hass, caplog):
)
await hass.async_block_till_done()
assert "https://abcd:efgh@foo.bar" not in caplog.text
assert "https://foo.bar" in caplog.text
assert "https://****:****@foo.bar" in caplog.text