Skip to content

Commit

Permalink
chore: disallow self-install/upgrade (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
marwanhawari authored Jan 19, 2025
1 parent 16325c5 commit 9436857
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,9 @@ var RegexGithubSearch = `(?i)^[A-Za-z0-9\_\.\-\/\:]+$`

// RegexURL is a regular express for valid URLs
var RegexURL = `(http|ftp|https):\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])`

// StewOwner is the username of the stew github repo owner
var StewOwner = `marwanhawari`

// StewRepo is the name of the stew github repo
var StewRepo = `stew`
9 changes: 9 additions & 0 deletions lib/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,19 @@ func (e InvalidGithubSearchQueryError) Error() string {
return fmt.Sprintf("%v The search query %v contains invalid characters", constants.RedColor("Error:"), constants.RedColor(e.SearchQuery))
}

// BinaryMismatchError occurs if the downloaded binary hash doesn't match the hash in the lockfile
type BinaryMismatchError struct {
BinaryName string
}

func (e BinaryMismatchError) Error() string {
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))
}

// SelfInstallError occurs when attempting to install or upgrade stew using stew
type SelfInstallError struct {
}

func (e SelfInstallError) Error() string {
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:"))
}
4 changes: 4 additions & 0 deletions lib/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func getGithubJSON(owner, repo string) (string, error) {

// NewGithubProject creates a new instance of the GithubProject struct
func NewGithubProject(owner, repo string) (GithubProject, error) {
if owner == constants.StewOwner && repo == constants.StewRepo {
return GithubProject{}, SelfInstallError{}
}

ghJSON, err := getGithubJSON(owner, repo)
if err != nil {
return GithubProject{}, err
Expand Down

0 comments on commit 9436857

Please sign in to comment.