Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pip-style authentication when publishing #1

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
23 changes: 20 additions & 3 deletions poetry/console/commands/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,27 @@ def handle(self) -> Optional[int]:
Path(self.option("client-cert")) if self.option("client-cert") else None
)

repository_name = self.option("repository")
username, password = self.option("username"), self.option("password")
if repository_name and not username and not password:
try:
repository = self.poetry.pool.repository(repository_name)
auth = repository.auth
except AttributeError as error:
raise AttributeError(
f"No credentials available for {repository_name}"
) from error
except ValueError:
raise ValueError(f"No repository named {repository_name} found")
else:
if auth:
username = auth.username
password = auth.password

publisher.publish(
self.option("repository"),
self.option("username"),
self.option("password"),
repository_name,
username,
password,
cert,
client_cert,
self.option("dry-run"),
Expand Down
4 changes: 4 additions & 0 deletions poetry/repositories/legacy_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ def __init__(

self._disable_cache = disable_cache

@property
def auth(self) -> Optional[requests.auth.HTTPBasicAuth]:
return self._authenticator.session.auth

@property
def cert(self) -> Optional[Path]:
return self._cert
Expand Down