...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package dcl
16
17 import (
18 "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/util/pathslice"
19 "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/util/slice"
20 )
21
22 func IsContainerField(path []string) bool {
23 if len(path) > 1 {
24 return false
25 }
26 field := pathslice.Base(path)
27 return field == "organization" || field == "project" || field == "folder"
28 }
29
30
31
32
33 func TrimNilFields(m map[string]interface{}) {
34 for k, v := range m {
35 if IsNil(v) {
36 delete(m, k)
37 continue
38 }
39
40 switch v := v.(type) {
41
42 case map[string]interface{}:
43 TrimNilFields(v)
44
45 case []interface{}:
46 if !slice.IsListOfStringInterfaceMaps(v) {
47
48 continue
49 }
50 for _, e := range v {
51 TrimNilFields(e.(map[string]interface{}))
52 }
53 }
54 }
55 }
56
57
58
59 func IsNil(v interface{}) bool {
60 if v == nil {
61 return true
62 }
63 switch v := v.(type) {
64 case []interface{}:
65 return v == nil
66 case map[string]interface{}:
67 return v == nil
68 }
69 return false
70 }
71
72 func AddToMap(key string, val interface{}, obj map[string]interface{}) {
73 if !IsNil(val) {
74 obj[key] = val
75 }
76 }
77
View as plain text