github.com/vchain-us/vcn@v0.9.11-0.20210921212052-a2484d23c0b3/pkg/cmd/dashboard/dashboard.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 dashboard
    10  
    11  import (
    12  	"fmt"
    13  
    14  	"github.com/pkg/browser"
    15  	"github.com/vchain-us/vcn/pkg/meta"
    16  
    17  	"github.com/spf13/cobra"
    18  )
    19  
    20  // NewCommand returns the cobra command for `vcn dashboard`
    21  func NewCommand() *cobra.Command {
    22  	cmd := &cobra.Command{
    23  		Use:     "dashboard",
    24  		Aliases: []string{"d"},
    25  		Short:   "Open " + meta.DashboardURL() + " in browser",
    26  		Long:    ``,
    27  		Run:     runDashboard,
    28  		Args:    cobra.NoArgs,
    29  	}
    30  
    31  	return cmd
    32  }
    33  
    34  func runDashboard(cmd *cobra.Command, args []string) {
    35  	// We intentionally do not read the customer's token from disk
    36  	// and GET the dashboard => this would be insecure as tokens would
    37  	// be visible in server logs. In case the anyhow long-running web session
    38  	// has expired the customer will have to log in.
    39  	url := meta.DashboardURL()
    40  	if output, _ := cmd.Flags().GetString("output"); output == "" {
    41  		fmt.Println(fmt.Sprintf("Taking you to <%s>", url))
    42  	}
    43  	browser.OpenURL(url)
    44  }