@@ -2,7 +2,9 @@ package cmd
22
33import (
44 "fmt"
5+ "strings"
56
7+ "github.com/loops-so/cli/internal/api"
68 "github.com/loops-so/cli/internal/config"
79 "github.com/spf13/cobra"
810)
@@ -11,23 +13,45 @@ var statusCmd = &cobra.Command{
1113 Use : "status" ,
1214 Short : "Print the resolved configuration" ,
1315 RunE : func (cmd * cobra.Command , args []string ) error {
14- cfg , err := runAuthStatus ()
16+ cfg , keyResp , err := runAuthStatus ()
1517 if err != nil {
1618 return err
1719 }
1820
21+ masked := maskKey (cfg .APIKey )
22+
1923 if isJSONOutput () {
20- return printJSON (cmd .OutOrStdout (), cfg )
24+ return printJSON (cmd .OutOrStdout (), struct {
25+ APIKey string `json:"apiKey"`
26+ EndpointURL string `json:"endpointUrl"`
27+ TeamName string `json:"teamName"`
28+ }{masked , cfg .EndpointURL , keyResp .TeamName })
2129 }
2230
23- fmt .Fprintf (cmd .OutOrStdout (), "API Key: %s\n " , cfg . APIKey )
31+ fmt .Fprintf (cmd .OutOrStdout (), "API Key: %s\n " , masked )
2432 fmt .Fprintf (cmd .OutOrStdout (), "Endpoint: %s\n " , cfg .EndpointURL )
33+ fmt .Fprintf (cmd .OutOrStdout (), "Team: %s\n " , keyResp .TeamName )
2534 return nil
2635 },
2736}
2837
29- func runAuthStatus () (* config.Config , error ) {
30- return config .Load ()
38+ func runAuthStatus () (* config.Config , * api.APIKeyResponse , error ) {
39+ cfg , err := config .Load ()
40+ if err != nil {
41+ return nil , nil , err
42+ }
43+ keyResp , err := api .NewClient (cfg .EndpointURL , cfg .APIKey ).GetAPIKey ()
44+ if err != nil {
45+ return nil , nil , fmt .Errorf ("API key verification failed: %w" , err )
46+ }
47+ return cfg , keyResp , nil
48+ }
49+
50+ func maskKey (key string ) string {
51+ if len (key ) <= 4 {
52+ return "****"
53+ }
54+ return fmt .Sprintf ("%s%s" , strings .Repeat ("*" , len (key )- 4 ), key [len (key )- 4 :])
3155}
3256
3357func init () {
0 commit comments