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

Curation - Recognize 403 or 500 errors from the tree builder #1138

Merged
merged 4 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 16 additions & 2 deletions utils/java/mvn.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,15 @@ func (mdt *MavenDepTreeManager) RunMvnCmd(goals []string) (cmdOutput []byte, err
//#nosec G204
cmdOutput, err = exec.Command("mvn", goals...).CombinedOutput()
if err != nil {
stringOutput := string(cmdOutput)
if len(cmdOutput) > 0 {
log.Info(string(cmdOutput))
log.Info(stringOutput)
}
if msg := mdt.suspectCurationBlockedError(stringOutput); msg != "" {
err = fmt.Errorf("failed running command 'mvn %s\n\n%s", strings.Join(goals, " "), msg)
} else {
err = fmt.Errorf("failed running command 'mvn %s': %s", strings.Join(goals, " "), err.Error())
}
err = fmt.Errorf("failed running command 'mvn %s': %s", strings.Join(goals, " "), err.Error())
}
return
}
Expand Down Expand Up @@ -246,3 +251,12 @@ func (mdt *MavenDepTreeManager) CreateTempDirWithSettingsXmlIfNeeded() (tempDirP
}
return
}

// In case mvn tree fails on 403 or 500 it can be related to packages blocked by curation.
// For this use case to succeed, pass through should be enabled in the curated repos
func (mdt *MavenDepTreeManager) suspectCurationBlockedError(cmdOutput string) (msgToUser string) {
if mdt.isCurationCmd && (strings.Contains(cmdOutput, "status code: 403") || strings.Contains(cmdOutput, "status code: 500")) {
msgToUser = "Failed to get dependencies tree for maven project, Please verify pass-through enabled on the curated repos"
}
return msgToUser
}
40 changes: 40 additions & 0 deletions utils/java/mvn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,43 @@ func TestRemoveMavenConfig(t *testing.T) {
assert.NoError(t, err)
assert.FileExists(t, mavenConfigPath)
}

func TestMavenDepTreeManager_suspectCurationBlockedError(t *testing.T) {
tests := []struct {
name string
wantMsgToUser string
input string
}{
{
name: "failed on 403",
wantMsgToUser: "Please verify pass-through enabled on the curated repos",
input: "ERROR] Failed to execute goal on project my-app: Could not resolve dependencies for project com.mycompany.app:my-app:jar:1.0-SNAPSHOT: Failed to " +
"collect dependencies at junit:junit:jar:3.8.1: Failed to read artifact descriptor for junit:junit:jar:3.8.1: " +
"The following artifacts could not be resolved: junit:junit:pom:3.8.1 (absent): Could not transfer artifact junit:junit:pom:3.8.1 " +
"from/to artifactory (http://test:8046/artifactory/api/curation/audit/maven-remote): status code: 403, reason phrase: Forbidden (403)",
},
{
name: "failed on 500",
wantMsgToUser: "Please verify pass-through enabled on the curated repos",
input: "[ERROR] Failed to execute goal on project my-app: Could not resolve dependencies for project com.mycompany.app:my-app:jar:1.0-SNAPSHOT: " +
"Failed to collect dependencies at junit:junit:jar:3.8.1: Failed to read artifact descriptor for junit:junit:jar:3.8.1: The following artifacts" +
" could not be resolved: junit:junit:pom:3.8.1 (absent): Could not transfer artifact junit:junit:pom:3.8.1 from/to artifactory" +
" (http://test:8046/artifactory/api/curation/audit/virtual-to-smart): status code: 500, reason phrase: Internal Server Error (500)",
},
{
name: "not 403 or 500",
wantMsgToUser: "",
input: "ERROR] Failed to execute goal on project my-app: Could not resolve dependencies for project com.mycompany.app:my-app:jar:1.0-SNAPSHOT: Failed to " +
"collect dependencies at junit:junit:jar:3.8.1: Failed to read artifact descriptor for junit:junit:jar:3.8.1: " +
"The following artifacts could not be resolved: junit:junit:pom:3.8.1 (absent): Could not transfer artifact junit:junit:pom:3.8.1 " +
"from/to artifactory (http://test:8046/artifactory/api/curation/audit/maven-remote): status code: 400, reason phrase: Forbidden (400)",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
mdt := &MavenDepTreeManager{}
msg := mdt.suspectCurationBlockedError(tt.input)
assert.Contains(t, tt.wantMsgToUser, msg)
})
}
}
Loading