Skip to content

Commit

Permalink
Modified way to ignore S3SHA
Browse files Browse the repository at this point in the history
  • Loading branch information
Vandita2020 committed Sep 28, 2023
1 parent d9bab7e commit 4b27e88
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pkg/generate/ack/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ var (
return code.SetSDK(r.Config(), r, ackmodel.OpTypeDelete, sourceVarName, targetVarName, indentLevel)
},
"GoCodeSetSDKForStruct": func(r *ackmodel.CRD, targetFieldName string, targetVarName string, targetShapeRef *awssdkmodel.ShapeRef, sourceFieldPath string, sourceVarName string, indentLevel int) string {
return code.SetSDKForStruct(r.Config(), r, targetFieldName, targetVarName, targetShapeRef, sourceFieldPath, sourceVarName, indentLevel)
return code.SetSDKForStruct(r.Config(), r, targetFieldName, targetVarName, targetShapeRef, sourceFieldPath, sourceVarName, model.OpTypeList, indentLevel)
},
"GoCodeSetResourceForStruct": func(r *ackmodel.CRD, targetFieldName string, targetVarName string, targetShapeRef *awssdkmodel.ShapeRef, sourceVarName string, sourceShapeRef *awssdkmodel.ShapeRef, indentLevel int) string {
var setCfg *ackgenconfig.SetFieldConfig = nil
Expand Down
51 changes: 40 additions & 11 deletions pkg/generate/code/set_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ func SetSDK(
continue
}

// setCfg := f.GetSetterConfig(opType)
// if setCfg != nil && setCfg.Ignore {
// continue
// }

sourceAdaptedVarName += "." + f.Names.Camel
sourceFieldPath := f.Names.Camel

Expand Down Expand Up @@ -349,6 +354,7 @@ func SetSDK(
sourceFieldPath,
sourceAdaptedVarName,
memberShapeRef,
opType,
indentLevel+1,
)
out += setSDKForScalar(
Expand Down Expand Up @@ -932,6 +938,7 @@ func setSDKForContainer(
sourceVarName string,
// ShapeRef of the target struct field
targetShapeRef *awssdkmodel.ShapeRef,
op model.OpType,
indentLevel int,
) string {
switch targetShapeRef.Shape.Type {
Expand All @@ -943,6 +950,7 @@ func setSDKForContainer(
targetShapeRef,
sourceFieldPath,
sourceVarName,
op,
indentLevel,
)
case "list":
Expand All @@ -953,6 +961,7 @@ func setSDKForContainer(
targetShapeRef,
sourceFieldPath,
sourceVarName,
op,
indentLevel,
)
case "map":
Expand All @@ -963,6 +972,7 @@ func setSDKForContainer(
targetShapeRef,
sourceFieldPath,
sourceVarName,
op,
indentLevel,
)
default:
Expand Down Expand Up @@ -1086,6 +1096,7 @@ func SetSDKForStruct(
sourceFieldPath string,
// The struct or struct field that we access our source value from
sourceVarName string,
op model.OpType,
indentLevel int,
) string {
out := ""
Expand All @@ -1105,22 +1116,35 @@ func SetSDKForStruct(

// To check if the field member has `ignore` set to `true`.
// This condition currently applies only for members of a field whose shape is `structure`
if r.Fields[targetFieldName] != nil {
memberField := r.Fields[targetFieldName].MemberFields[memberName]
if memberField != nil && memberField.FieldConfig != nil && memberField.FieldConfig.Set != nil {
set := memberField.FieldConfig.Set
shouldIgnore := false
for _, value := range set {
if value.Ignore == true {
shouldIgnore = true
}
}
if shouldIgnore {
var setCfg *ackgenconfig.SetFieldConfig
f, ok := r.Fields[targetFieldName]
if ok {
mf, ok := f.MemberFields[memberName]
if ok {
setCfg = mf.GetSetterConfig(op)
if setCfg != nil && setCfg.Ignore {
continue
}
}

}

// if r.Fields[targetFieldName] != nil {
// memberField := r.Fields[targetFieldName].MemberFields[memberName]
// if memberField != nil && memberField.FieldConfig != nil && memberField.FieldConfig.Set != nil {
// set := memberField.FieldConfig.Set
// shouldIgnore := false
// for _, value := range set {
// if value.Ignore == true {
// shouldIgnore = true
// }
// }
// if shouldIgnore {
// continue
// }
// }
// }

out += fmt.Sprintf(
"%sif %s != nil {\n", indent, sourceAdaptedVarName,
)
Expand All @@ -1144,6 +1168,7 @@ func SetSDKForStruct(
memberFieldPath,
sourceAdaptedVarName,
memberShapeRef,
op,
indentLevel+1,
)
out += setSDKForScalar(
Expand Down Expand Up @@ -1201,6 +1226,7 @@ func setSDKForSlice(
sourceFieldPath string,
// The struct or struct field that we access our source value from
sourceVarName string,
op model.OpType,
indentLevel int,
) string {
out := ""
Expand Down Expand Up @@ -1234,6 +1260,7 @@ func setSDKForSlice(
sourceFieldPath,
iterVarName,
&targetShape.MemberRef,
op,
indentLevel+1,
)
addressOfVar := ""
Expand Down Expand Up @@ -1264,6 +1291,7 @@ func setSDKForMap(
sourceFieldPath string,
// The struct or struct field that we access our source value from
sourceVarName string,
op model.OpType,
indentLevel int,
) string {
out := ""
Expand Down Expand Up @@ -1298,6 +1326,7 @@ func setSDKForMap(
sourceFieldPath,
valIterVarName,
&targetShape.ValueRef,
op,
indentLevel+1,
)
addressOfVar := ""
Expand Down
9 changes: 9 additions & 0 deletions pkg/model/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@ func (f *Field) GetSetterConfig(opType OpType) *ackgenconfig.SetFieldConfig {
}
rmMethod := ResourceManagerMethodFromOpType(opType)
for _, setCfg := range f.FieldConfig.Set {
if setCfg == nil {
continue
}
if setCfg.Ignore == true {
return setCfg
}
if setCfg.Ignore == true || setCfg.To == nil {
continue
}
// If the Method attribute is nil, that means the setter config applies to
// all resource manager methods for this field.
if setCfg.Method == nil || strings.EqualFold(rmMethod, *setCfg.Method) {
Expand Down

0 comments on commit 4b27e88

Please sign in to comment.