mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-03-03 15:02:35 +02:00
Fix project config reset when preset is set (#3782)
This commit is contained in:
parent
6714794066
commit
3d48364862
@ -653,7 +653,6 @@ func setPresetForProject(sys checkmarx.System, projectID, presetIDValue int, pro
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "updating configuration of project %v failed", projectName)
|
return errors.Wrapf(err, "updating configuration of project %v failed", projectName)
|
||||||
}
|
}
|
||||||
log.Entry().Debugf("Configuration of project %v updated", projectName)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,6 +111,31 @@ type Project struct {
|
|||||||
Link Link `json:"link"`
|
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
|
// Team - Team Structure
|
||||||
type Team struct {
|
type Team struct {
|
||||||
ID json.RawMessage `json:"id"`
|
ID json.RawMessage `json:"id"`
|
||||||
@ -476,6 +501,23 @@ func (sys *SystemInstance) GetPresets() []Preset {
|
|||||||
// UpdateProjectConfiguration updates the configuration of the project addressed by projectID
|
// UpdateProjectConfiguration updates the configuration of the project addressed by projectID
|
||||||
func (sys *SystemInstance) UpdateProjectConfiguration(projectID int, presetID int, engineConfigurationID string) error {
|
func (sys *SystemInstance) UpdateProjectConfiguration(projectID int, presetID int, engineConfigurationID string) error {
|
||||||
engineConfigID, _ := strconv.Atoi(engineConfigurationID)
|
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{}{
|
jsonData := map[string]interface{}{
|
||||||
"projectId": projectID,
|
"projectId": projectID,
|
||||||
"presetId": presetID,
|
"presetId": presetID,
|
||||||
@ -487,12 +529,11 @@ func (sys *SystemInstance) UpdateProjectConfiguration(projectID int, presetID in
|
|||||||
return errors.Wrapf(err, "error marshalling project data")
|
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)
|
_, err = sendRequest(sys, http.MethodPost, "/sast/scanSettings", bytes.NewBuffer(jsonValue), header)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "request to checkmarx system failed")
|
return errors.Wrapf(err, "request to checkmarx system failed")
|
||||||
}
|
}
|
||||||
|
sys.logger.Debugf("Project configuration updated")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user