From 63c45d1980df73c8ab954ddc501a5c8af0fe7c51 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 5 Nov 2024 18:33:14 +0100 Subject: [PATCH] go: Add operational webhook endpoint API --- go/operational_webhook_endpoint.go | 119 +++++++++++++++++++++++++++++ go/svix.go | 20 +++-- 2 files changed, 131 insertions(+), 8 deletions(-) create mode 100644 go/operational_webhook_endpoint.go diff --git a/go/operational_webhook_endpoint.go b/go/operational_webhook_endpoint.go new file mode 100644 index 000000000..79285a4d9 --- /dev/null +++ b/go/operational_webhook_endpoint.go @@ -0,0 +1,119 @@ +package svix + +import ( + "context" + + "github.com/svix/svix-webhooks/go/internal/openapi" +) + +type ( + ListResponseOperationalWebhookEndpointOut = openapi.ListResponseOperationalWebhookEndpointOut + OperationalWebhookEndpointIn = openapi.OperationalWebhookEndpointIn + OperationalWebhookEndpointUpdate = openapi.OperationalWebhookEndpointUpdate + OperationalWebhookEndpointOut = openapi.OperationalWebhookEndpointOut + OperationalWebhookEndpointSecretOut = openapi.OperationalWebhookEndpointSecretOut + OperationalWebhookEndpointSecretIn = openapi.OperationalWebhookEndpointSecretIn + Ordering = openapi.Ordering +) + +type OperationalWebhookEndpoint struct { + api *openapi.APIClient +} + +type OperationalWebhookEndpointListOptions struct { + Iterator *string + Limit *int32 + Order *Ordering +} + +func (e *OperationalWebhookEndpoint) List(ctx context.Context, options *OperationalWebhookEndpointListOptions) (*ListResponseOperationalWebhookEndpointOut, error) { + req := e.api.WebhookEndpointAPI.ListOperationalWebhookEndpoint(ctx) + if options != nil { + if options.Iterator != nil { + req = req.Iterator(*options.Iterator) + } + if options.Limit != nil { + req = req.Limit(*options.Limit) + } + if options.Order != nil { + req = req.Order(*options.Order) + } + } + ret, res, err := req.Execute() + if err != nil { + return nil, wrapError(err, res) + } + return ret, nil +} + +func (e *OperationalWebhookEndpoint) Create(ctx context.Context, endpointIn *OperationalWebhookEndpointIn) (*OperationalWebhookEndpointOut, error) { + return e.CreateWithOptions(ctx, endpointIn, nil) +} + +func (e *OperationalWebhookEndpoint) CreateWithOptions(ctx context.Context, endpointIn *OperationalWebhookEndpointIn, options *PostOptions) (*OperationalWebhookEndpointOut, error) { + req := e.api.WebhookEndpointAPI.CreateOperationalWebhookEndpoint(ctx) + req = req.OperationalWebhookEndpointIn(*endpointIn) + if options != nil { + if options.IdempotencyKey != nil { + req = req.IdempotencyKey(*options.IdempotencyKey) + } + } + ret, res, err := req.Execute() + if err != nil { + return nil, wrapError(err, res) + } + return ret, nil +} + +func (e *OperationalWebhookEndpoint) Get(ctx context.Context, endpointId string) (*OperationalWebhookEndpointOut, error) { + req := e.api.WebhookEndpointAPI.GetOperationalWebhookEndpoint(ctx, endpointId) + ret, res, err := req.Execute() + if err != nil { + return nil, wrapError(err, res) + } + return ret, nil +} + +func (e *OperationalWebhookEndpoint) Update(ctx context.Context, endpointId string, endpointUpdate *OperationalWebhookEndpointUpdate) (*OperationalWebhookEndpointOut, error) { + req := e.api.WebhookEndpointAPI.UpdateOperationalWebhookEndpoint(ctx, endpointId) + req = req.OperationalWebhookEndpointUpdate(*endpointUpdate) + ret, res, err := req.Execute() + if err != nil { + return nil, wrapError(err, res) + } + return ret, nil +} + +func (e *OperationalWebhookEndpoint) Delete(ctx context.Context, endpointId string) error { + req := e.api.WebhookEndpointAPI.DeleteOperationalWebhookEndpoint(ctx, endpointId) + res, err := req.Execute() + return wrapError(err, res) +} + +func (e *OperationalWebhookEndpoint) GetSecret(ctx context.Context, endpointId string) (*OperationalWebhookEndpointSecretOut, error) { + req := e.api.WebhookEndpointAPI.GetOperationalWebhookEndpointSecret(ctx, endpointId) + ret, res, err := req.Execute() + if err != nil { + return nil, wrapError(err, res) + } + return ret, nil +} + +func (e *OperationalWebhookEndpoint) RotateSecret(ctx context.Context, endpointId string, endpointSecretRotateIn *OperationalWebhookEndpointSecretIn) error { + return e.RotateSecretWithOptions(ctx, endpointId, endpointSecretRotateIn, nil) +} + +func (e *OperationalWebhookEndpoint) RotateSecretWithOptions(ctx context.Context, endpointId string, endpointSecretRotateIn *OperationalWebhookEndpointSecretIn, options *PostOptions) error { + req := e.api.WebhookEndpointAPI.RotateOperationalWebhookEndpointSecret(ctx, endpointId) + req = req.OperationalWebhookEndpointSecretIn(*endpointSecretRotateIn) + if options != nil { + if options.IdempotencyKey != nil { + req = req.IdempotencyKey(*options.IdempotencyKey) + } + } + res, err := req.Execute() + if err != nil { + return wrapError(err, res) + } + return nil +} diff --git a/go/svix.go b/go/svix.go index 1eb22bec7..0760bfccd 100644 --- a/go/svix.go +++ b/go/svix.go @@ -20,14 +20,15 @@ type ( HTTPClient *http.Client } Svix struct { - Authentication *Authentication - Application *Application - Endpoint *Endpoint - EventType *EventType - Integration *Integration - Message *Message - MessageAttempt *MessageAttempt - Statistics *Statistics + Authentication *Authentication + Application *Application + Endpoint *Endpoint + EventType *EventType + Integration *Integration + Message *Message + MessageAttempt *MessageAttempt + Statistics *Statistics + OperationalWebhookEndpoint *OperationalWebhookEndpoint } ) @@ -108,5 +109,8 @@ func New(token string, options *SvixOptions) *Svix { Statistics: &Statistics{ api: apiClient, }, + OperationalWebhookEndpoint: &OperationalWebhookEndpoint{ + api: apiClient, + }, } }