From 6e37e11c0daf8886e4699be233e00952b3288b65 Mon Sep 17 00:00:00 2001 From: Oleg Sucharevich Date: Wed, 13 Feb 2019 18:05:43 +0200 Subject: [PATCH] fix bug when running version cmd --- package.json | 2 +- venonactl/cmd/root.go | 61 +++++++++++++++++++++++-------------------- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/package.json b/package.json index 6ce36ce8..520c7757 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "venona", - "version": "0.15.0", + "version": "0.15.1", "description": "Codefresh agent to run on Codefresh's runtime environment and execute pipeline", "main": "index.js", "scripts": { diff --git a/venonactl/cmd/root.go b/venonactl/cmd/root.go index 2282f7b2..5c64090f 100644 --- a/venonactl/cmd/root.go +++ b/venonactl/cmd/root.go @@ -62,36 +62,11 @@ var rootCmd = &cobra.Command{ PersistentPreRunE: func(cmd *cobra.Command, args []string) error { fullPath := cmd.CommandPath() + isVersionTarget := strings.Index(fullPath, "version") != -1 if verbose == true { logrus.SetLevel(logrus.DebugLevel) } - if configPath == "" { - configPath = fmt.Sprintf("%s/.cfconfig", os.Getenv("HOME")) - } - - if cfAPIHost == "" && cfAPIToken == "" { - context, err := sdkUtils.ReadAuthContext(configPath, cfContext) - if err != nil { - return err - } - cfAPIHost = context.URL - cfAPIToken = context.Token - - logrus.WithFields(logrus.Fields{ - "Context-Name": context.Name, - "Codefresh-Host": cfAPIHost, - }).Debug("Using codefresh context") - } else { - logrus.Debug("Using creentials from environment variables") - } - client := codefresh.New(&codefresh.ClientOptions{ - Auth: codefresh.AuthOptions{ - Token: cfAPIToken, - }, - Host: cfAPIHost, - }) - s := store.GetStore() s.Version = &store.Version{ Current: &store.CurrentVersion{ @@ -104,6 +79,7 @@ var rootCmd = &cobra.Command{ s.Image = &store.Image{ Name: "codefresh/venona", } + if skipVerionCheck || localDevFlow == "true" { latestVersion := &store.LatestVersion{ Version: store.DefaultVersion, @@ -124,7 +100,7 @@ var rootCmd = &cobra.Command{ res, _ := store.IsRunningLatestVersion() // the local version and the latest version not match // make sure the command is no venonactl version - if !res && strings.Index(fullPath, "version") == -1 { + if !res && !isVersionTarget { logrus.WithFields(logrus.Fields{ "Local-Version": s.Version.Current.Version, "Latest-Version": s.Version.Latest.Version, @@ -132,6 +108,36 @@ var rootCmd = &cobra.Command{ } } + if isVersionTarget { + return nil + } + + if configPath == "" { + configPath = fmt.Sprintf("%s/.cfconfig", os.Getenv("HOME")) + } + + if cfAPIHost == "" && cfAPIToken == "" { + context, err := sdkUtils.ReadAuthContext(configPath, cfContext) + if err != nil { + return err + } + cfAPIHost = context.URL + cfAPIToken = context.Token + + logrus.WithFields(logrus.Fields{ + "Context-Name": context.Name, + "Codefresh-Host": cfAPIHost, + }).Debug("Using codefresh context") + } else { + logrus.Debug("Using creentials from environment variables") + } + client := codefresh.New(&codefresh.ClientOptions{ + Auth: codefresh.AuthOptions{ + Token: cfAPIToken, + }, + Host: cfAPIHost, + }) + if kubeConfigPath == "" { currentUser, _ := user.Current() if currentUser != nil { @@ -153,7 +159,6 @@ var rootCmd = &cobra.Command{ Client: client, } s.Mode = store.ModeInCluster - s.ServerCert = &certs.ServerCert{} return nil