-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
options.go
69 lines (59 loc) · 1.82 KB
/
options.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
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
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Hubble
package options
import (
"fmt"
"strings"
"github.com/sirupsen/logrus"
)
// Option is used to configure parsers
type Option func(*Options)
// Options contains all parser options
type Options struct {
CacheSize int
HubbleRedactSettings HubbleRedactSettings
}
// HubbleRedactSettings contains all hubble redact related options
type HubbleRedactSettings struct {
Enabled bool
RedactHTTPQuery bool
RedactHTTPUserInfo bool
RedactKafkaAPIKey bool
RedactHttpHeaders HttpHeadersList
}
// HttpHeadersList contains the allow/deny list of headers
type HttpHeadersList struct {
Allow map[string]struct{}
Deny map[string]struct{}
}
// CacheSize configures the amount of L7 requests cached for latency calculation
func CacheSize(size int) Option {
return func(opt *Options) {
opt.CacheSize = size
}
}
// Redact configures which data Hubble will redact.
func Redact(logger logrus.FieldLogger, httpQuery, httpUserInfo, kafkaApiKey bool, allowHeaders, denyHeaders []string) Option {
return func(opt *Options) {
opt.HubbleRedactSettings.Enabled = true
opt.HubbleRedactSettings.RedactHTTPQuery = httpQuery
opt.HubbleRedactSettings.RedactHTTPUserInfo = httpUserInfo
opt.HubbleRedactSettings.RedactKafkaAPIKey = kafkaApiKey
opt.HubbleRedactSettings.RedactHttpHeaders = HttpHeadersList{
Allow: headerSliceToMap(allowHeaders),
Deny: headerSliceToMap(denyHeaders),
}
if logger != nil {
logger.WithField(
"options",
fmt.Sprintf("%+v", opt)).Info("configured Hubble with redact options")
}
}
}
func headerSliceToMap(headerList []string) map[string]struct{} {
headerMap := make(map[string]struct{}, len(headerList))
for _, header := range headerList {
headerMap[strings.ToLower(header)] = struct{}{}
}
return headerMap
}