Skip to content

Commit

Permalink
Kwu disabled endpoints (stripe#726)
Browse files Browse the repository at this point in the history
* only use endpoing which are not disabled

* updaate test

* updated test

* revert tests

* updated test
  • Loading branch information
kwu-stripe authored Aug 5, 2021
1 parent 1fdf354 commit 7d3ddb5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
9 changes: 9 additions & 0 deletions pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ type EndpointRoute struct {

// EventTypes is the list of event types that should be sent to the endpoint.
EventTypes []string

// Status is whether or not the endpoint is enabled.
Status string
}

// EndpointResponse describes the response to a Stripe event from an endpoint
Expand Down Expand Up @@ -661,6 +664,11 @@ func buildEndpointRoutes(endpoints requests.WebhookEndpointList, forwardURL, for
endpointRoutes := make([]EndpointRoute, 0)

for _, endpoint := range endpoints.Data {
// Ensure the endpoint is enabled.
if endpoint.Status == "disabled" {
continue
}

u, err := url.Parse(endpoint.URL)
// Silently skip over invalid paths
if err == nil {
Expand All @@ -676,6 +684,7 @@ func buildEndpointRoutes(endpoints requests.WebhookEndpointList, forwardURL, for
ForwardHeaders: forwardHeaders,
Connect: false,
EventTypes: endpoint.EnabledEvents,
Status: endpoint.Status,
})
} else {
url, err := buildForwardURL(forwardConnectURL, u)
Expand Down
12 changes: 11 additions & 1 deletion pkg/proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,26 @@ func TestBuildEndpointRoutes(t *testing.T) {
URL: "https://planetexpress.com/hooks",
Application: "",
EnabledEvents: []string{"*"},
Status: "enabled",
}

endpointConnect := requests.WebhookEndpoint{
URL: "https://planetexpress.com/connect-hooks",
Application: "ca_123",
EnabledEvents: []string{"*"},
Status: "enabled",
}

endpointDisabled := requests.WebhookEndpoint{
URL: "https://test-app-url/stripe/payment-webhook",
Application: "ca_123",
EnabledEvents: []string{"payment_intent.payment_failed",
"payment_intent.succeeded"},
Status: "disabled",
}

endpointList := requests.WebhookEndpointList{
Data: []requests.WebhookEndpoint{endpointNormal, endpointConnect},
Data: []requests.WebhookEndpoint{endpointNormal, endpointConnect, endpointDisabled},
}

output, err := buildEndpointRoutes(endpointList, localURL, localURL, []string{"Host: hostname"}, []string{"Host: connecthostname"})
Expand Down
1 change: 1 addition & 0 deletions pkg/requests/webhook_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type WebhookEndpoint struct {
Application string `json:"application"`
EnabledEvents []string `json:"enabled_events"`
URL string `json:"url"`
Status string `json:"status"`
}

// WebhookEndpointsList returns all the webhook endpoints on a users' account
Expand Down

0 comments on commit 7d3ddb5

Please sign in to comment.