@@ -51,7 +51,7 @@ import (
51
51
func ResourceIsSynced (
52
52
cfg * ackgenconfig.Config ,
53
53
r * model.CRD ,
54
- // String
54
+ // resource variable name
55
55
resVarName string ,
56
56
// Number of levels of indentation to use
57
57
indentLevel int ,
@@ -62,24 +62,24 @@ func ResourceIsSynced(
62
62
return out
63
63
}
64
64
65
- for _ , condition := range resConfig .Synced .When {
66
- if condition .Path == nil || * condition .Path == "" {
65
+ for _ , condCfg := range resConfig .Synced .When {
66
+ if condCfg .Path == nil || * condCfg .Path == "" {
67
67
panic ("Received an empty sync condition path. 'SyncCondition.Path' must be provided." )
68
68
}
69
- if len (condition .In ) == 0 {
69
+ if len (condCfg .In ) == 0 {
70
70
panic ("'SyncCondition.In' must be provided." )
71
71
}
72
- fp := fieldpath .FromString (* condition .Path )
73
- field , err := getTopLevelField (r , * condition .Path )
72
+ fp := fieldpath .FromString (* condCfg .Path )
73
+ field , err := getTopLevelField (r , * condCfg .Path )
74
74
if err != nil {
75
- msg := fmt .Sprintf ("cannot find top level field of path '%s': %v" , * condition .Path , err )
75
+ msg := fmt .Sprintf ("cannot find top level field of path '%s': %v" , * condCfg .Path , err )
76
76
panic (msg )
77
77
}
78
78
candidatesVarName := fmt .Sprintf ("%sCandidates" , field .Names .CamelLower )
79
79
if fp .Size () == 2 {
80
- out += scalarFieldEqual (resVarName , candidatesVarName , field .ShapeRef .GoTypeElem (), condition )
80
+ out += scalarFieldEqual (resVarName , candidatesVarName , field .ShapeRef .GoTypeElem (), condCfg )
81
81
} else {
82
- out += fieldPathSafeEqual (resVarName , candidatesVarName , field , condition )
82
+ out += fieldPathSafeEqual (resVarName , candidatesVarName , field , condCfg )
83
83
}
84
84
}
85
85
@@ -113,21 +113,26 @@ func getTopLevelField(r *model.CRD, fieldPath string) (*model.Field, error) {
113
113
}
114
114
115
115
// scalarFieldEqual returns Go code that compares a scalar field to a given set of values.
116
- func scalarFieldEqual (resVarName string , candidatesVarName string , goType string , condition ackgenconfig.SyncedCondition ) string {
116
+ func scalarFieldEqual (
117
+ resVarName string ,
118
+ candidatesVarName string ,
119
+ goType string ,
120
+ condCfg ackgenconfig.SyncedCondition ,
121
+ ) string {
117
122
out := ""
118
- fieldPath := fmt .Sprintf ("%s.%s" , resVarName , * condition .Path )
123
+ fieldPath := fmt .Sprintf ("%s.%s" , resVarName , * condCfg .Path )
119
124
120
125
valuesSlice := ""
121
126
switch goType {
122
127
case "string" :
123
128
// []string{"AVAILABLE", "ACTIVE"}
124
- valuesSlice = fmt .Sprintf ("[]string{\" %s\" }" , strings .Join (condition .In , "\" , \" " ))
129
+ valuesSlice = fmt .Sprintf ("[]string{\" %s\" }" , strings .Join (condCfg .In , "\" , \" " ))
125
130
case "int64" , "PositiveLongObject" , "Long" :
126
131
// []int64{1, 2}
127
- valuesSlice = fmt .Sprintf ("[]int{%s}" , strings .Join (condition .In , ", " ))
132
+ valuesSlice = fmt .Sprintf ("[]int{%s}" , strings .Join (condCfg .In , ", " ))
128
133
case "bool" :
129
134
// []bool{false}
130
- valuesSlice = fmt .Sprintf ("[]bool{%s}" , condition .In )
135
+ valuesSlice = fmt .Sprintf ("[]bool{%s}" , condCfg .In )
131
136
default :
132
137
panic ("not supported type " + goType )
133
138
}
@@ -157,11 +162,11 @@ func fieldPathSafeEqual(
157
162
resVarName string ,
158
163
candidatesVarName string ,
159
164
field * model.Field ,
160
- condition ackgenconfig.SyncedCondition ,
165
+ condCfg ackgenconfig.SyncedCondition ,
161
166
) string {
162
167
out := ""
163
- rootPath := fmt .Sprintf ("%s.%s" , resVarName , strings .Split (* condition .Path , "." )[0 ])
164
- knownShapesPath := strings .Join (strings .Split (* condition .Path , "." )[1 :], "." )
168
+ rootPath := fmt .Sprintf ("%s.%s" , resVarName , strings .Split (* condCfg .Path , "." )[0 ])
169
+ knownShapesPath := strings .Join (strings .Split (* condCfg .Path , "." )[1 :], "." )
165
170
166
171
fp := fieldpath .FromString (knownShapesPath )
167
172
shapes := fp .IterShapeRefs (field .ShapeRef )
@@ -171,7 +176,7 @@ func fieldPathSafeEqual(
171
176
if index == len (shapes )- 1 {
172
177
// Some aws-sdk-go scalar shapes don't contain the real name of a shape
173
178
// In this case we use the full path given in condition.Path
174
- subFieldPath = fmt .Sprintf ("%s.%s" , resVarName , * condition .Path )
179
+ subFieldPath = fmt .Sprintf ("%s.%s" , resVarName , * condCfg .Path )
175
180
} else {
176
181
subFieldPath += "." + shape .Shape .ShapeName
177
182
}
@@ -182,13 +187,13 @@ func fieldPathSafeEqual(
182
187
// }
183
188
out += "\t }\n "
184
189
}
185
- out += scalarFieldEqual (resVarName , candidatesVarName , shapes [len (shapes )- 1 ].GoTypeElem (), condition )
190
+ out += scalarFieldEqual (resVarName , candidatesVarName , shapes [len (shapes )- 1 ].GoTypeElem (), condCfg )
186
191
return out
187
192
}
188
193
189
194
func fieldPathContainsMapOrArray (fieldPath string , shapeRef * awssdkmodel.ShapeRef ) bool {
190
- c := fieldpath .FromString (fieldPath )
191
- sr := c .ShapeRef (shapeRef )
195
+ fp := fieldpath .FromString (fieldPath )
196
+ sr := fp .ShapeRef (shapeRef )
192
197
193
198
if sr == nil {
194
199
return false
@@ -197,8 +202,8 @@ func fieldPathContainsMapOrArray(fieldPath string, shapeRef *awssdkmodel.ShapeRe
197
202
return true
198
203
}
199
204
if sr .ShapeName == "structure" {
200
- fieldName := c .PopFront ()
201
- return fieldPathContainsMapOrArray (c .Copy ().At (1 ), sr .Shape .MemberRefs [fieldName ])
205
+ fieldName := fp .PopFront ()
206
+ return fieldPathContainsMapOrArray (fp .Copy ().At (1 ), sr .Shape .MemberRefs [fieldName ])
202
207
}
203
208
return false
204
209
}
0 commit comments