Skip to content

Commit

Permalink
Rename auth webhook component
Browse files Browse the repository at this point in the history
- `WebhookCache` -> `AuthWebhookCache`
- `WebhookClient` -> `AuthWebhookClient`
  • Loading branch information
window9u committed Feb 18, 2025
1 parent a491bbc commit d1bc63e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions server/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ type Backend struct {
Config *Config

// AuthWebhookCache is used to cache the response of the auth webhook.
WebhookCache *cache.LRUExpireCache[string, pkgtypes.Pair[
AuthWebhookCache *cache.LRUExpireCache[string, pkgtypes.Pair[
int,
*types.AuthWebhookResponse,
]]
// WebhookClient is used to send auth webhook.
WebhookClient *webhook.Client[types.AuthWebhookRequest, types.AuthWebhookResponse]
// AuthWebhookClient is used to send auth webhook.
AuthWebhookClient *webhook.Client[types.AuthWebhookRequest, types.AuthWebhookResponse]

// EventWebhookCache is used to cache the response of the event webhook.
EventWebhookCache *cache.LRUExpireCache[string, int]
Expand Down Expand Up @@ -95,11 +95,11 @@ func New(
conf.Hostname = hostname
}

// 02. Create the webhook webhookCache and client.
webhookCache := cache.NewLRUExpireCache[string, pkgtypes.Pair[int, *types.AuthWebhookResponse]](
// 02. Create the webhook authWebhookCache and client.
authWebhookCache := cache.NewLRUExpireCache[string, pkgtypes.Pair[int, *types.AuthWebhookResponse]](
conf.AuthWebhookCacheSize,
)
webhookClient := webhook.NewClient[types.AuthWebhookRequest, types.AuthWebhookResponse](
authWebhookClient := webhook.NewClient[types.AuthWebhookRequest, types.AuthWebhookResponse](
webhook.Options{
MaxRetries: conf.AuthWebhookMaxRetries,
MinWaitInterval: conf.ParseAuthWebhookMinWaitInterval(),
Expand Down Expand Up @@ -182,8 +182,8 @@ func New(
return &Backend{
Config: conf,

WebhookCache: webhookCache,
WebhookClient: webhookClient,
AuthWebhookCache: authWebhookCache,
AuthWebhookClient: authWebhookClient,

EventWebhookClient: eventWebhookClient,
EventWebhookCache: eventWebhookCache,
Expand Down
6 changes: 3 additions & 3 deletions server/rpc/auth/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ func verifyAccess(
}

cacheKey := generateCacheKey(prj.PublicKey, body)
if entry, ok := be.WebhookCache.Get(cacheKey); ok {
if entry, ok := be.AuthWebhookCache.Get(cacheKey); ok {
return handleWebhookResponse(entry.First, entry.Second)
}

res, status, err := be.WebhookClient.Send(
res, status, err := be.AuthWebhookClient.Send(
ctx,
prj.AuthWebhookURL,
"",
Expand All @@ -74,7 +74,7 @@ func verifyAccess(

// TODO(hackerwins): We should consider caching the response of Unauthorized as well.
if status != http.StatusUnauthorized {
be.WebhookCache.Add(
be.AuthWebhookCache.Add(
cacheKey,
pkgtypes.Pair[int, *types.AuthWebhookResponse]{First: status, Second: res},
be.Config.ParseAuthWebhookCacheTTL(),
Expand Down

0 comments on commit d1bc63e

Please sign in to comment.