From ce2c19f9b335a9d93ab9f2d21792b1a811ff1ff4 Mon Sep 17 00:00:00 2001 From: William Petit Date: Wed, 5 Jul 2023 13:54:01 -0600 Subject: [PATCH] feat(layer,queue): implement matchURLs option --- doc/fr/references/layers/queue.md | 8 ++++++++ internal/proxy/director/layer/queue/layer_options.go | 4 ++-- internal/proxy/director/layer/queue/options.go | 4 +++- internal/proxy/director/layer/queue/queue.go | 8 ++++++++ .../proxy/director/layer/queue/schema/layer-options.json | 6 ++++++ 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/doc/fr/references/layers/queue.md b/doc/fr/references/layers/queue.md index e7404ab..07766fe 100644 --- a/doc/fr/references/layers/queue.md +++ b/doc/fr/references/layers/queue.md @@ -22,6 +22,14 @@ Ce layer permet d'ajouter un mécanisme de file d'attente dynamique au proxy ass - **Valeur par défaut:** `1m` - **Description:** Durée de vie d'une session dans la file d'attente sans activité avant expiration. +### `matchURLs` + +- **Type:** `[]string` +- **Valeur par défaut:** `["*"]` +- **Description:** Limiter l'action de la file d'attente à cette liste de patrons d'URLs. + + Par exemple, si vous souhaitez limiter votre file à l'ensemble d'une section "`/blog`" d'un site, vous pouvez déclarer la valeur `["*/blog*"]`. Les autres URLs du site ne seront pas affectées par cette file d'attente. + ### Schéma Voir le [schéma JSON](../../../../internal/proxy/director/layer/queue/schema/layer-options.json). \ No newline at end of file diff --git a/internal/proxy/director/layer/queue/layer_options.go b/internal/proxy/director/layer/queue/layer_options.go index 7925a1b..8dfcbbb 100644 --- a/internal/proxy/director/layer/queue/layer_options.go +++ b/internal/proxy/director/layer/queue/layer_options.go @@ -11,15 +11,15 @@ import ( type LayerOptions struct { Capacity int64 `mapstructure:"capacity"` - Matchers []string `mapstructure:"matchers"` KeepAlive time.Duration `mapstructure:"keepAlive"` + MatchURLs []string `mapstructure:"matchURLs"` } func fromStoreOptions(storeOptions store.LayerOptions, defaultKeepAlive time.Duration) (*LayerOptions, error) { layerOptions := LayerOptions{ Capacity: 1000, - Matchers: []string{"*"}, KeepAlive: defaultKeepAlive, + MatchURLs: []string{"*"}, } config := mapstructure.DecoderConfig{ diff --git a/internal/proxy/director/layer/queue/options.go b/internal/proxy/director/layer/queue/options.go index db4a6ad..e0dbf6c 100644 --- a/internal/proxy/director/layer/queue/options.go +++ b/internal/proxy/director/layer/queue/options.go @@ -1,6 +1,8 @@ package queue -import "time" +import ( + "time" +) type Options struct { TemplateDir string diff --git a/internal/proxy/director/layer/queue/queue.go b/internal/proxy/director/layer/queue/queue.go index 9e98486..f5c8f10 100644 --- a/internal/proxy/director/layer/queue/queue.go +++ b/internal/proxy/director/layer/queue/queue.go @@ -13,6 +13,7 @@ import ( "time" "forge.cadoles.com/Cadoles/go-proxy" + "forge.cadoles.com/Cadoles/go-proxy/wildcard" "forge.cadoles.com/cadoles/bouncer/internal/proxy/director" "forge.cadoles.com/cadoles/bouncer/internal/store" "github.com/Masterminds/sprig/v3" @@ -57,6 +58,13 @@ func (q *Queue) Middleware(layer *store.Layer) proxy.Middleware { return } + matches := wildcard.MatchAny(r.URL.String(), options.MatchURLs...) + if !matches { + h.ServeHTTP(w, r) + + return + } + defer q.updateMetrics(ctx, layer.Proxy, layer.Name, options) cookieName := q.getCookieName(layer.Name) diff --git a/internal/proxy/director/layer/queue/schema/layer-options.json b/internal/proxy/director/layer/queue/schema/layer-options.json index 7cfd568..a4034a8 100644 --- a/internal/proxy/director/layer/queue/schema/layer-options.json +++ b/internal/proxy/director/layer/queue/schema/layer-options.json @@ -9,6 +9,12 @@ }, "keepAlive": { "type": "string" + }, + "matchURLs": { + "type": "array", + "items": { + "type": "string" + } } }, "additionalProperties": false