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

Remove WebhookConfig.Headers in favour of WebhookConfig.HTTP.HTTPHeaders #122

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 9 additions & 4 deletions pkg/eventstreams/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/hyperledger/firefly-common/pkg/config"
"github.com/hyperledger/firefly-common/pkg/dbsql"
"github.com/hyperledger/firefly-common/pkg/ffresty"
"github.com/hyperledger/firefly-common/pkg/fftypes"
"github.com/hyperledger/firefly-common/pkg/retry"
"github.com/hyperledger/firefly-common/pkg/wsclient"
Expand Down Expand Up @@ -301,8 +302,10 @@ func TestE2E_DeliveryWebHooks200(t *testing.T) {
Webhook: &WebhookConfig{
URL: ptrTo(whServer.URL + "/some/path"),
Method: ptrTo("PUT"),
Headers: map[string]string{
"my-header": "my-value",
HTTP: &ffresty.HTTPConfig{
HTTPHeaders: map[string]interface{}{
"my-header": "my-value",
},
},
},
}
Expand Down Expand Up @@ -371,8 +374,10 @@ func TestE2E_DeliveryWebHooks500Retry(t *testing.T) {
Webhook: &WebhookConfig{
URL: ptrTo(whServer.URL + "/some/path"),
Method: ptrTo("PUT"),
Headers: map[string]string{
"my-header": "my-value",
HTTP: &ffresty.HTTPConfig{
HTTPHeaders: map[string]interface{}{
"my-header": "my-value",
},
},
},
}
Expand Down
10 changes: 7 additions & 3 deletions pkg/eventstreams/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
type WebhookConfig struct {
URL *string `ffstruct:"whconfig" json:"url,omitempty"`
Method *string `ffstruct:"whconfig" json:"method,omitempty"`
Headers map[string]string `ffstruct:"whconfig" json:"headers,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would have to feed its way into a release note as it's a breaking change, I wonder if we want a deprecated field instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest at the stage of lifeycle we're at with this function we're ok with the release notes item.
I can include that cutting a release on the common library.

TLSConfigName *string `ffstruct:"whconfig" json:"tlsConfigName,omitempty"`
HTTP *ffresty.HTTPConfig `ffstruct:"whconfig" json:"http,omitempty"`
validated bool
Expand Down Expand Up @@ -115,8 +114,13 @@ func (w *webhookAction[CT, DT]) AttemptDispatch(ctx context.Context, attempt int
SetResult(&resBody).
SetError(&resBody)
req.Header.Set("Content-Type", "application/json")
for h, v := range w.spec.Headers {
req.Header.Set(h, v)

if w.spec.HTTP != nil {
for h, v := range w.spec.HTTP.HTTPHeaders {
if vs, ok := v.(string); ok {
req.Header.Set(h, vs)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we just remove this. They get added as part of the init of the HTTP Config so this will result in double work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - thanks

}
res, err := req.Execute(method, u.String())
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions pkg/eventstreams/webhooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,11 @@ func TestWebhooksCustomHeaders403(t *testing.T) {

u := fmt.Sprintf("http://%s/test/path", s.Listener.Addr())
wh := newTestWebhooks(t, &WebhookConfig{URL: &u})
wh.spec.Headers = map[string]string{
"test-header": "test-value",
wh.spec.HTTP = &ffresty.HTTPConfig{
HTTPHeaders: map[string]interface{}{
"test-header": "test-value",
},
}

done := make(chan struct{})
go func() {
err := wh.AttemptDispatch(context.Background(), 0, &EventBatch[testData]{
Expand Down