Skip to content

Commit

Permalink
Fix potential use of wrong statements (#3168)
Browse files Browse the repository at this point in the history
  • Loading branch information
theunrepentantgeek authored Jul 28, 2023
1 parent 7b29f8b commit 11f4803
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func newConvertFromARMFunctionBuilder(
result.typeConversionBuilder.AddConversionHandlers(result.convertComplexTypeNameProperty)
result.propertyConversionHandlers = []propertyConversionHandler{
// Handlers for specific properties come first
skipPropertiesFlaggedWithNoARMConversion,
result.namePropertyHandler,
result.ownerPropertyHandler,
result.conditionsPropertyHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func newConvertToARMFunctionBuilder(

result.propertyConversionHandlers = []propertyConversionHandler{
// Handlers for specific properties come first
skipPropertiesFlaggedWithNoARMConversion,
result.namePropertyHandler,
result.operatorSpecPropertyHandler,
result.configMapReferencePropertyHandler,
Expand Down
24 changes: 18 additions & 6 deletions v2/tools/generator/internal/armconversion/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ const (
TypeKindStatus
)

const (
ConversionTag = "conversion"
NoARMConversionValue = "noarmconversion"
)

func (builder conversionBuilder) propertyConversionHandler(
toProp *astmodel.PropertyDefinition,
fromType *astmodel.ObjectType,
Expand All @@ -58,7 +53,7 @@ func (builder conversionBuilder) propertyConversionHandler(
break
}

if conversion.matched || toProp.HasTagValue(ConversionTag, NoARMConversionValue) {
if conversion.matched {
return conversion.statements, nil
}
}
Expand Down Expand Up @@ -241,3 +236,20 @@ func removeEmptyStatements(stmts []dst.Stmt) []dst.Stmt {

return result
}

const (
ConversionTag = "conversion"
NoARMConversionValue = "noarmconversion"
)

func skipPropertiesFlaggedWithNoARMConversion(
toProp *astmodel.PropertyDefinition,
fromType *astmodel.ObjectType,
) (propertyConversionHandlerResult, error) {
// If the property has been flagged as not being convertible, skip it
if toProp.HasTagValue(ConversionTag, NoARMConversionValue) {
return handledWithNoOp, nil
}

return notHandled, nil
}

0 comments on commit 11f4803

Please sign in to comment.