diff options
author | Michael Muré <batolettre@gmail.com> | 2019-12-08 21:15:06 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2019-12-08 21:28:27 +0100 |
commit | b92adfcb5f79f2b32c3dafb0fc3e7f1b753b6197 (patch) | |
tree | 69202c4021b10f3ab7b7f5ebf229d501e95c4786 /commands/bridge_auth.go | |
parent | 981a4a848b1329da1a73270e27633911f9298bb1 (diff) | |
download | git-bug-b92adfcb5f79f2b32c3dafb0fc3e7f1b753b6197.tar.gz |
bridge: huge refactor to accept multiple kind of credentials
Diffstat (limited to 'commands/bridge_auth.go')
-rw-r--r-- | commands/bridge_auth.go | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/commands/bridge_auth.go b/commands/bridge_auth.go index e7fce1bd..4e8b50c4 100644 --- a/commands/bridge_auth.go +++ b/commands/bridge_auth.go @@ -7,36 +7,56 @@ import ( text "github.com/MichaelMure/go-term-text" - "github.com/MichaelMure/git-bug/bridge/core" + "github.com/MichaelMure/git-bug/bridge/core/auth" + "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/util/colors" + "github.com/MichaelMure/git-bug/util/interrupt" ) func runBridgeAuth(cmd *cobra.Command, args []string) error { - tokens, err := core.ListTokens(repo) + backend, err := cache.NewRepoCache(repo) if err != nil { return err } + defer backend.Close() + interrupt.RegisterCleaner(backend.Close) - for _, token := range tokens { - token, err := core.LoadToken(repo, token) + creds, err := auth.List(backend) + if err != nil { + return err + } + + defaultUser, _ := backend.GetUserIdentity() + + for _, cred := range creds { + targetFmt := text.LeftPadMaxLine(cred.Target(), 10, 0) + + var value string + switch cred := cred.(type) { + case *auth.Token: + value = cred.Value + } + + user, err := backend.ResolveIdentity(cred.UserId()) if err != nil { return err } - printToken(token) - } + userFmt := user.DisplayName() - return nil -} + if cred.UserId() == defaultUser.Id() { + userFmt = colors.Red(userFmt) + } -func printToken(token *core.Token) { - targetFmt := text.LeftPadMaxLine(token.Target, 10, 0) + fmt.Printf("%s %s %s %s %s\n", + colors.Cyan(cred.ID().Human()), + colors.Yellow(targetFmt), + colors.Magenta(cred.Kind()), + userFmt, + value, + ) + } - fmt.Printf("%s %s %s %s\n", - colors.Cyan(token.ID().Human()), - colors.Yellow(targetFmt), - colors.Magenta("token"), - token.Value, - ) + return nil } var bridgeAuthCmd = &cobra.Command{ |