mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 04:14:38 +00:00
Revert "keyring swap, better error messages/warnings, delay upgrade notif"
This reverts commit 7f69a3b23f.
This commit is contained in:
@@ -11,7 +11,6 @@ import (
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/rs/zerolog/log"
|
||||
@@ -21,16 +20,13 @@ func CheckForUpdate() {
|
||||
if checkEnv := os.Getenv("INFISICAL_DISABLE_UPDATE_CHECK"); checkEnv != "" {
|
||||
return
|
||||
}
|
||||
latestVersion, publishedDate, err := getLatestTag("Infisical", "infisical")
|
||||
latestVersion, err := getLatestTag("Infisical", "infisical")
|
||||
if err != nil {
|
||||
log.Debug().Err(err)
|
||||
// do nothing and continue
|
||||
return
|
||||
}
|
||||
|
||||
daysSinceRelease, _ := daysSinceDate(publishedDate)
|
||||
|
||||
if latestVersion != CLI_VERSION && daysSinceRelease > 5 {
|
||||
if latestVersion != CLI_VERSION {
|
||||
yellow := color.New(color.FgYellow).SprintFunc()
|
||||
blue := color.New(color.FgCyan).SprintFunc()
|
||||
black := color.New(color.FgBlack).SprintFunc()
|
||||
@@ -47,45 +43,44 @@ func CheckForUpdate() {
|
||||
updateInstructions := GetUpdateInstructions()
|
||||
|
||||
if updateInstructions != "" {
|
||||
msg = fmt.Sprintf("%s\n", GetUpdateInstructions())
|
||||
msg = fmt.Sprintf("\n%s\n", GetUpdateInstructions())
|
||||
fmt.Fprintln(os.Stderr, msg)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func getLatestTag(repoOwner string, repoName string) (string, string, error) {
|
||||
func getLatestTag(repoOwner string, repoName string) (string, error) {
|
||||
url := fmt.Sprintf("https://api.github.com/repos/%s/%s/releases/latest", repoOwner, repoName)
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
return "", err
|
||||
}
|
||||
if resp.StatusCode != 200 {
|
||||
return "", "", errors.New(fmt.Sprintf("gitHub API returned status code %d", resp.StatusCode))
|
||||
return "", errors.New(fmt.Sprintf("gitHub API returned status code %d", resp.StatusCode))
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
return "", err
|
||||
}
|
||||
|
||||
var releaseDetails struct {
|
||||
TagName string `json:"tag_name"`
|
||||
PublishedAt string `json:"published_at"`
|
||||
var releaseTag struct {
|
||||
TagName string `json:"tag_name"`
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(body, &releaseDetails); err != nil {
|
||||
return "", "", fmt.Errorf("failed to unmarshal github response: %w", err)
|
||||
if err := json.Unmarshal(body, &releaseTag); err != nil {
|
||||
return "", fmt.Errorf("failed to unmarshal github response: %w", err)
|
||||
}
|
||||
|
||||
tag_prefix := "infisical-cli/v"
|
||||
|
||||
// Extract the version from the first valid tag
|
||||
version := strings.TrimPrefix(releaseDetails.TagName, tag_prefix)
|
||||
version := strings.TrimPrefix(releaseTag.TagName, tag_prefix)
|
||||
|
||||
return version, releaseDetails.PublishedAt, nil
|
||||
return version, nil
|
||||
}
|
||||
|
||||
func GetUpdateInstructions() string {
|
||||
@@ -150,16 +145,3 @@ func IsRunningInDocker() bool {
|
||||
|
||||
return strings.Contains(string(cgroup), "docker")
|
||||
}
|
||||
|
||||
func daysSinceDate(dateString string) (int, error) {
|
||||
layout := "2006-01-02T15:04:05Z"
|
||||
parsedDate, err := time.Parse(layout, dateString)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
currentTime := time.Now()
|
||||
difference := currentTime.Sub(parsedDate)
|
||||
days := int(difference.Hours() / 24)
|
||||
return days, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user