-
Notifications
You must be signed in to change notification settings - Fork 70
/
command_entity.go
53 lines (41 loc) · 1.08 KB
/
command_entity.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
package decode
import (
"encoding/base64"
"fmt"
"strings"
"github.com/spf13/cobra"
"github.com/newrelic/newrelic-cli/internal/utils"
)
var (
entityKey string
)
// Command represents the decode command.
var cmdEntity = &cobra.Command{
Use: "entity",
Short: "Decodes NR1 Entitys ",
Example: `newrelic decode entity MXxBUE18QVBQTElDQVRJT058Mzk4NDkyNDQw`,
Run: func(cmd *cobra.Command, args []string) {
relicString := strings.Join(args, "")
decoded, err := base64.StdEncoding.DecodeString(relicString)
utils.LogIfFatal(err)
decodedEntity := string(decoded)
splitEntity := strings.Split(decodedEntity, "|")
switch entityKey {
case "account":
fmt.Println(splitEntity[0])
case "product":
fmt.Println(splitEntity[1])
case "feature":
fmt.Println(splitEntity[2])
case "ID":
fmt.Println(splitEntity[3])
default:
fmt.Println(decodedEntity)
}
},
}
func init() {
Command.AddCommand(cmdEntity)
cmdEntity.Flags().StringVarP(&entityKey, "key", "k", "", "the key you require back from an entity")
utils.LogIfError(cmdEntity.MarkFlagRequired("key"))
}