2019-11-10 17:50:56 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-02-05 00:05:34 +03:00
|
|
|
"sort"
|
|
|
|
"strings"
|
2019-11-10 17:50:56 +03:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2019-12-08 23:15:06 +03:00
|
|
|
"github.com/MichaelMure/git-bug/bridge/core/auth"
|
2019-11-10 17:50:56 +03:00
|
|
|
)
|
|
|
|
|
2020-06-28 19:26:29 +03:00
|
|
|
func newBridgeAuthShow() *cobra.Command {
|
|
|
|
env := newEnv()
|
|
|
|
|
|
|
|
cmd := &cobra.Command{
|
2021-05-09 12:33:20 +03:00
|
|
|
Use: "show",
|
|
|
|
Short: "Display an authentication credential.",
|
|
|
|
PreRunE: loadBackend(env),
|
|
|
|
RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error {
|
2020-06-28 19:26:29 +03:00
|
|
|
return runBridgeAuthShow(env, args)
|
2021-05-09 12:33:20 +03:00
|
|
|
}),
|
2021-01-24 16:05:40 +03:00
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
ValidArgsFunction: completeBridgeAuth(env),
|
2020-06-28 19:26:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func runBridgeAuthShow(env *Env, args []string) error {
|
|
|
|
cred, err := auth.LoadWithPrefix(env.repo, args[0])
|
2019-11-10 17:50:56 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-28 19:26:29 +03:00
|
|
|
env.out.Printf("Id: %s\n", cred.ID())
|
|
|
|
env.out.Printf("Target: %s\n", cred.Target())
|
|
|
|
env.out.Printf("Kind: %s\n", cred.Kind())
|
|
|
|
env.out.Printf("Creation: %s\n", cred.CreateTime().Format(time.RFC822))
|
2019-12-08 23:15:06 +03:00
|
|
|
|
|
|
|
switch cred := cred.(type) {
|
|
|
|
case *auth.Token:
|
2020-06-28 19:26:29 +03:00
|
|
|
env.out.Printf("Value: %s\n", cred.Value)
|
2019-12-08 23:15:06 +03:00
|
|
|
}
|
2019-11-10 17:50:56 +03:00
|
|
|
|
2020-06-28 19:26:29 +03:00
|
|
|
env.out.Println("Metadata:")
|
2020-02-05 00:05:34 +03:00
|
|
|
|
|
|
|
meta := make([]string, 0, len(cred.Metadata()))
|
|
|
|
for key, value := range cred.Metadata() {
|
|
|
|
meta = append(meta, fmt.Sprintf(" %s --> %s\n", key, value))
|
|
|
|
}
|
|
|
|
sort.Strings(meta)
|
|
|
|
|
2020-06-28 19:26:29 +03:00
|
|
|
env.out.Print(strings.Join(meta, ""))
|
2020-02-05 00:05:34 +03:00
|
|
|
|
2019-11-10 17:50:56 +03:00
|
|
|
return nil
|
|
|
|
}
|