implement token and status print

This commit is contained in:
Vitor Vezani
2023-05-15 18:29:43 -03:00
parent bf889a280b
commit 5c1c68a74a
3 changed files with 43 additions and 7 deletions

View File

@@ -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

24
pkg/auth/status.go Normal file
View File

@@ -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
}

View File

@@ -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
}