mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 18:27:36 +00:00
add cli version check before every command
This commit is contained in:
@@ -17,7 +17,7 @@ var rootCmd = &cobra.Command{
|
|||||||
Short: "Infisical CLI is used to inject environment variables into any process",
|
Short: "Infisical CLI is used to inject environment variables into any process",
|
||||||
Long: `Infisical is a simple, end-to-end encrypted service that enables teams to sync and manage their environment variables across their development life cycle.`,
|
Long: `Infisical is a simple, end-to-end encrypted service that enables teams to sync and manage their environment variables across their development life cycle.`,
|
||||||
CompletionOptions: cobra.CompletionOptions{HiddenDefaultCmd: true},
|
CompletionOptions: cobra.CompletionOptions{HiddenDefaultCmd: true},
|
||||||
Version: "0.2.5",
|
Version: util.CLI_VERSION,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||||
@@ -33,8 +33,9 @@ func init() {
|
|||||||
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&debugLogging, "debug", "d", false, "Enable verbose logging")
|
rootCmd.PersistentFlags().BoolVarP(&debugLogging, "debug", "d", false, "Enable verbose logging")
|
||||||
rootCmd.PersistentFlags().StringVar(&config.INFISICAL_URL, "domain", util.INFISICAL_DEFAULT_API_URL, "Point the CLI to your own backend [can also set via environment variable name: INFISICAL_API_URL]")
|
rootCmd.PersistentFlags().StringVar(&config.INFISICAL_URL, "domain", util.INFISICAL_DEFAULT_API_URL, "Point the CLI to your own backend [can also set via environment variable name: INFISICAL_API_URL]")
|
||||||
// rootCmd.PersistentPreRun = func(cmd *cobra.Command, args []string) {
|
rootCmd.PersistentPreRun = func(cmd *cobra.Command, args []string) {
|
||||||
// }
|
util.CheckForUpdate()
|
||||||
|
}
|
||||||
|
|
||||||
// if config.INFISICAL_URL is set to the default value, check if INFISICAL_URL is set in the environment
|
// if config.INFISICAL_URL is set to the default value, check if INFISICAL_URL is set in the environment
|
||||||
// this is used to allow overrides of the default value
|
// this is used to allow overrides of the default value
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CheckForUpdate() {
|
||||||
|
latestVersion, err := getLatestTag("infisical", "infisical")
|
||||||
|
if err != nil {
|
||||||
|
// do nothing and continue
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if latestVersion != CLI_VERSION {
|
||||||
|
PrintWarning(fmt.Sprintf("Please update your CLI. You are running version %s but the latest version is %s", CLI_VERSION, latestVersion))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getLatestTag(repoOwner string, repoName string) (string, error) {
|
||||||
|
url := fmt.Sprintf("https://api.github.com/repos/%s/%s/tags", repoOwner, repoName)
|
||||||
|
resp, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
var tags []struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
json.Unmarshal(body, &tags)
|
||||||
|
|
||||||
|
return tags[0].Name, nil
|
||||||
|
}
|
||||||
@@ -11,4 +11,5 @@ const (
|
|||||||
KEYRING_SERVICE_NAME = "infisical"
|
KEYRING_SERVICE_NAME = "infisical"
|
||||||
PERSONAL_SECRET_TYPE_NAME = "personal"
|
PERSONAL_SECRET_TYPE_NAME = "personal"
|
||||||
SHARED_SECRET_TYPE_NAME = "shared"
|
SHARED_SECRET_TYPE_NAME = "shared"
|
||||||
|
CLI_VERSION = "v0.2.5"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user