Skip to content
Closed
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
1 change: 1 addition & 0 deletions supervisor/docker/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ async def process_pull_image_log(reference: PullLogEntry) -> None:
image,
str(version),
platform=MAP_ARCH[image_arch],
auth=self._get_credentials(image),
)

# Tag latest
Expand Down
13 changes: 12 additions & 1 deletion supervisor/docker/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
FILE_HASSIO_DOCKER,
SOCKET_DOCKER,
BusEvent,
ATTR_USERNAME,
ATTR_PASSWORD,
)
from ..coresys import CoreSys, CoreSysAttributes
from ..exceptions import (
Expand Down Expand Up @@ -432,6 +434,7 @@ async def pull_image(
repository: str,
tag: str = "latest",
platform: str | None = None,
auth: str | dict | None = None,
) -> dict[str, Any]:
"""Pull the specified image and return it.

Expand All @@ -440,8 +443,16 @@ async def pull_image(
raises only if the get fails afterwards. Additionally it fires progress reports for the pull
on the bus so listeners can use that to update status for users.
"""
if isinstance(auth, dict) and ATTR_USERNAME in auth and ATTR_PASSWORD in auth:
auth = auth[ATTR_USERNAME] + ":" + auth[ATTR_PASSWORD]
elif isinstance(auth, str) and ":" in auth:
pass # auth is already viable
else:
_LOGGER.info("Pulling %s without authentication", repository)
auth = None

async for e in self.images.pull(
repository, tag=tag, platform=platform, stream=True
repository, tag=tag, platform=platform, stream=True, auth=auth
):
entry = PullLogEntry.from_pull_log_dict(job_id, e)
if entry.error:
Expand Down
6 changes: 3 additions & 3 deletions tests/docker/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def test_docker_image_platform(
coresys.docker.images.inspect.return_value = {"Id": "test:1.2.3"}
await test_docker_interface.install(AwesomeVersion("1.2.3"), "test", arch=cpu_arch)
coresys.docker.images.pull.assert_called_once_with(
"test", tag="1.2.3", platform=platform, stream=True
"test", tag="1.2.3", platform=platform, stream=True, auth=None
)
coresys.docker.images.inspect.assert_called_once_with("test:1.2.3")

Expand All @@ -68,7 +68,7 @@ async def test_docker_image_default_platform(
):
await test_docker_interface.install(AwesomeVersion("1.2.3"), "test")
coresys.docker.images.pull.assert_called_once_with(
"test", tag="1.2.3", platform="linux/386", stream=True
"test", tag="1.2.3", platform="linux/386", stream=True, auth=None
)

coresys.docker.images.inspect.assert_called_once_with("test:1.2.3")
Expand Down Expand Up @@ -319,7 +319,7 @@ async def capture_log_entry(event: PullLogEntry) -> None:
):
await test_docker_interface.install(AwesomeVersion("1.2.3"), "test")
coresys.docker.images.pull.assert_called_once_with(
"test", tag="1.2.3", platform="linux/386", stream=True
"test", tag="1.2.3", platform="linux/386", stream=True, auth=None
)
coresys.docker.images.inspect.assert_called_once_with("test:1.2.3")

Expand Down
2 changes: 2 additions & 0 deletions tests/homeassistant/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ async def test_core_loads_wrong_image_for_machine(
"ghcr.io/home-assistant/qemux86-64-homeassistant",
"2024.4.0",
platform="linux/amd64",
auth={},
)

container.remove.assert_called_once_with(force=True, v=True)
Expand Down Expand Up @@ -535,6 +536,7 @@ async def test_core_loads_wrong_image_for_architecture(
"ghcr.io/home-assistant/qemux86-64-homeassistant",
"2024.4.0",
platform="linux/amd64",
auth={},
)

container.remove.assert_called_once_with(force=True, v=True)
Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/test_plugin_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ async def test_load_with_incorrect_image(
with patch.object(DockerAPI, "pull_image", return_value=img_data) as pull_image:
await plugin.load()
pull_image.assert_called_once_with(
ANY, correct_image, "2024.4.0", platform="linux/amd64"
ANY, correct_image, "2024.4.0", platform="linux/amd64", auth={}
)

container.remove.assert_called_once_with(force=True, v=True)
Expand Down