-
Notifications
You must be signed in to change notification settings - Fork 226
Extend ack-generate to generate slice with elements of type K8s Secret #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,17 +236,6 @@ func SetSDK( | |
sourceAdaptedVarName += "." + f.Names.Camel | ||
sourceFieldPath := f.Names.Camel | ||
|
||
if r.IsSecretField(memberName) { | ||
out += setSDKForSecret( | ||
cfg, r, | ||
memberName, | ||
targetVarName, | ||
sourceAdaptedVarName, | ||
indentLevel, | ||
) | ||
continue | ||
} | ||
|
||
memberShapeRef, _ := inputShape.MemberRefs[memberName] | ||
memberShape := memberShapeRef.Shape | ||
|
||
|
@@ -339,16 +328,26 @@ func SetSDK( | |
) | ||
} | ||
default: | ||
out += setSDKForScalar( | ||
cfg, r, | ||
memberName, | ||
targetVarName, | ||
inputShape.Type, | ||
sourceFieldPath, | ||
sourceAdaptedVarName, | ||
memberShapeRef, | ||
indentLevel+1, | ||
) | ||
if r.IsSecretField(memberName) { | ||
out += setSDKForSecret( | ||
cfg, r, | ||
memberName, | ||
targetVarName, | ||
sourceAdaptedVarName, | ||
indentLevel, | ||
) | ||
} else { | ||
out += setSDKForScalar( | ||
cfg, r, | ||
memberName, | ||
targetVarName, | ||
inputShape.Type, | ||
sourceFieldPath, | ||
sourceAdaptedVarName, | ||
memberShapeRef, | ||
indentLevel+1, | ||
) | ||
} | ||
} | ||
out += fmt.Sprintf( | ||
"%s}\n", indent, | ||
|
@@ -770,6 +769,25 @@ func setSDKForContainer( | |
indentLevel, | ||
) | ||
default: | ||
if r.IsSecretField(sourceFieldPath) { | ||
indent := strings.Repeat("\t", indentLevel) | ||
// if ko.Spec.MasterUserPassword != nil { | ||
out := fmt.Sprintf( | ||
"%sif %s != nil {\n", | ||
indent, sourceVarName, | ||
) | ||
out += setSDKForSecret( | ||
cfg, r, | ||
"", | ||
targetVarName, | ||
sourceVarName, | ||
indentLevel, | ||
) | ||
// } | ||
out += fmt.Sprintf("%s}\n", indent) | ||
return out | ||
} | ||
|
||
return setSDKForScalar( | ||
cfg, r, | ||
targetFieldName, | ||
|
@@ -789,15 +807,27 @@ func setSDKForContainer( | |
// | ||
// The Go code output from this function looks like this: | ||
// | ||
// if ko.Spec.MasterUserPassword != nil { | ||
// tmpSecret, err := rm.rr.SecretValueFromReference(ctx, ko.Spec.MasterUserPassword) | ||
// if err != nil { | ||
// return nil, err | ||
// } | ||
// if tmpSecret != "" { | ||
// res.SetMasterUserPassword(tmpSecret) | ||
// } | ||
// } | ||
// | ||
// or: | ||
// | ||
// tmpSecret, err := rm.rr.SecretValueFromReference(ctx, f3iter) | ||
// if err != nil { | ||
// return nil, err | ||
// } | ||
// if tmpSecret != "" { | ||
// f3elem = tmpSecret | ||
// } | ||
// | ||
// The second case is used when the SecretKeyReference field | ||
// is a slice of `[]*string` in the original AWS API Input shape. | ||
|
||
func setSDKForSecret( | ||
cfg *ackgenconfig.Config, | ||
r *model.CRD, | ||
|
@@ -809,15 +839,11 @@ func setSDKForSecret( | |
sourceVarName string, | ||
indentLevel int, | ||
) string { | ||
|
||
out := "" | ||
indent := strings.Repeat("\t", indentLevel) | ||
secVar := "tmpSecret" | ||
|
||
// if ko.Spec.MasterUserPassword != nil { | ||
out += fmt.Sprintf( | ||
"%sif %s != nil {\n", | ||
indent, sourceVarName, | ||
) | ||
// tmpSecret, err := rm.rr.SecretValueFromReference(ctx, ko.Spec.MasterUserPassword) | ||
out += fmt.Sprintf( | ||
"%s\t%s, err := rm.rr.SecretValueFromReference(ctx, %s)\n", | ||
|
@@ -833,13 +859,18 @@ func setSDKForSecret( | |
// res.SetMasterUserPassword(tmpSecret) | ||
// } | ||
out += fmt.Sprintf("%s\tif tmpSecret != \"\" {\n", indent) | ||
out += fmt.Sprintf( | ||
"%s\t\t%s.Set%s(%s)\n", | ||
indent, targetVarName, targetFieldName, secVar, | ||
) | ||
if targetFieldName == "" { | ||
out += fmt.Sprintf( | ||
"%s\t\t%s = %s\n", | ||
indent, targetVarName, secVar, | ||
) | ||
} else { | ||
out += fmt.Sprintf( | ||
"%s\t\t%s.Set%s(%s)\n", | ||
indent, targetVarName, targetFieldName, secVar, | ||
) | ||
} | ||
out += fmt.Sprintf("%s\t}\n", indent) | ||
// } | ||
out += fmt.Sprintf("%s}\n", indent) | ||
return out | ||
} | ||
|
||
|
@@ -871,16 +902,7 @@ func setSDKForStruct( | |
cleanMemberName := cleanMemberNames.Camel | ||
sourceAdaptedVarName := sourceVarName + "." + cleanMemberName | ||
memberFieldPath := sourceFieldPath + "." + cleanMemberName | ||
if r.IsSecretField(memberFieldPath) { | ||
out += setSDKForSecret( | ||
cfg, r, | ||
memberName, | ||
targetVarName, | ||
sourceAdaptedVarName, | ||
indentLevel, | ||
) | ||
continue | ||
} | ||
|
||
out += fmt.Sprintf( | ||
"%sif %s != nil {\n", indent, sourceAdaptedVarName, | ||
) | ||
|
@@ -918,16 +940,26 @@ func setSDKForStruct( | |
) | ||
} | ||
default: | ||
out += setSDKForScalar( | ||
cfg, r, | ||
memberName, | ||
targetVarName, | ||
targetShape.Type, | ||
memberFieldPath, | ||
sourceAdaptedVarName, | ||
memberShapeRef, | ||
indentLevel+1, | ||
) | ||
if r.IsSecretField(memberFieldPath) { | ||
out += setSDKForSecret( | ||
cfg, r, | ||
memberName, | ||
targetVarName, | ||
sourceAdaptedVarName, | ||
indentLevel, | ||
) | ||
} else { | ||
out += setSDKForScalar( | ||
cfg, r, | ||
memberName, | ||
targetVarName, | ||
targetShape.Type, | ||
memberFieldPath, | ||
sourceAdaptedVarName, | ||
memberShapeRef, | ||
indentLevel+1, | ||
) | ||
} | ||
} | ||
out += fmt.Sprintf( | ||
"%s}\n", indent, | ||
|
@@ -974,14 +1006,16 @@ func setSDKForSlice( | |
// | ||
// f0elem.SetMyField(*f0iter) | ||
containerFieldName := "" | ||
sourceAttributePath := sourceFieldPath | ||
if targetShape.MemberRef.Shape.Type == "structure" { | ||
containerFieldName = targetFieldName | ||
sourceAttributePath = sourceFieldPath+"." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we have a unit test that can stress this code path? I don't believe the unit test about User.Passwords will hit this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This path is unit tested in |
||
} | ||
out += setSDKForContainer( | ||
cfg, r, | ||
containerFieldName, | ||
elemVarName, | ||
sourceFieldPath+".", | ||
sourceAttributePath, | ||
iterVarName, | ||
&targetShape.MemberRef, | ||
indentLevel+1, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ func cleanGoType( | |
api *SDKAPI, | ||
cfg *ackgenconfig.Config, | ||
shape *awssdkmodel.Shape, | ||
fieldCfg *ackgenconfig.FieldConfig, | ||
) (string, string, string) { | ||
// There are shapes that are called things like DBProxyStatus that are | ||
// fields in a DBProxy CRD... we need to ensure the type names don't | ||
|
@@ -48,20 +49,26 @@ func cleanGoType( | |
} else if shape.Type == "list" { | ||
// If it's a list type, where the element is a structure, we need to | ||
// set the GoType to the cleaned-up Camel-cased name | ||
mgte, mgt, _ := cleanGoType(api, cfg, shape.MemberRef.Shape) | ||
mgte, mgt, mgtwp := cleanGoType(api, cfg, shape.MemberRef.Shape, fieldCfg) | ||
cleanNames := names.New(mgte) | ||
gte = cleanNames.Camel | ||
if api.HasConflictingTypeName(mgte, cfg) { | ||
gte += "_SDK" | ||
} | ||
|
||
gt = "[]" + mgt | ||
gtwp = "[]" + mgtwp | ||
} else if shape.Type == "timestamp" { | ||
// time.Time needs to be converted to apimachinery/metav1.Time | ||
// otherwise there is no DeepCopy support | ||
gtwp = "*metav1.Time" | ||
gte = "metav1.Time" | ||
gt = "*metav1.Time" | ||
} else if fieldCfg != nil && fieldCfg.IsSecret { | ||
gt = "*ackv1alpha1.SecretKeyReference" | ||
gte = "SecretKeyReference" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good fix here. ++ |
||
gtwp = "*ackv1alpha1.SecretKeyReference" | ||
return gte, gt, gtwp | ||
} | ||
|
||
// Replace the type part of the full type-with-package-name with the | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please update the above code comment to say something like this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated code comments.