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

Setting credentials through env. variable are not working #1807

Closed
nierob opened this issue Dec 31, 2019 · 6 comments · Fixed by #1909
Closed

Setting credentials through env. variable are not working #1807

nierob opened this issue Dec 31, 2019 · 6 comments · Fixed by #1909
Labels
kind/bug Something isn't working as expected

Comments

@nierob
Copy link

nierob commented Dec 31, 2019

  • [ x ] I am on the latest Poetry version.
  • [ x ] I have searched the issues of this repo and believe that this is not a duplicate.
  • [ x ] If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • OS version and name: *nix
  • Poetry version: Poetry version 1.0.0

Issue

I'm failing to use env. variables to set custom pypi credentials.

My pyproject.toml contains private pypi's like this:

[[tool.poetry.source]]
url = "https://XXXXX/nexus/repository/pypi-central/simple"
name = "nexus"

I'm running this script:

export POETRY_HTTP_BASIC_NEXUS_USERNAME=****
export POETRY_HTTP_BASIC_NEXUS_PASSWORD=****
poetry install

and it fails with:

[EnvCommandError]
Command ['/opt/.cache/pypoetry/virtualenvs/YYYY-4zvP7SOo-py3.8/bin/pip', 'install', '--no-deps', '--index-url', 'https://XXXXX/nexus/repository/pypi-central/simple', '--extra-index-url', 'https://pypi.org/', 'six==1.12.0'] errored with the following return code 2, and output: 
Looking in indexes: https://RESOLVED-XXXXX/nexus/repository/pypi-central/simple, https://****:****@XXXXX/nexus/repository/epd-pypi/simple, https://pypi.org/
Collecting six==1.12.0

....

File "/opt/.cache/pypoetry/virtualenvs/YYYY-4zvP7SOo-py3.8/lib/python3.8/site-packages/pip/_internal/download.py", line 386, in handle_401
    username, password, save = self._prompt_for_password(parsed.netloc)
  File "/opt/.cache/pypoetry/virtualenvs/YYYY-4zvP7SOo-py3.8/lib/python3.8/site-packages/pip/_internal/download.py", line 358, in _prompt_for_password
    username = ask_input("User for %s: " % netloc)
  File "/opt/.cache/pypoetry/virtualenvs/YYYY-4zvP7SOo-py3.8/lib/python3.8/site-packages/pip/_internal/utils/misc.py", line 281, in ask_input
    return input(message)
EOFError: EOF when reading a line
User for XXXXX: 

I investigated the code and it seems that credentials are never acquired separately from config, but always as a pair. That means that code never ask for http-basic.nexus.password and http-basic.nexus.username, but for http-basic.nexus then the value is used as a dict (search for password_manager.get_http_auth usage). I could not find single test case, so I wrote one, fill free to use it:

diff --git a/tests/config/test_config.py b/tests/config/test_config.py
index 07373ad..72ad236 100644
--- a/tests/config/test_config.py
+++ b/tests/config/test_config.py
@@ -14,3 +14,13 @@ def test_config_get_from_environment_variable(config, environ):

     os.environ["POETRY_VIRTUALENVS_CREATE"] = "false"
     assert not config.get("virtualenvs.create")
+
+def test_basic_http_credentials_through_env(config, environ):
+    assert config.get("http-basic.test_repo") is None
+
+    os.environ["POETRY_HTTP_BASIC_TEST_REPO_USERNAME"] = "foo"
+    os.environ["POETRY_HTTP_BASIC_TEST_REPO_PASSWORD"] = "bar"
+    credentials = config.get("http-basic.test-repo")
+    assert credentials is not None
+    assert credentials["username"] == "foo"
+    assert credentials["password"] == "bar"
@nierob nierob added the kind/bug Something isn't working as expected label Dec 31, 2019
@nierob nierob changed the title Setting credentials through env. variable is not working Setting credentials through env. variable are not working Dec 31, 2019
@seasonedgeek
Copy link

I had a similar issue today. I spent a good part of my evening looking at poetry's source code. It seems, based on poetry's pyproject.toml, that poetry runs on anything python v2.7 thru v3.6.
Have you worked on your issue using, perhaps v3.6 or below?

@nierob
Copy link
Author

nierob commented Jan 12, 2020

Nope, I was trying on python 3.7.5 and some 3.8, I think :(

@nierob
Copy link
Author

nierob commented Feb 1, 2020 via email

@aparkerlue
Copy link

This isn't working on the most recent release, 1.0.8.

@andrmueller
Copy link

I got the same error, but it was not related to the used python version. My mistake in a CI environment was exporting the environment variables POETRY_HTTP_BASIC_XXX_USERNAME + POETRY_HTTP_BASIC_XXX_PASSWORD and executing all the poetry config commands in one step and the poetry install in another where the env variables were not present anymore.

TLDR:

  • set the environment variable right before usage of poetry install. Setting it before the poetry config commands you may execute does not persist them for later executions of poetry install.

Copy link

github-actions bot commented Mar 3, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants