-
Notifications
You must be signed in to change notification settings - Fork 73
/
output_parser.go
76 lines (65 loc) · 1.46 KB
/
output_parser.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
70
71
72
73
74
75
76
package execution
import (
"fmt"
"strconv"
)
type OutputParser struct {
output map[string]interface{}
}
func NewOutputParser(output map[string]interface{}) *OutputParser {
return &OutputParser{
output: output,
}
}
func (op *OutputParser) EntityGUID() string {
if val, ok := op.output["EntityGuid"]; ok {
return fmt.Sprintf("%s", val)
}
return ""
}
func (op *OutputParser) Metadata() map[string]string {
metadata, ok := op.output["Metadata"].(map[string]interface{})
if ok {
result := map[string]string{}
for k := range metadata {
if v, ok := metadata[k].(string); ok {
result[k] = v
}
}
return result
}
return nil
}
func (op *OutputParser) IsCapturedCliOutput() bool {
capturedOutput := false
data, ok := op.metadataWithKey("CapturedCliOutput")
if ok {
valAsBool, err := strconv.ParseBool(data)
if err == nil {
capturedOutput = valAsBool
}
}
return capturedOutput
}
func (op *OutputParser) metadataWithKey(key string) (string, bool) {
metadata, ok := op.output["Metadata"].(map[string]interface{})
if ok {
data, exists := metadata[key]
if exists {
return data.(string), ok
}
}
return "", ok
}
func (op *OutputParser) AddMetadata(key string, value string) {
output := op.output
if output == nil {
op.output = make(map[string]interface{})
}
metadata, ok := op.output["Metadata"].(map[string]interface{})
if !ok {
metadata = make(map[string]interface{})
}
metadata[key] = value
op.output["Metadata"] = metadata
}