From 5c1c68a74ad449a3a71dcc4e4e42ef49ff3d95a0 Mon Sep 17 00:00:00 2001 From: Vitor Vezani Date: Mon, 15 May 2023 18:29:43 -0300 Subject: [PATCH] implement token and status print --- cmd/polaris/auth.go | 10 ++++------ pkg/auth/status.go | 24 ++++++++++++++++++++++++ pkg/auth/token.go | 16 +++++++++++++++- 3 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 pkg/auth/status.go diff --git a/cmd/polaris/auth.go b/cmd/polaris/auth.go index e4666baf..dc0008ee 100644 --- a/cmd/polaris/auth.go +++ b/cmd/polaris/auth.go @@ -55,12 +55,10 @@ var statusCmd = &cobra.Command{ Short: "View authentication status.", Long: `View authentication status.`, Run: func(cmd *cobra.Command, args []string) { - /* - ✓ Logged in to github.com as vitorvezani (keyring) - ✓ Git operations for github.com configured to use ssh protocol. - ✓ Token: ghp_************************************ - ✓ Token scopes: admin:public_key, read:org, repo - */ + err := auth.PrintStatus() + if err != nil { + logrus.Fatalf("printing status") + } }, PersistentPostRunE: func(cmd *cobra.Command, args []string) error { return nil diff --git a/pkg/auth/status.go b/pkg/auth/status.go new file mode 100644 index 00000000..11e60c89 --- /dev/null +++ b/pkg/auth/status.go @@ -0,0 +1,24 @@ +package auth + +import "fmt" + +func PrintStatus() error { + + if content, err := readPolarisHostsFile(); err == nil { + if len(content) > 0 { + for k, h := range content { + fmt.Println(k, h) + // TODO: Vitor - implement this + /* + ✓ Logged in to github.com as vitorvezani (keyring) + ✓ Git operations for github.com configured to use ssh protocol. + ✓ Token: ghp_************************************ + ✓ Token scopes: admin:public_key, read:org, repo + */ + } + return nil + } + } + fmt.Println("You are not logged into Fairwinds Insights. Run polaris auth login to authenticate.") + return nil +} diff --git a/pkg/auth/token.go b/pkg/auth/token.go index 423fa1e7..42d3d6cc 100644 --- a/pkg/auth/token.go +++ b/pkg/auth/token.go @@ -1,6 +1,20 @@ package auth +import "fmt" + func PrintToken() error { - // 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 + if content, err := readPolarisHostsFile(); err == nil { + if len(content) > 0 { + for k, h := range content { + if len(content) == 1 { + fmt.Println(h.Token) + } else { + fmt.Printf("%s: %s\n", k, h.Token) + } + } + return nil + } + } + fmt.Println("no oauth token") return nil }