Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: disallow self-install/upgrade #61

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading