aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/go-plugin/log_entry.go
diff options
context:
space:
mode:
authorAlex Pilon <apilon@hashicorp.com>2019-02-22 18:24:37 -0500
committerAlex Pilon <apilon@hashicorp.com>2019-02-22 18:24:37 -0500
commit15c0b25d011f37e7c20aeca9eaf461f78285b8d9 (patch)
tree255c250a5c9d4801c74092d33b7337d8c14438ff /vendor/github.com/hashicorp/go-plugin/log_entry.go
parent07971ca38143c5faf951d152fba370ddcbe26ad5 (diff)
downloadterraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.gz
terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.zst
terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.zip
deps: github.com/hashicorp/terraform@sdk-v0.11-with-go-modules
Updated via: go get github.com/hashicorp/terraform@sdk-v0.11-with-go-modules and go mod tidy
Diffstat (limited to 'vendor/github.com/hashicorp/go-plugin/log_entry.go')
-rw-r--r--vendor/github.com/hashicorp/go-plugin/log_entry.go73
1 files changed, 73 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/go-plugin/log_entry.go b/vendor/github.com/hashicorp/go-plugin/log_entry.go
new file mode 100644
index 0000000..2996c14
--- /dev/null
+++ b/vendor/github.com/hashicorp/go-plugin/log_entry.go
@@ -0,0 +1,73 @@
1package plugin
2
3import (
4 "encoding/json"
5 "time"
6)
7
8// logEntry is the JSON payload that gets sent to Stderr from the plugin to the host
9type logEntry struct {
10 Message string `json:"@message"`
11 Level string `json:"@level"`
12 Timestamp time.Time `json:"timestamp"`
13 KVPairs []*logEntryKV `json:"kv_pairs"`
14}
15
16// logEntryKV is a key value pair within the Output payload
17type logEntryKV struct {
18 Key string `json:"key"`
19 Value interface{} `json:"value"`
20}
21
22// flattenKVPairs is used to flatten KVPair slice into []interface{}
23// for hclog consumption.
24func flattenKVPairs(kvs []*logEntryKV) []interface{} {
25 var result []interface{}
26 for _, kv := range kvs {
27 result = append(result, kv.Key)
28 result = append(result, kv.Value)
29 }
30
31 return result
32}
33
34// parseJSON handles parsing JSON output
35func parseJSON(input string) (*logEntry, error) {
36 var raw map[string]interface{}
37 entry := &logEntry{}
38
39 err := json.Unmarshal([]byte(input), &raw)
40 if err != nil {
41 return nil, err
42 }
43
44 // Parse hclog-specific objects
45 if v, ok := raw["@message"]; ok {
46 entry.Message = v.(string)
47 delete(raw, "@message")
48 }
49
50 if v, ok := raw["@level"]; ok {
51 entry.Level = v.(string)
52 delete(raw, "@level")
53 }
54
55 if v, ok := raw["@timestamp"]; ok {
56 t, err := time.Parse("2006-01-02T15:04:05.000000Z07:00", v.(string))
57 if err != nil {
58 return nil, err
59 }
60 entry.Timestamp = t
61 delete(raw, "@timestamp")
62 }
63
64 // Parse dynamic KV args from the hclog payload.
65 for k, v := range raw {
66 entry.KVPairs = append(entry.KVPairs, &logEntryKV{
67 Key: k,
68 Value: v,
69 })
70 }
71
72 return entry, nil
73}