Skip to content

Commit

Permalink
config get: support getting oauth_token from keyring
Browse files Browse the repository at this point in the history
Since we've advertised `gh config get -h HOST oauth_token` as an API for outside scripts and extensions to access the token, this should continue working even if the token was technically stored in keyring and not in the config file.
  • Loading branch information
mislav committed Mar 9, 2023
1 parent b2b0a16 commit db68dfa
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/cmd/config/get/get.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package get

import (
"errors"
"fmt"

"github.com/MakeNowJust/heredoc"
Expand Down Expand Up @@ -53,6 +54,16 @@ func NewCmdConfigGet(f *cmdutil.Factory, runF func(*GetOptions) error) *cobra.Co
}

func getRun(opts *GetOptions) error {
// search keyring storage when fetching the `oauth_token` value
if opts.Hostname != "" && opts.Key == "oauth_token" {
token, _ := opts.Config.Authentication().Token(opts.Hostname)
if token == "" {
return errors.New(`could not find key "oauth_token"`)
}
fmt.Fprintf(opts.IO.Out, "%s\n", token)
return nil
}

val, err := opts.Config.GetOrDefault(opts.Hostname, opts.Key)
if err != nil {
return err
Expand Down

0 comments on commit db68dfa

Please sign in to comment.