FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(core): Typing in auth by Tranquility2 · Pull Request #691 · testcontainers/testcontainers-python · GitHub

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

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
15 changes: 9 additions & 6 deletions core/testcontainers/core/auth.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json as json
from collections import namedtuple
from logging import warning
from typing import Optional
from typing import Any, Optional

DockerAuthInfo = namedtuple("DockerAuthInfo", ["registry", "username", "password"])

Expand All @@ -12,7 +12,7 @@
}


def process_docker_auth_config_encoded(auth_config_dict: dict) -> list[DockerAuthInfo]:
def process_docker_auth_config_encoded(auth_config_dict: dict[str, dict[str, dict[str, Any]]]) -> list[DockerAuthInfo]:
"""
Process the auths config.

Expand All @@ -30,16 +30,19 @@ def process_docker_auth_config_encoded(auth_config_dict: dict) -> list[DockerAut
auth_info: list[DockerAuthInfo] = []

auths = auth_config_dict.get("auths")
if not auths:
raise KeyError("No auths found in the docker auth config")

for registry, auth in auths.items():
auth_str = auth.get("auth")
auth_str = str(auth.get("auth"))
auth_str = base64.b64decode(auth_str).decode("utf-8")
username, password = auth_str.split(":")
auth_info.append(DockerAuthInfo(registry, username, password))

return auth_info


def process_docker_auth_config_cred_helpers(auth_config_dict: dict) -> None:
def process_docker_auth_config_cred_helpers(auth_config_dict: dict[str, Any]) -> None:
"""
Process the credHelpers config.

Expand All @@ -56,7 +59,7 @@ def process_docker_auth_config_cred_helpers(auth_config_dict: dict) -> None:
warning(_AUTH_WARNINGS.pop("credHelpers"))


def process_docker_auth_config_store(auth_config_dict: dict) -> None:
def process_docker_auth_config_store(auth_config_dict: dict[str, Any]) -> None:
"""
Process the credsStore config.

Expand All @@ -74,7 +77,7 @@ def process_docker_auth_config_store(auth_config_dict: dict) -> None:
def parse_docker_auth_config(auth_config: str) -> Optional[list[DockerAuthInfo]]:
"""Parse the docker auth config from a string and handle the different formats."""
try:
auth_config_dict: dict = json.loads(auth_config)
auth_config_dict: dict[str, Any] = json.loads(auth_config)
if "credHelpers" in auth_config:
process_docker_auth_config_cred_helpers(auth_config_dict)
if "credsStore" in auth_config:
Expand Down
2 changes: 2 additions & 0 deletions core/tests/test_auth.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
def test_parse_docker_auth_config_encoded():
auth_config_json = '{"auths":{"https://index.docker.io/v1/":{"auth":"dXNlcm5hbWU6cGFzc3dvcmQ="}}}'
auth_info = parse_docker_auth_config(auth_config_json)
assert auth_info
assert len(auth_info) == 1
assert auth_info[0] == DockerAuthInfo(
registry="https://index.docker.io/v1/",
Expand Down Expand Up @@ -37,6 +38,7 @@ def test_parse_docker_auth_config_encoded_multiple():
}
auth_config_json = json.dumps(auth_dict)
auth_info = parse_docker_auth_config(auth_config_json)
assert auth_info
assert len(auth_info) == 3
assert auth_info[0] == DockerAuthInfo(
registry="localhost:5000",
Expand Down

Back | FazBrowse Home | New Git URL