-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.go
More file actions
100 lines (79 loc) · 2.85 KB
/
Copy pathconfig.go
File metadata and controls
100 lines (79 loc) · 2.85 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package gonvoy
import (
"errors"
"strings"
"github.com/ardikabs/gonvoy/pkg/util"
"github.com/envoyproxy/envoy/contrib/golang/common/go/api"
)
var (
errInternalConfigNotFound = errors.New("internal config not found")
)
type internalConfig struct {
filterConfig interface{}
callbacks api.ConfigCallbacks
internalCache Cache
metricsPrefix string
strictBodyAccess bool
allowRequestBodyRead bool
allowRequestBodyWrite bool
allowResponseBodyRead bool
allowResponseBodyWrite bool
preserveContentLengthOnRequest bool
preserveContentLengthOnResponse bool
autoReloadRoute bool
}
func newInternalConfig(options ConfigOptions) *internalConfig {
gc := &internalConfig{
internalCache: newInternalCache(),
autoReloadRoute: options.AutoReloadRoute,
metricsPrefix: options.MetricsPrefix,
strictBodyAccess: !options.DisableStrictBodyAccess,
allowRequestBodyRead: options.EnableRequestBodyRead,
allowRequestBodyWrite: options.EnableRequestBodyWrite,
allowResponseBodyRead: options.EnableResponseBodyRead,
allowResponseBodyWrite: options.EnableResponseBodyWrite,
preserveContentLengthOnRequest: options.DisableChunkedEncodingRequest,
preserveContentLengthOnResponse: options.DisableChunkedEncodingResponse,
}
return gc
}
func (c *internalConfig) defineCounterMetric(name string) api.CounterMetric {
name = strings.ToLower(util.ReplaceAllEmptySpace(c.metricsPrefix + name))
return c.callbacks.DefineCounterMetric(name)
}
func (c *internalConfig) defineGaugeMetric(name string) api.GaugeMetric {
name = strings.ToLower(util.ReplaceAllEmptySpace(c.metricsPrefix + name))
return c.callbacks.DefineGaugeMetric(name)
}
func (c *internalConfig) defineHistogramMetric(name string) api.HistogramMetric {
panic("NOT IMPLEMENTED")
}
func validateFilterConfig(filterConfig interface{}) error {
type validator interface {
Validate() error
}
if validate, ok := filterConfig.(validator); ok {
return validate.Validate()
}
return nil
}
func applyInternalConfig(c *context, cfg *internalConfig) error {
if cfg == nil {
return errInternalConfigNotFound
}
if err := validateFilterConfig(cfg.filterConfig); err != nil {
return err
}
c.filterConfig = cfg.filterConfig
c.cache = cfg.internalCache
c.metrics = newMetrics(cfg.defineCounterMetric, cfg.defineGaugeMetric, cfg.defineHistogramMetric)
c.autoReloadRoute = cfg.autoReloadRoute
c.strictBodyAccess = cfg.strictBodyAccess
c.requestBodyAccessRead = cfg.allowRequestBodyRead
c.requestBodyAccessWrite = cfg.allowRequestBodyWrite
c.responseBodyAccessRead = cfg.allowResponseBodyRead
c.responseBodyAccessWrite = cfg.allowResponseBodyWrite
c.preserveContentLengthOnRequest = cfg.preserveContentLengthOnRequest
c.preserveContentLengthOnResponse = cfg.preserveContentLengthOnResponse
return nil
}