2022-07-06 05:08:21 +00:00
|
|
|
package provider_template
|
|
|
|
|
|
|
|
import (
|
2022-07-10 16:19:33 +00:00
|
|
|
"context"
|
2023-03-26 01:50:45 +00:00
|
|
|
"fmt"
|
|
|
|
"strings"
|
2022-07-08 13:39:23 +00:00
|
|
|
"time"
|
|
|
|
|
2022-07-06 05:08:21 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/db/models"
|
|
|
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
2022-07-08 13:39:23 +00:00
|
|
|
"github.com/google/uuid"
|
2022-07-06 05:08:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// AddWebhook to add webhook
|
2023-07-31 11:12:11 +00:00
|
|
|
func (p *provider) AddWebhook(ctx context.Context, webhook *models.Webhook) (*model.Webhook, error) {
|
2022-07-08 13:39:23 +00:00
|
|
|
if webhook.ID == "" {
|
|
|
|
webhook.ID = uuid.New().String()
|
|
|
|
}
|
|
|
|
webhook.Key = webhook.ID
|
|
|
|
webhook.CreatedAt = time.Now().Unix()
|
|
|
|
webhook.UpdatedAt = time.Now().Unix()
|
2023-03-26 01:50:45 +00:00
|
|
|
// Add timestamp to make event name unique for legacy version
|
|
|
|
webhook.EventName = fmt.Sprintf("%s-%d", webhook.EventName, time.Now().Unix())
|
2022-07-10 16:19:33 +00:00
|
|
|
return webhook.AsAPIWebhook(), nil
|
2022-07-06 05:08:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateWebhook to update webhook
|
2023-07-31 11:12:11 +00:00
|
|
|
func (p *provider) UpdateWebhook(ctx context.Context, webhook *models.Webhook) (*model.Webhook, error) {
|
2022-07-08 13:39:23 +00:00
|
|
|
webhook.UpdatedAt = time.Now().Unix()
|
2023-03-26 01:50:45 +00:00
|
|
|
// Event is changed
|
|
|
|
if !strings.Contains(webhook.EventName, "-") {
|
|
|
|
webhook.EventName = fmt.Sprintf("%s-%d", webhook.EventName, time.Now().Unix())
|
|
|
|
}
|
2022-07-10 16:19:33 +00:00
|
|
|
return webhook.AsAPIWebhook(), nil
|
2022-07-06 05:08:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListWebhooks to list webhook
|
2023-07-31 11:12:11 +00:00
|
|
|
func (p *provider) ListWebhook(ctx context.Context, pagination *model.Pagination) (*model.Webhooks, error) {
|
2022-07-06 05:08:21 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetWebhookByID to get webhook by id
|
2022-07-10 16:19:33 +00:00
|
|
|
func (p *provider) GetWebhookByID(ctx context.Context, webhookID string) (*model.Webhook, error) {
|
|
|
|
return nil, nil
|
2022-07-06 05:08:21 +00:00
|
|
|
}
|
|
|
|
|
2022-07-09 05:51:32 +00:00
|
|
|
// GetWebhookByEventName to get webhook by event_name
|
2023-03-26 01:50:45 +00:00
|
|
|
func (p *provider) GetWebhookByEventName(ctx context.Context, eventName string) ([]*model.Webhook, error) {
|
2022-07-10 16:19:33 +00:00
|
|
|
return nil, nil
|
2022-07-06 05:08:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteWebhook to delete webhook
|
2022-07-10 16:19:33 +00:00
|
|
|
func (p *provider) DeleteWebhook(ctx context.Context, webhook *model.Webhook) error {
|
2022-07-11 14:10:54 +00:00
|
|
|
// Also delete webhook logs for given webhook id
|
2022-07-06 05:08:21 +00:00
|
|
|
return nil
|
|
|
|
}
|