Skip to content

Commit

Permalink
authenticator: allow multiple repos w/ same netloc
Browse files Browse the repository at this point in the history
Co-authored-by: Agni Sairent <[email protected]>
Co-authored-by: Dos Moonen <[email protected]>
  • Loading branch information
3 people committed May 6, 2022
1 parent 5c1bf62 commit 7ffcc23
Show file tree
Hide file tree
Showing 7 changed files with 406 additions and 115 deletions.
20 changes: 20 additions & 0 deletions src/poetry/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ def _all(config: dict, parent_key: str = "") -> dict:
def raw(self) -> dict[str, Any]:
return self._config

@staticmethod
def _get_environment_repositories() -> dict[str, dict[str, str]]:
repositories = {}
pattern = re.compile(r"POETRY_REPOSITORIES_(?P<name>[A-Z_]+)_URL")

for env_key in os.environ.keys():
match = pattern.match(env_key)
if match:
repositories[match.group("name").lower().replace("_", "-")] = {
"url": os.environ[env_key]
}

return repositories

def get(self, setting_name: str, default: Any = None) -> Any:
"""
Retrieve a setting value.
Expand All @@ -112,6 +126,12 @@ def get(self, setting_name: str, default: Any = None) -> Any:
# Looking in the environment if the setting
# is set via a POETRY_* environment variable
if self._use_environment:
if setting_name == "repositories":
# repositories setting is special for now
repositories = self._get_environment_repositories()
if repositories:
return repositories

env = "POETRY_" + "_".join(k.upper().replace("-", "_") for k in keys)
env_value = os.getenv(env)
if env_value is not None:
Expand Down
6 changes: 3 additions & 3 deletions src/poetry/publishing/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ def publish(
logger.debug(
f"Found authentication information for {repository_name}."
)
username = auth["username"]
password = auth["password"]
username = auth.username
password = auth.password

resolved_client_cert = client_cert or get_client_cert(
self._poetry.config, repository_name
)
# Requesting missing credentials but only if there is not a client cert defined.
if not resolved_client_cert:
if not resolved_client_cert and hasattr(self._io, "ask"):
if username is None:
username = self._io.ask("Username:")

Expand Down
Loading

0 comments on commit 7ffcc23

Please sign in to comment.