-
Notifications
You must be signed in to change notification settings - Fork 69
/
command_config.go
48 lines (36 loc) · 1.32 KB
/
command_config.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
package agent
import (
"github.com/spf13/cobra"
"github.com/newrelic/newrelic-cli/internal/output"
"github.com/newrelic/newrelic-cli/internal/utils"
)
var (
encodeKey string
textToEncode string
)
var cmdConfig = &cobra.Command{
Use: "config",
Short: "Configuration utilities/helpers for New Relic agents",
}
var cmdConfigObfuscate = &cobra.Command{
Use: "obfuscate",
Short: "Obfuscate a configuration value using a key",
Long: `Obfuscate a configuration value using a key. The obfuscated value
should be placed in the Agent configuration or in an environment variable."
`,
Example: "newrelic agent config obfuscate --value <config_value> --key <obfuscation_key>",
Run: func(cmd *cobra.Command, args []string) {
result := ObfuscationResult{
ObfuscatedValue: obfuscateStringWithKey(textToEncode, encodeKey),
}
utils.LogIfFatal(output.Print(result))
},
}
func init() {
Command.AddCommand(cmdConfig)
cmdConfig.AddCommand(cmdConfigObfuscate)
cmdConfigObfuscate.Flags().StringVarP(&encodeKey, "key", "k", "", "the key to use when obfuscating the clear-text value")
cmdConfigObfuscate.Flags().StringVarP(&textToEncode, "value", "v", "", "the value, in clear text, to be obfuscated")
utils.LogIfError(cmdConfigObfuscate.MarkFlagRequired("key"))
utils.LogIfError(cmdConfigObfuscate.MarkFlagRequired("value"))
}