Skip to content

Commit

Permalink
grpc service method to get all webhook endpoints (#790)
Browse files Browse the repository at this point in the history
* grpc service method to get all webhook endpoints

* make api vesion a constant

* fix lint

* fix lint issue
  • Loading branch information
etsai-stripe committed Nov 30, 2021
1 parent 1d93952 commit f60b7d0
Show file tree
Hide file tree
Showing 8 changed files with 572 additions and 90 deletions.
65 changes: 65 additions & 0 deletions docs/rpc/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@
- [VersionRequest](#rpc.VersionRequest)
- [VersionResponse](#rpc.VersionResponse)

- [webhook_endpoints_list.proto](#webhook_endpoints_list.proto)
- [WebhookEndpointsListRequest](#rpc.WebhookEndpointsListRequest)
- [WebhookEndpointsListResponse](#rpc.WebhookEndpointsListResponse)
- [WebhookEndpointsListResponse.WebhookEndpointData](#rpc.WebhookEndpointsListResponse.WebhookEndpointData)

- [Scalar Value Types](#scalar-value-types)


Expand Down Expand Up @@ -110,6 +115,7 @@
| Trigger | [TriggerRequest](#rpc.TriggerRequest) | [TriggerResponse](#rpc.TriggerResponse) | Trigger a webhook event. Like `stripe trigger`. |
| TriggersList | [TriggersListRequest](#rpc.TriggersListRequest) | [TriggersListResponse](#rpc.TriggersListResponse) | Get a list of supported events for `Trigger`. |
| Version | [VersionRequest](#rpc.VersionRequest) | [VersionResponse](#rpc.VersionResponse) | Get the version of the Stripe CLI. Like `stripe version`. |
| WebhookEndpointsList | [WebhookEndpointsListRequest](#rpc.WebhookEndpointsListRequest) | [WebhookEndpointsListResponse](#rpc.WebhookEndpointsListResponse) | Get the list of webhook endpoints. |



Expand Down Expand Up @@ -958,6 +964,65 @@



<a name="webhook_endpoints_list.proto"></a>
<p align="right"><a href="#top">Top</a></p>

## webhook_endpoints_list.proto



<a name="rpc.WebhookEndpointsListRequest"></a>

### WebhookEndpointsListRequest







<a name="rpc.WebhookEndpointsListResponse"></a>

### WebhookEndpointsListResponse



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| endpoints | [WebhookEndpointsListResponse.WebhookEndpointData](#rpc.WebhookEndpointsListResponse.WebhookEndpointData) | repeated | A list webhook endpoints |






<a name="rpc.WebhookEndpointsListResponse.WebhookEndpointData"></a>

### WebhookEndpointsListResponse.WebhookEndpointData



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| application | [string](#string) | | Webhook endpoint application |
| enabledEvents | [string](#string) | repeated | Enabled events of the webhook endpoint |
| url | [string](#string) | | Webhook endpoint URL |
| status | [string](#string) | | Webhook endpoint status |















## Scalar Value Types

| .proto Type | Notes | C++ | Java | Python | Go | C# | PHP | Ruby |
Expand Down
2 changes: 1 addition & 1 deletion pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ func getEndpointsFromAPI(ctx context.Context, secretKey, apiBaseURL string) requ
apiBaseURL = stripe.DefaultAPIBaseURL
}

return requests.WebhookEndpointsList(ctx, apiBaseURL, "2019-03-14", secretKey, &config.Profile{})
return requests.WebhookEndpointsList(ctx, apiBaseURL, stripe.APIVersion, secretKey, &config.Profile{})
}

func buildEndpointRoutes(endpoints requests.WebhookEndpointList, forwardURL, forwardConnectURL string, forwardHeaders []string, forwardConnectHeaders []string) ([]EndpointRoute, error) {
Expand Down
34 changes: 34 additions & 0 deletions pkg/rpcservice/webhook_endpoints_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package rpcservice

import (
"context"

"github.com/stripe/stripe-cli/pkg/requests"
"github.com/stripe/stripe-cli/pkg/stripe"
"github.com/stripe/stripe-cli/rpc"
)

// WebhookEndpointsList returns a list of webhook endpoints.
func (srv *RPCService) WebhookEndpointsList(ctx context.Context, req *rpc.WebhookEndpointsListRequest) (*rpc.WebhookEndpointsListResponse, error) {
userConfig := srv.cfg.UserCfg
livemode := false

key, err := userConfig.Profile.GetAPIKey(livemode)
if err != nil {
return nil, err
}

endpoints := requests.WebhookEndpointsList(ctx, stripe.DefaultAPIBaseURL, stripe.APIVersion, key, &userConfig.Profile)

formattedEndpoints := make([]*rpc.WebhookEndpointsListResponse_WebhookEndpointData, 0, len(endpoints.Data))
for _, v := range endpoints.Data {
formattedEndpoints = append(formattedEndpoints, &rpc.WebhookEndpointsListResponse_WebhookEndpointData{
Application: v.Application,
EnabledEvents: v.EnabledEvents,
Url: v.URL,
Status: v.Status,
})
}

return &rpc.WebhookEndpointsListResponse{Endpoints: formattedEndpoints}, nil
}
3 changes: 3 additions & 0 deletions pkg/stripe/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const DefaultAPIBaseURL = "https://api.stripe.com"
// DefaultDashboardBaseURL is the default base URL for dashboard requests
const DefaultDashboardBaseURL = "https://dashboard.stripe.com"

// APIVersion is API version used in CLI
const APIVersion = "2019-03-14"

// Client is the API client used to sent requests to Stripe.
type Client struct {
// The base URL (protocol + hostname) used for all requests sent by this
Expand Down

0 comments on commit f60b7d0

Please sign in to comment.