-
-
Notifications
You must be signed in to change notification settings - Fork 162
/
webhooks.go
34 lines (29 loc) · 936 Bytes
/
webhooks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package resolvers
import (
"context"
"fmt"
"github.com/authorizerdev/authorizer/server/db"
"github.com/authorizerdev/authorizer/server/graph/model"
"github.com/authorizerdev/authorizer/server/token"
"github.com/authorizerdev/authorizer/server/utils"
log "github.com/sirupsen/logrus"
)
// WebhooksResolver resolver for getting the list of webhooks based on pagination
func WebhooksResolver(ctx context.Context, params *model.PaginatedInput) (*model.Webhooks, error) {
gc, err := utils.GinContextFromContext(ctx)
if err != nil {
log.Debug("Failed to get GinContext: ", err)
return nil, err
}
if !token.IsSuperAdmin(gc) {
log.Debug("Not logged in as super admin")
return nil, fmt.Errorf("unauthorized")
}
pagination := utils.GetPagination(params)
webhooks, err := db.Provider.ListWebhook(ctx, pagination)
if err != nil {
log.Debug("failed to get webhooks: ", err)
return nil, err
}
return webhooks, nil
}