jaraco / keyring

MIT License
1.24k stars 152 forks source link

feature: Add `get` options to cli for interface with `get_credential` and support JSON output #678

Closed BakerNet closed 4 months ago

BakerNet commented 4 months ago

Internally, keyring supports get_credential, which is useful for backends which can supply their own username. This adds an exposed get_credential in the cli - keyring --mode creds get [service] [OPTIONAL - username]

This also adds support for JSON output type via --output json option

Help text for reference:

  --output {plain,json}
                        Output format for 'get' operation. Default is 'plain'
  --mode {password,creds}
                        Mode for 'get' operation. 'password' requires a username and will return only the password.
                        'creds' does not require a username and will return both the username and password separated by
                        a newline. Default is 'password'

Example output:

 ➜  keyring --mode creds get https://example.com/
hello
world
 ➜  keyring --mode creds --output json get https://example.com/
{"username": "hello", "password": "world"}
 ➜  keyring --output json get https://example.com/ hello
{"password": "world"}
jaraco commented 4 months ago

Releasing as v25.2.0.