-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
137 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package utils | ||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
type PackageManager string | ||
|
||
const ( | ||
Npm PackageManager = "npm" | ||
Maven PackageManager = "maven" | ||
Pip PackageManager = "pip" | ||
Go PackageManager = "go" | ||
) | ||
|
||
// ForbiddenError represents a 403 Forbidden error. | ||
type ForbiddenError struct { | ||
Message string | ||
} | ||
|
||
// Error implements the error interface for ForbiddenError. | ||
func (e *ForbiddenError) Error() string { | ||
return "403 Forbidden" | ||
} | ||
|
||
// NewForbiddenError creates a new ForbiddenError with the given message. | ||
func NewForbiddenError() *ForbiddenError { | ||
return &ForbiddenError{} | ||
} | ||
|
||
// IsForbiddenOutput checks whether the provided output includes a 403 Forbidden. The various package managers have their own forbidden output formats. | ||
func IsForbiddenOutput(tech PackageManager, cmdOutput string) bool { | ||
switch tech { | ||
case "npm": | ||
return strings.Contains(strings.ToLower(cmdOutput), "403 forbidden") | ||
case "maven": | ||
return strings.Contains(cmdOutput, "status code: 403") || | ||
strings.Contains(strings.ToLower(cmdOutput), "403 forbidden") || | ||
// In some cases mvn returns 500 status code even though it got 403 from artifactory. | ||
strings.Contains(cmdOutput, "status code: 500") | ||
case "pip": | ||
return strings.Contains(strings.ToLower(cmdOutput), "http error 403") | ||
case "go": | ||
return strings.Contains(strings.ToLower(cmdOutput), "403 forbidden") || | ||
strings.Contains(strings.ToLower(cmdOutput), " 403") | ||
} | ||
return false | ||
} |