Skip to content

Commit 9436857

Browse files
authored
chore: disallow self-install/upgrade (#61)
1 parent 16325c5 commit 9436857

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

constants/constants.go

+6
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,9 @@ var RegexGithubSearch = `(?i)^[A-Za-z0-9\_\.\-\/\:]+$`
4545

4646
// RegexURL is a regular express for valid URLs
4747
var RegexURL = `(http|ftp|https):\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])`
48+
49+
// StewOwner is the username of the stew github repo owner
50+
var StewOwner = `marwanhawari`
51+
52+
// StewRepo is the name of the stew github repo
53+
var StewRepo = `stew`

lib/errors.go

+9
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,19 @@ func (e InvalidGithubSearchQueryError) Error() string {
163163
return fmt.Sprintf("%v The search query %v contains invalid characters", constants.RedColor("Error:"), constants.RedColor(e.SearchQuery))
164164
}
165165

166+
// BinaryMismatchError occurs if the downloaded binary hash doesn't match the hash in the lockfile
166167
type BinaryMismatchError struct {
167168
BinaryName string
168169
}
169170

170171
func (e BinaryMismatchError) Error() string {
171172
return fmt.Sprintf("%v The hash for the downloaded binary %v does not match the hash in the lockfile", constants.RedColor("Error:"), constants.RedColor(e.BinaryName))
172173
}
174+
175+
// SelfInstallError occurs when attempting to install or upgrade stew using stew
176+
type SelfInstallError struct {
177+
}
178+
179+
func (e SelfInstallError) Error() string {
180+
return fmt.Sprintf("%v Stew cannot self-install/self-upgrade. You should upgrade stew with the original install method, whether it was manually or through a package manager", constants.RedColor("Error:"))
181+
}

lib/github.go

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ func getGithubJSON(owner, repo string) (string, error) {
5656

5757
// NewGithubProject creates a new instance of the GithubProject struct
5858
func NewGithubProject(owner, repo string) (GithubProject, error) {
59+
if owner == constants.StewOwner && repo == constants.StewRepo {
60+
return GithubProject{}, SelfInstallError{}
61+
}
62+
5963
ghJSON, err := getGithubJSON(owner, repo)
6064
if err != nil {
6165
return GithubProject{}, err

0 commit comments

Comments
 (0)