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

Support using environment variables to configure username and passwords #1961

Closed
wants to merge 1 commit into from
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
12 changes: 10 additions & 2 deletions poetry/utils/password_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,19 @@ def delete_pypi_token(self, name):
self._keyring.delete_password(name, "__token__")

def get_http_auth(self, name):
username = self._config.get("http-basic.{}.username".format(name))
password = self._config.get("http-basic.{}.password".format(name))
auth = self._config.get("http-basic.{}".format(name))
if not auth:

if not auth and not (username or password):
return None

username, password = auth["username"], auth.get("password")
if not username:
username = auth['username']

if not password:
password = auth.get('password')

if password is None:
password = self._keyring.get_password(name, username)

Expand Down
18 changes: 18 additions & 0 deletions tests/utils/test_password_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def test_set_http_password(config, mock_available_backend, backend):
assert "password" not in auth


@pytest.paramaterize
def test_get_http_auth(config, mock_available_backend, backend):
backend.set_password("poetry-repository-foo", "bar", "baz")
config.auth_config_source.add_property("http-basic.foo", {"username": "bar"})
Expand All @@ -82,6 +83,23 @@ def test_get_http_auth(config, mock_available_backend, backend):
assert "baz" == auth["password"]


@pytest.mark.parametrize("user_env,password_env,combined", (
("bar", "baz", {}, {"username": "bar", "password": "baz"}),
("bar", None, {"username": "notbar", "password": "baz"}),
(None, "baz", {"username": "bar", "password": "notbaz"}),
(None, None, {"username": "bar", "password": "baz"}),
))
def test_get_http_auth_specific_variables(config, mock_available_backend, backend, user_env, password_env, combined):
if user_env:
config.auth_config_source.add_property("http-basic.foo.username", user_env)
if password_env:
config.auth_config_source.add_property("http-basic.foo.password", password_env)
manager = PasswordManager(config)

auth = manager.get_http_auth("foo")
assert auth == {"username": "bar", "password": "baz"}


def test_delete_http_password(config, mock_available_backend, backend):
backend.set_password("poetry-repository-foo", "bar", "baz")
config.auth_config_source.add_property("http-basic.foo", {"username": "bar"})
Expand Down