1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00

Fix project config reset when preset is set (#3782)

This commit is contained in:
Adrien 2022-05-18 17:10:00 +02:00 committed by GitHub
parent 6714794066
commit 3d48364862
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 3 deletions

View File

@ -653,7 +653,6 @@ func setPresetForProject(sys checkmarx.System, projectID, presetIDValue int, pro
if err != nil {
return errors.Wrapf(err, "updating configuration of project %v failed", projectName)
}
log.Entry().Debugf("Configuration of project %v updated", projectName)
return nil
}

View File

@ -111,6 +111,31 @@ type Project struct {
Link Link `json:"link"`
}
// ScanSettings - scan settings at project level
type ScanSettings struct {
Project ProjectLink `json:"project"`
Preset PresetLink `json:"preset"`
EngineConfiguration EngineConfigurationLink `json:"engineConfiguration" `
}
// ProjectLink - project link found in ScanSettings response
type ProjectLink struct {
ProjectID int `json:"id"`
Link Link `json:"link"`
}
// PresetLink - preset link found in ScanSettings response
type PresetLink struct {
PresetID int `json:"id"`
Link Link `json:"link"`
}
// EngineConfigurationLink - engine configuration link found in ScanSettings response
type EngineConfigurationLink struct {
EngineConfigurationID int `json:"id"`
Link Link `json:"link"`
}
// Team - Team Structure
type Team struct {
ID json.RawMessage `json:"id"`
@ -476,6 +501,23 @@ func (sys *SystemInstance) GetPresets() []Preset {
// UpdateProjectConfiguration updates the configuration of the project addressed by projectID
func (sys *SystemInstance) UpdateProjectConfiguration(projectID int, presetID int, engineConfigurationID string) error {
engineConfigID, _ := strconv.Atoi(engineConfigurationID)
var projectScanSettings ScanSettings
header := http.Header{}
header.Set("Content-Type", "application/json")
data, err := sendRequest(sys, http.MethodGet, fmt.Sprintf("/sast/scanSettings/%v", projectID), nil, header)
if err != nil {
// if an error happens, try to update the config anyway
sys.logger.Warnf("Failed to fetch scan settings of project %v: %s", projectID, err)
} else {
// Check if the current project config needs to be updated
json.Unmarshal(data, &projectScanSettings)
if projectScanSettings.Preset.PresetID == presetID && projectScanSettings.EngineConfiguration.EngineConfigurationID == engineConfigID {
sys.logger.Debugf("Project configuration does not need to be updated")
return nil
}
}
jsonData := map[string]interface{}{
"projectId": projectID,
"presetId": presetID,
@ -487,12 +529,11 @@ func (sys *SystemInstance) UpdateProjectConfiguration(projectID int, presetID in
return errors.Wrapf(err, "error marshalling project data")
}
header := http.Header{}
header.Set("Content-Type", "application/json")
_, err = sendRequest(sys, http.MethodPost, "/sast/scanSettings", bytes.NewBuffer(jsonValue), header)
if err != nil {
return errors.Wrapf(err, "request to checkmarx system failed")
}
sys.logger.Debugf("Project configuration updated")
return nil
}