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

Http basic config password starting with "-" #2889

Closed
3 tasks done
jeremad opened this issue Sep 7, 2020 · 10 comments · Fixed by #4552
Closed
3 tasks done

Http basic config password starting with "-" #2889

jeremad opened this issue Sep 7, 2020 · 10 comments · Fixed by #4552
Labels
kind/bug Something isn't working as expected

Comments

@jeremad
Copy link

jeremad commented Sep 7, 2020

  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • OS version and name: ubuntu 20.04 (also tested on mac)
  • Poetry version: 1.0.10
  • Link of a Gist with the contents of your pyproject.toml file: N/A

Issue

I way to use poetry with a private repository, as described in the documentation I run:

poetry -vvv config http-basic.foo username "-some_password"

Note the - at the beginning of the password

I have the following error:

[NoSuchOptionException]
The "-s" option does not exist.

Traceback (most recent call last):
  File "/home/jeremad/.poetry/lib/poetry/_vendor/py3.8/clikit/console_application.py", line 123, in run
    io = io_factory(
  File "/home/jeremad/.poetry/lib/poetry/console/config/application_config.py", line 168, in create_io
    resolved_command = application.resolve_command(args)
  File "/home/jeremad/.poetry/lib/poetry/_vendor/py3.8/clikit/console_application.py", line 110, in resolve_command
    return self._config.command_resolver.resolve(args, self)
  File "/home/jeremad/.poetry/lib/poetry/_vendor/py3.8/clikit/resolver/default_resolver.py", line 43, in resolve
    result = self.process_default_commands(args, application.default_commands)
  File "/home/jeremad/.poetry/lib/poetry/_vendor/py3.8/clikit/resolver/default_resolver.py", line 104, in process_default_commands
    if resolved_command.is_parsable():
  File "/home/jeremad/.poetry/lib/poetry/_vendor/py3.8/clikit/resolver/resolve_result.py", line 43, in is_parsable
    self._parse()
  File "/home/jeremad/.poetry/lib/poetry/_vendor/py3.8/clikit/resolver/resolve_result.py", line 49, in _parse
    self._parsed_args = self._command.parse(self._raw_args)
  File "/home/jeremad/.poetry/lib/poetry/_vendor/py3.8/clikit/api/command/command.py", line 113, in parse
    return self._config.args_parser.parse(args, self._args_format, lenient)
  File "/home/jeremad/.poetry/lib/poetry/_vendor/py3.8/clikit/args/default_args_parser.py", line 53, in parse
    self._parse(args, _fmt, lenient)
  File "/home/jeremad/.poetry/lib/poetry/_vendor/py3.8/clikit/args/default_args_parser.py", line 103, in _parse
    self._parse_short_option(token, tokens, fmt, lenient)
  File "/home/jeremad/.poetry/lib/poetry/_vendor/py3.8/clikit/args/default_args_parser.py", line 258, in _parse_short_option
    self._parse_short_option_set(name, tokens, fmt, lenient)
  File "/home/jeremad/.poetry/lib/poetry/_vendor/py3.8/clikit/args/default_args_parser.py", line 280, in _parse_short_option_set
    raise NoSuchOptionException(name[i])
@jeremad jeremad added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Sep 7, 2020
jeremad pushed a commit to jeremad/poetry that referenced this issue Sep 7, 2020
@jeremad
Copy link
Author

jeremad commented Sep 7, 2020

a test that reproduces the error: jeremad@7233156

@bneijt
Copy link

bneijt commented Sep 7, 2020

Sounds a lot like #929 where people noticed the run command does not support the double dash approach to stop the argument parser from parsing further commands. The ArgvArgs clikit argument parser has the proper "takewhile" approach witch stops at a double dash, we should consider trying to mimic that approach in my opinion.

From ArgvArgs:

self._option_tokens = list(
            itertools.takewhile(lambda arg: arg != "--", self.tokens)
        )

@jeremad
Copy link
Author

jeremad commented Sep 8, 2020

It sure does look like it!

@szEvEz
Copy link

szEvEz commented May 26, 2021

We are also running in the exact same issue. We're running poetry config in our Gitlab CI and make use of $CI_REGISTRY_PASSWORD", which also can start with a - , therefore resulting into the following stacktrace

poetry config http-basic.gitlab -xtihg              

  Stack trace:

  11  ~/.poetry/lib/poetry/_vendor/py3.8/clikit/console_application.py:123 in run
      io = io_factory(

  10  ~/.poetry/lib/poetry/console/config/application_config.py:221 in create_io
      resolved_command = application.resolve_command(args)

   9  ~/.poetry/lib/poetry/_vendor/py3.8/clikit/console_application.py:110 in resolve_command
      return self._config.command_resolver.resolve(args, self)

   8  ~/.poetry/lib/poetry/_vendor/py3.8/clikit/resolver/default_resolver.py:34 in resolve
      return self.create_resolved_command(result)

   7  ~/.poetry/lib/poetry/_vendor/py3.8/clikit/resolver/default_resolver.py:166 in create_resolved_command
      if not result.is_parsable():

   6  ~/.poetry/lib/poetry/_vendor/py3.8/clikit/resolver/resolve_result.py:43 in is_parsable
      self._parse()

   5  ~/.poetry/lib/poetry/_vendor/py3.8/clikit/resolver/resolve_result.py:49 in _parse
      self._parsed_args = self._command.parse(self._raw_args)

   4  ~/.poetry/lib/poetry/_vendor/py3.8/clikit/api/command/command.py:113 in parse
      return self._config.args_parser.parse(args, self._args_format, lenient)

   3  ~/.poetry/lib/poetry/_vendor/py3.8/clikit/args/default_args_parser.py:53 in parse
      self._parse(args, _fmt, lenient)

   2  ~/.poetry/lib/poetry/_vendor/py3.8/clikit/args/default_args_parser.py:103 in _parse
      self._parse_short_option(token, tokens, fmt, lenient)

   1  ~/.poetry/lib/poetry/_vendor/py3.8/clikit/args/default_args_parser.py:258 in _parse_short_option
      self._parse_short_option_set(name, tokens, fmt, lenient)

  NoSuchOptionException

  The "-x" option does not exist.

  at ~/.poetry/lib/poetry/_vendor/py3.8/clikit/args/default_args_parser.py:280 in _parse_short_option_set
      276│     ):  # type: (str, List[str], ArgsFormat, bool) -> None
      277│         l = len(name)
      278│         for i in range(0, l):
      279│             if not fmt.has_option(name[i]):
    → 280│                 raise NoSuchOptionException(name[i])
      281│ 
      282│             option = fmt.get_option(name[i])
      283│             if option.accepts_value():
      284│                 self._add_long_option(

Is there a way to workaround this issue?

@bneijt
Copy link

bneijt commented May 27, 2021

You could add the password to the configuration file yourself. If you do not have a functioning keyring backend (often the case with CI) an auth.toml file will be created with the password in plaintext. Creating that file using a shell script should be quite trivial.

@DrLuke
Copy link
Contributor

DrLuke commented Sep 23, 2021

This works:
poetry config -- http-basic.foo username -some_password

The -- part makes the argument parser stop parsing anything starting with dashes as options. This also means that you need to put all your options before the double dashes.

@bneijt
Copy link

bneijt commented Sep 23, 2021

If what @DrLuke says is true, then this bug can be closed as it must have been fixed in a newer release (mind you, the bug is already a year old).

I do not have the rights to close it, but @abn is probably allowed to close this issue till further notice then.

@DrLuke
Copy link
Contributor

DrLuke commented Sep 23, 2021

I'm not sure if this really was a bug in the first place, but rather unfortunate CLI design instead. When configuring basic auth credentials, only the username is required, and the password is optional. So the parser is given the choice if you're providing another optional argument or if you're inputting options, and I'd go for parsing it as options as well.

Maybe it makes sense to document this here?

DrLuke added a commit to DrLuke/poetry that referenced this issue Sep 23, 2021
Document a solution for using passwords that start with a dash. This happened to a few people when using automatically generated tokens in a CI environment.
See: python-poetry#2889
@jeremad
Copy link
Author

jeremad commented Sep 28, 2021

I'm not sure if this really was a bug in the first place, but rather unfortunate CLI design instead. When configuring basic auth credentials, only the username is required, and the password is optional. So the parser is given the choice if you're providing another optional argument or if you're inputting options, and I'd go for parsing it as options as well.

Maybe it makes sense to document this here?

totally works for me

neersighted added a commit that referenced this issue Nov 14, 2021
…4552)

Document a solution for using passwords that start with a dash. This happened to a few people when using automatically generated tokens in a CI environment.

Fixes #2889

Co-authored-by: Bjorn Neergaard <bjorn@neersighted.com>
1nF0rmed pushed a commit to 1nF0rmed/poetry that referenced this issue Nov 15, 2021
…ython-poetry#4552)

Document a solution for using passwords that start with a dash. This happened to a few people when using automatically generated tokens in a CI environment.

Fixes python-poetry#2889

Co-authored-by: Bjorn Neergaard <bjorn@neersighted.com>
edvardm pushed a commit to edvardm/poetry that referenced this issue Nov 24, 2021
…ython-poetry#4552)

Document a solution for using passwords that start with a dash. This happened to a few people when using automatically generated tokens in a CI environment.

Fixes python-poetry#2889

Co-authored-by: Bjorn Neergaard <bjorn@neersighted.com>
@abn abn removed the status/triage This issue needs to be triaged label Mar 3, 2022
Copy link

github-actions bot commented Mar 2, 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 2, 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.

5 participants