Skip to content

Commit

Permalink
Update check: set empty API token (#766)
Browse files Browse the repository at this point in the history
* Enforce empty API token

* Show specific error message if GITHUB_TOKEN set
  • Loading branch information
marians committed Jul 13, 2022
1 parent a65f060 commit f98299f
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions pkg/selfupdate/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import (
)

type Config struct {
// GithubToken will be used when fetching versions
// from private GitHub repositories.
GithubToken string
// CurrentVersion is the currently installed version
// of the application.
CurrentVersion string
Expand All @@ -26,7 +23,6 @@ type Config struct {
}

type Updater struct {
githubToken string
currentVersion semver.Version
repository string
cacheDir string
Expand All @@ -46,8 +42,7 @@ func New(c Config) (*Updater, error) {
var err error

u := &Updater{
githubToken: c.GithubToken,
cacheDir: c.CacheDir,
cacheDir: c.CacheDir,
}

{
Expand All @@ -65,8 +60,10 @@ func New(c Config) (*Updater, error) {
}

{
// APIToken is empty here to suppress the use of the GITHUB_TOKEN
// environment variable or any .gitconfig token.
u.selfUpdater, err = selfupdate.NewUpdater(selfupdate.Config{
APIToken: u.githubToken,
APIToken: "",
})
if err != nil {
return nil, microerror.Mask(err)
Expand Down Expand Up @@ -133,6 +130,10 @@ func (u *Updater) getLatestVersion() (semver.Version, error) {
}

if latestVersion == nil {
token := os.Getenv("GITHUB_TOKEN")
if token != "" {
return semver.Version{}, microerror.Maskf(versionNotFoundError, "please check whether the GITHUB_TOKEN env variable is a token with access to %s", u.repository)
}
return semver.Version{}, microerror.Maskf(versionNotFoundError, "couldn't find the latest version and/or release assets on GitHub, probably due to token without access to the repository %s.", u.repository)
}

Expand Down

0 comments on commit f98299f

Please sign in to comment.