-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
utils.go
52 lines (43 loc) · 1.25 KB
/
utils.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
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
package workloadmeta
import (
"fmt"
"strings"
"github.com/DataDog/datadog-agent/pkg/util/scrubber"
)
func mapToString(m map[string]string) string {
var sb strings.Builder
for k, v := range m {
fmt.Fprintf(&sb, "%s:%s ", k, v)
}
return sb.String()
}
func mapToScrubbedJSONString(m map[string]string) string {
var sb strings.Builder
for k, v := range m {
scrubbed, err := scrubber.ScrubJSONString(v)
if err == nil {
fmt.Fprintf(&sb, "%s:%s ", k, scrubbed)
} else {
fmt.Fprintf(&sb, "%s:%s ", k, v)
}
}
return sb.String()
}
func sliceToString(s []string) string {
return strings.Join(s, " ")
}
// filterAndFormatEnvVars extracts and formats a subset of allowed environment variables.
func filterAndFormatEnvVars(envs map[string]string) string {
allowedEnvVariables := []string{"DD_SERVICE", "DD_ENV", "DD_VERSION"}
var sb strings.Builder
for _, allowed := range allowedEnvVariables {
if val, found := envs[allowed]; found {
fmt.Fprintf(&sb, "%s:%s ", allowed, val)
}
}
return sb.String()
}