MCPcopy Create free account
hub / github.com/authorizerdev/authorizer / UpdateWebhook

Method UpdateWebhook

internal/service/admin_webhooks.go:90–180  ·  view source on GitHub ↗

UpdateWebhook updates an existing webhook's event, endpoint, headers, or enabled state and returns a status message. Requires super-admin auth. Logic migrated from internal/graphql/update_webhook.go.

(ctx context.Context, meta RequestMetadata, params *model.UpdateWebhookRequest)

Source from the content-addressed store, hash-verified

88// enabled state and returns a status message. Requires super-admin auth. Logic
89// migrated from internal/graphql/update_webhook.go.
90func (p *provider) UpdateWebhook(ctx context.Context, meta RequestMetadata, params *model.UpdateWebhookRequest) (*model.Response, *ResponseSideEffects, error) {
91 log := p.Log.With().Str("func", "UpdateWebhook").Logger()
92 if err := p.requireSuperAdmin(ctx, meta); err != nil {
93 return nil, nil, err
94 }
95
96 webhook, err := p.StorageProvider.GetWebhookByID(ctx, params.ID)
97 if err != nil {
98 log.Debug().Err(err).Msg("failed GetWebhookByID")
99 return nil, nil, err
100 }
101
102 var headersMap map[string]interface{}
103 if err := json.Unmarshal([]byte(webhook.Headers), &headersMap); err != nil {
104 log.Debug().Err(err).Msg("error un-marshalling headers")
105 }
106 headersString := ""
107 if headersMap != nil {
108 headerBytes, err := json.Marshal(webhook.Headers)
109 if err != nil {
110 log.Debug().Err(err).Msg("failed to marshall headers")
111 return nil, nil, err
112 }
113 headersString = string(headerBytes)
114 }
115
116 webhookDetails := &schemas.Webhook{
117 ID: webhook.ID,
118 Key: webhook.ID,
119 EventName: webhook.EventName,
120 EventDescription: webhook.EventDescription,
121 EndPoint: webhook.EndPoint,
122 Enabled: webhook.Enabled,
123 Headers: headersString,
124 CreatedAt: webhook.CreatedAt,
125 }
126
127 if params.EventName != nil && webhookDetails.EventName != refs.StringValue(params.EventName) {
128 if isValid := validators.IsValidWebhookEventName(refs.StringValue(params.EventName)); !isValid {
129 log.Debug().Str("event_name", refs.StringValue(params.EventName)).Msg("invalid event name")
130 return nil, nil, fmt.Errorf("invalid event name %s", refs.StringValue(params.EventName))
131 }
132 webhookDetails.EventName = refs.StringValue(params.EventName)
133 }
134 if params.Endpoint != nil && webhookDetails.EndPoint != refs.StringValue(params.Endpoint) {
135 if strings.TrimSpace(refs.StringValue(params.Endpoint)) == "" {
136 log.Debug().Msg("empty endpoint not allowed")
137 return nil, nil, fmt.Errorf("empty endpoint not allowed")
138 }
139 // SSRF protection: validate endpoint URL and resolved IPs (skip in test env).
140 if p.Env != constants.TestEnv {
141 if err := validators.ValidateEndpointURL(refs.StringValue(params.Endpoint)); err != nil {
142 log.Debug().Err(err).Str("endpoint", refs.StringValue(params.Endpoint)).Msg("endpoint URL rejected by SSRF filter")
143 return nil, nil, fmt.Errorf("invalid endpoint: %s", err.Error())
144 }
145 }
146 webhookDetails.EndPoint = refs.StringValue(params.Endpoint)
147 }

Callers

nothing calls this directly

Calls 9

requireSuperAdminMethod · 0.95
StringValueFunction · 0.92
IsValidWebhookEventNameFunction · 0.92
ValidateEndpointURLFunction · 0.92
BoolValueFunction · 0.92
ErrorMethod · 0.80
GetWebhookByIDMethod · 0.65
UpdateWebhookMethod · 0.65
LogEventMethod · 0.65

Tested by

no test coverage detected