-
Notifications
You must be signed in to change notification settings - Fork 222
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
feat: Add webhook configuration for sending event payloads #2087
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2087 +/- ##
==========================================
+ Coverage 70.61% 70.75% +0.14%
==========================================
Files 70 73 +3
Lines 6823 6997 +174
==========================================
+ Hits 4818 4951 +133
- Misses 1727 1761 +34
- Partials 278 285 +7
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
body, err := json.Marshal(e) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, w.url, bytes.NewBuffer(body)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// If the signing secret is configured, add the specific header to it. | ||
if w.signingSecret != "" { | ||
signedPayload := w.signPayload(body) | ||
|
||
req.Header.Add(fliptSignatureHeader, fmt.Sprintf("%x", signedPayload)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should probably also be adding the URL to this payload.
Just wondering, given we're concerned with signing event payload, if we should also be concerned about where they're being signed. So that folks couldn't replay signed events to different sources and them still be deemed valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GeorgeMac That is a great idea. So basically adding the URL in the event payload?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thought around client body reading. Otherwise, I think this looks great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking good, one comment about the name of the maxBackoff configuration field, also would you mind adding some tests for the webhook/webhook.go
and webhook/client.go
files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great, just one piece of debugging left in there.
} | ||
|
||
// SendAudit will send an audit event to a configured server at a URL. | ||
func (w *HTTPClient) SendAudit(e audit.Event) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was thinking we might want to modify the signature of this method to add ctx
as the first parameter, that way we could pass it down to http.NewRequestWithContext
below, and cancel any inflight requests if Flipt were to shutdown potentially
return err | ||
} | ||
|
||
req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, w.url, bytes.NewBuffer(body)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should probably set the request headers for content-type: application/json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great! great work @yquansah !! 🪝
Adds support for receiving Flipt audit event payloads to a configured server. This PR does the following:
Audit
configuration for supporting sending a webhookAudit
configurationCompletes FLI-591