Skip to content

Commit 7ffcc23

Browse files
abnAgni SairentDarsstar
committed
authenticator: allow multiple repos w/ same netloc
Co-authored-by: Agni Sairent <[email protected]> Co-authored-by: Dos Moonen <[email protected]>
1 parent 5c1bf62 commit 7ffcc23

File tree

7 files changed

+406
-115
lines changed

7 files changed

+406
-115
lines changed

src/poetry/config/config.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,20 @@ def _all(config: dict, parent_key: str = "") -> dict:
103103
def raw(self) -> dict[str, Any]:
104104
return self._config
105105

106+
@staticmethod
107+
def _get_environment_repositories() -> dict[str, dict[str, str]]:
108+
repositories = {}
109+
pattern = re.compile(r"POETRY_REPOSITORIES_(?P<name>[A-Z_]+)_URL")
110+
111+
for env_key in os.environ.keys():
112+
match = pattern.match(env_key)
113+
if match:
114+
repositories[match.group("name").lower().replace("_", "-")] = {
115+
"url": os.environ[env_key]
116+
}
117+
118+
return repositories
119+
106120
def get(self, setting_name: str, default: Any = None) -> Any:
107121
"""
108122
Retrieve a setting value.
@@ -112,6 +126,12 @@ def get(self, setting_name: str, default: Any = None) -> Any:
112126
# Looking in the environment if the setting
113127
# is set via a POETRY_* environment variable
114128
if self._use_environment:
129+
if setting_name == "repositories":
130+
# repositories setting is special for now
131+
repositories = self._get_environment_repositories()
132+
if repositories:
133+
return repositories
134+
115135
env = "POETRY_" + "_".join(k.upper().replace("-", "_") for k in keys)
116136
env_value = os.getenv(env)
117137
if env_value is not None:

src/poetry/publishing/publisher.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ def publish(
6969
logger.debug(
7070
f"Found authentication information for {repository_name}."
7171
)
72-
username = auth["username"]
73-
password = auth["password"]
72+
username = auth.username
73+
password = auth.password
7474

7575
resolved_client_cert = client_cert or get_client_cert(
7676
self._poetry.config, repository_name
7777
)
7878
# Requesting missing credentials but only if there is not a client cert defined.
79-
if not resolved_client_cert:
79+
if not resolved_client_cert and hasattr(self._io, "ask"):
8080
if username is None:
8181
username = self._io.ask("Username:")
8282

0 commit comments

Comments
 (0)