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

"Anonymous credential has no username" on keyring get #694

Closed
koterpillar opened this issue Sep 17, 2024 · 2 comments · Fixed by #695
Closed

"Anonymous credential has no username" on keyring get #694

koterpillar opened this issue Sep 17, 2024 · 2 comments · Fixed by #695

Comments

@koterpillar
Copy link

koterpillar commented Sep 17, 2024

Describe the bug
Getting existing credentials using keyring get fails with an exception stacktrace showing "Anonymous credential has no username".

To Reproduce
Steps to reproduce the behavior:

$ keyring set aaaa bbbb
Password for 'bbbb' in 'aaaa': <enter password>
$ keyring get aaaa bbbb
Traceback (most recent call last):
  File "<snip>/keyring", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "<snip>/venvs/keyring/lib/python3.12/site-packages/keyring/cli.py", line 219, in main
    return cli.run(argv)
           ^^^^^^^^^^^^^
  File "<snip>/venvs/keyring/lib/python3.12/site-packages/keyring/cli.py", line 120, in run
    return method()
           ^^^^^^^^
  File "<snip>/venvs/keyring/lib/python3.12/site-packages/keyring/cli.py", line 132, in do_get
    getattr(self, f'_emit_{self.output_format}')(credential)
  File "<snip>/venvs/keyring/lib/python3.12/site-packages/keyring/cli.py", line 140, in _emit_plain
    if credential.username:
       ^^^^^^^^^^^^^^^^^^^
  File "<snip>/venvs/keyring/lib/python3.12/site-packages/keyring/credentials.py", line 39, in username
    raise ValueError("Anonymous credential has no username")
ValueError: Anonymous credential has no username

Expected behavior

keyring get should return the password set by keyring set.

Environment

  • OS: macOS 14.6.1 (23G93)
$ pipx list | grep keyring <note: pipx>
package keyring 25.4.0, installed using Python 3.12.4
$ keyring --list-backends
keyring.backends.macOS.Keyring (priority: 5)
keyring.backends.fail.Keyring (priority: 0)
keyring.backends.chainer.ChainerBackend (priority: -1)

Additional context

Works fine with 25.3.0, even with a password set by 25.4.0.

@valorl
Copy link

valorl commented Sep 18, 2024

Yep, it seems like the introduction of AnonymousCredentials, which throws on .username hasn't been handled properly in the CLI, as both _emit_json and _emit_plain will try to access it. (cc @zanieb)

@ffissore
Copy link
Contributor

#695 contains a fix. Not sure if this goes against the design decision of introducing AnonymousCredential, but I don't have enough context to come up with something better

jaraco added a commit to ffissore/keyring that referenced this issue Sep 20, 2024
Captures missed expectation reported in jaraco#694
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants