Skip to content
Open
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
21 changes: 20 additions & 1 deletion internal/provider/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
)

var (
projectPropertyURLRegex = regexp.MustCompile("^/api/v1/project/" + uuidRegex + "/property$")
projectPropertyURLRegex = regexp.MustCompile("^/api/v1/project/" + uuidRegex + "/property$")
notificationRuleURLPattern = "/api/v1/notification/rule"

Check failure on line 23 in internal/provider/http_client.go

View workflow job for this annotation

GitHub Actions / Build

notificationRuleURLPattern is a global variable (gochecknoglobals)
)

type (
Expand All @@ -34,7 +35,7 @@
}
)

func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {

Check failure on line 38 in internal/provider/http_client.go

View workflow job for this annotation

GitHub Actions / Build

cognitive complexity 13 of func `(*transport).RoundTrip` is high (> 10) (gocognit)
for _, header := range t.headers {
req.Header.Add(header.Name, header.Value)
}
Expand All @@ -56,6 +57,24 @@
}
req.Body = io.NopCloser(bodyBuf)
}
// The DependencyTrack API rejects updates that include triggerType
// ("Trigger type can not be changed"), even if the value hasn't changed.
// Strip it from notification rule update (POST) requests.
if req.URL.Path == notificationRuleURLPattern && req.Method == http.MethodPost {
var body map[string]json.RawMessage
err := json.NewDecoder(req.Body).Decode(&body)
if err != nil {
return nil, err
}
delete(body, "triggerType")
bodyBuf := new(bytes.Buffer)
err = json.NewEncoder(bodyBuf).Encode(body)
if err != nil {
return nil, err
}
req.Body = io.NopCloser(bodyBuf)
req.ContentLength = int64(bodyBuf.Len())
}
// End patching.
return t.inner.RoundTrip(req)
}
Expand Down
Loading