From db8c9ec1633e5788aa0f913e36c70b465e2d45be Mon Sep 17 00:00:00 2001 From: "M. Mert Yildiran" Date: Fri, 10 Mar 2023 18:41:38 +0300 Subject: [PATCH] :sparkles: Ask for license key input --- cmd/pro.go | 45 ++++++++++++++++++++++++++++++--------------- config/config.go | 2 +- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/cmd/pro.go b/cmd/pro.go index e39951562..711ae864e 100644 --- a/cmd/pro.go +++ b/cmd/pro.go @@ -27,7 +27,7 @@ var proCmd = &cobra.Command{ } const ( - PRO_URL = "https://master.d2hqi2yb1n0lz7.amplifyapp.com/" + PRO_URL = "https://console.kubeshark.co" PRO_PORT = 5252 ) @@ -64,6 +64,20 @@ func acquireLicense() { runLicenseRecieverServer() } +func updateLicense(licenseKey string) { + config.Config.License = licenseKey + err := config.WriteConfig(&config.Config) + if err != nil { + panic(err) + } + + connector.PostLicense(config.Config.License) + + log.Info().Msg("Updated the license. Exiting.") + + os.Exit(0) +} + func runLicenseRecieverServer() { gin.SetMode(gin.ReleaseMode) ginApp := gin.New() @@ -92,20 +106,21 @@ func runLicenseRecieverServer() { log.Info().Str("key", licenseKey).Msg("Received license:") - config.Config.License = licenseKey - err = config.WriteConfig(&config.Config) - if err != nil { - panic(err) - } - - connector.PostLicense(config.Config.License) - - log.Info().Msg("Updated the license.") - - os.Exit(0) + updateLicense(licenseKey) }) - if err := ginApp.Run(fmt.Sprintf(":%d", PRO_PORT)); err != nil { - panic(err) - } + go func() { + if err := ginApp.Run(fmt.Sprintf(":%d", PRO_PORT)); err != nil { + panic(err) + } + }() + + log.Info().Str("url", PRO_URL).Msg("Opened the login page in your browser:") + + log.Info().Msg("Alternatively enter your license key:") + + var licenseKey string + fmt.Scanf("%s", &licenseKey) + + updateLicense(licenseKey) } diff --git a/config/config.go b/config/config.go index 5bfca826f..4f10a5028 100644 --- a/config/config.go +++ b/config/config.go @@ -51,7 +51,7 @@ func InitConfig(cmd *cobra.Command) error { return nil } - if cmd.Use != "console" { + if cmd.Use != "console" && cmd.Use != "pro" { go version.CheckNewerVersion() }