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

better catch unauthorized errors with forced password prompt #424

Merged
merged 1 commit into from
Jan 31, 2024

Conversation

proddata
Copy link
Member

@proddata proddata commented Jan 30, 2024

About

Better catch unauthorized errors with forced password prompt instead of displaying stack trace, when using the -W option.

 % crash --hosts 'https://elite-krait.eks1.eu-west-1.aws.cratedb.net:4200' -U 'admin' -W
Password: 
401 Client Error: Unauthorized

Before, it was like:

Password:
Traceback (most recent call last):
  File "/path/to/.venv/bin/crash", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/path/to/.venv/lib/python3.11/site-packages/crate/crash/command.py", line 589, in main
    raise e
  File "/path/to/.venv/lib/python3.11/site-packages/crate/crash/command.py", line 575, in main
    cmd = _create_shell(crate_hosts, error_trace, output_writer, is_tty,
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/.venv/lib/python3.11/site-packages/crate/crash/command.py", line 622, in _create_shell
    return CrateShell(crate_hosts,
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/.venv/lib/python3.11/site-packages/crate/crash/command.py", line 228, in __init__
    self._connect(crate_hosts)
  File "/path/to/.venv/lib/python3.11/site-packages/crate/crash/command.py", line 323, in _connect
    self.connection = connect(servers,
                      ^^^^^^^^^^^^^^^^
  File "/path/to/.venv/lib/python3.11/site-packages/crate/client/connection.py", line 152, in __init__
    self.lowest_server_version = self._lowest_server_version()
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/.venv/lib/python3.11/site-packages/crate/client/connection.py", line 196, in _lowest_server_version
    _, _, version = self.client.server_infos(server)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/.venv/lib/python3.11/site-packages/crate/client/http.py", line 461, in server_infos
    _raise_for_status(response)
  File "/path/to/.venv/lib/python3.11/site-packages/crate/client/http.py", line 199, in _raise_for_status
    return _raise_for_status_real(response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/.venv/lib/python3.11/site-packages/crate/client/http.py", line 231, in _raise_for_status_real
    raise ProgrammingError(message)
crate.client.exceptions.ProgrammingError: 401 Client Error: Unauthorized

References

@proddata proddata requested review from amotl and surister January 30, 2024 14:31
@proddata proddata force-pushed the proddata/unauthorized branch from 924f224 to d4ec734 Compare January 30, 2024 14:39
if '401' in msg and not args.force_passwd_prompt:
if is_tty:
password = getpass()
if '401' in msg and not args.force_passwd_prompt and is_tty:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why we would retry creating a shell with the same parameters so I would move the tty check upwards

@amotl
Copy link
Member

amotl commented Jan 30, 2024

Thanks for the patch.

I agree to unify the behavior between -W and <n/a> when prompting for passwords, unless there are other objections. There may have been specific reasons for the current behaviour to discriminate between tty vs. non-interactive environments, but personally I can't see any, as long as is_tty is respected properly.

To check/ask back for that, I am also adding @seut and @mfussenegger as reviewers.

@amotl amotl requested review from mfussenegger and seut January 30, 2024 16:41
@proddata proddata added ready-to-merge Let Mergify merge the PR once approved and checks pass and removed ready-to-merge Let Mergify merge the PR once approved and checks pass labels Jan 31, 2024
@proddata proddata merged commit 6c7359f into master Jan 31, 2024
21 checks passed
@proddata proddata deleted the proddata/unauthorized branch January 31, 2024 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants