github.com/vchain-us/vcn@v0.9.11-0.20210921212052-a2484d23c0b3/pkg/cmd/info/info.go (about) 1 /* 2 * Copyright (c) 2018-2020 vChain, Inc. All Rights Reserved. 3 * This software is released under GPL3. 4 * The full license information can be found under: 5 * https://www.gnu.org/licenses/gpl-3.0.en.html 6 * 7 */ 8 9 package info 10 11 import ( 12 "fmt" 13 "github.com/vchain-us/vcn/internal/logs" 14 "github.com/vchain-us/vcn/pkg/api" 15 "github.com/vchain-us/vcn/pkg/meta" 16 "github.com/vchain-us/vcn/pkg/store" 17 "os" 18 19 "github.com/spf13/cobra" 20 ) 21 22 // NewCommand returns the cobra command for `vcn info` 23 func NewCommand() *cobra.Command { 24 cmd := &cobra.Command{ 25 Use: "info", 26 Short: "Display vcn information", 27 Long: ``, 28 RunE: runInfo, 29 Args: cobra.NoArgs, 30 } 31 32 return cmd 33 } 34 35 func runInfo(cmd *cobra.Command, args []string) error { 36 cmd.SilenceUsage = true 37 38 context := store.Config().CurrentContext 39 40 fmt.Printf(` 41 Version: %s 42 Git Rev: %s 43 UserAgent: %s 44 Config file: %s 45 Log level: %s 46 `, 47 meta.Version(), 48 meta.GitRevision(), 49 meta.UserAgent(), 50 store.ConfigFile(), 51 logs.LOG.GetLevel().String(), 52 ) 53 54 if context.LcHost != "" { 55 fmt.Printf(` 56 Host: %s 57 Port: %s 58 No-tls: %t 59 Skip-verify-tls: %t 60 Certificate: %s 61 Current signerID(if api key env is set): %s 62 `, 63 context.LcHost, 64 context.LcPort, 65 context.LcNoTls, 66 context.LcSkipTlsVerify, 67 context.LcCert, 68 api.GetSignerIDByApiKey(os.Getenv(meta.VcnLcApiKey)), 69 ) 70 71 } 72 73 if context.Email != "" { 74 fmt.Printf(` 75 Stage: %s 76 Log level: %s 77 API endpoint: %s 78 MainNet: %s 79 Contract Addr.: %s 80 `, 81 meta.StageEnvironment().String(), 82 logs.LOG.GetLevel().String(), 83 meta.APIEndpoint(""), 84 meta.MainNet(), 85 meta.AssetsRelayContractAddress(), 86 ) 87 u := api.NewUser(context.Email) 88 fmt.Printf("\nCodeNotary.io user: %s\n", u.Email()) 89 hasAuth, err := u.IsAuthenticated() 90 if err != nil { 91 return err 92 } 93 if !hasAuth { 94 fmt.Println("\nNo CodeNotary.io user authenticated (token expired).") 95 return nil 96 } 97 id, err := u.SignerID() 98 if err != nil { 99 return err 100 } 101 fmt.Printf("SignerID: %s\n", id) 102 } 103 return nil 104 }