Skip to content

Commit

Permalink
fix: PRT - Fix the bug that prevented existing addons to be enabled a…
Browse files Browse the repository at this point in the history
…fter spec update (#1739)

* Fix the bug that prevented existing addons to be enabled after spec update

* Small fix
  • Loading branch information
shleikes authored Oct 13, 2024
1 parent a5e41e5 commit f4cc0bf
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
16 changes: 7 additions & 9 deletions protocol/chainlib/base_chain_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ func (bcp *BaseChainParser) SetPolicyFromAddonAndExtensionMap(policyInformation
bcp.extensionParser.SetConfiguredExtensions(configuredExtensions)
// manage allowed addons
for addon := range bcp.allowedAddons {
if _, ok := policyInformation[addon]; ok {
bcp.allowedAddons[addon] = true
}
_, bcp.allowedAddons[addon] = policyInformation[addon]
}
}

Expand Down Expand Up @@ -231,7 +229,7 @@ func (bcp *BaseChainParser) GetVerifications(supported []string) (retVerificatio

func (bcp *BaseChainParser) Construct(spec spectypes.Spec, internalPaths map[string]struct{}, taggedApis map[spectypes.FUNCTION_TAG]TaggedContainer,
serverApis map[ApiKey]ApiContainer, apiCollections map[CollectionKey]*spectypes.ApiCollection, headers map[ApiKey]*spectypes.Header,
verifications map[VerificationKey][]VerificationContainer, extensionParser extensionslib.ExtensionParser,
verifications map[VerificationKey][]VerificationContainer,
) {
bcp.spec = spec
bcp.internalPaths = internalPaths
Expand All @@ -242,16 +240,16 @@ func (bcp *BaseChainParser) Construct(spec spectypes.Spec, internalPaths map[str
bcp.verifications = verifications
allowedAddons := map[string]bool{}
allowedExtensions := map[string]struct{}{}
for _, apoCollection := range apiCollections {
for _, extension := range apoCollection.Extensions {
for _, apiCollection := range apiCollections {
for _, extension := range apiCollection.Extensions {
allowedExtensions[extension.Name] = struct{}{}
}
allowedAddons[apoCollection.CollectionData.AddOn] = false
// if addon was already existing (happens on spec update), use the existing policy, otherwise set it to false by default
allowedAddons[apiCollection.CollectionData.AddOn] = bcp.allowedAddons[apiCollection.CollectionData.AddOn]
}
bcp.allowedAddons = allowedAddons

bcp.extensionParser = extensionslib.ExtensionParser{AllowedExtensions: allowedExtensions}
bcp.extensionParser.SetConfiguredExtensions(extensionParser.GetConfiguredExtensions())
bcp.extensionParser = extensionslib.NewExtensionParser(allowedExtensions, bcp.extensionParser.GetConfiguredExtensions())
}

func (bcp *BaseChainParser) GetParsingByTag(tag spectypes.FUNCTION_TAG) (parsing *spectypes.ParseDirective, apiCollection *spectypes.ApiCollection, existed bool) {
Expand Down
11 changes: 9 additions & 2 deletions protocol/chainlib/extensionslib/extension_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,17 @@ type ExtensionParserRule interface {
}

type ExtensionParser struct {
AllowedExtensions map[string]struct{}
allowedExtensions map[string]struct{}
configuredExtensions map[ExtensionKey]*spectypes.Extension
}

func NewExtensionParser(allowedExtensions map[string]struct{}, configuredExtensions map[ExtensionKey]*spectypes.Extension) ExtensionParser {
return ExtensionParser{
allowedExtensions: allowedExtensions,
configuredExtensions: configuredExtensions,
}
}

func (ep *ExtensionParser) GetExtension(extension ExtensionKey) *spectypes.Extension {
if extension.Extension == "" {
return nil
Expand All @@ -50,7 +57,7 @@ func (ep *ExtensionParser) AllowedExtension(extension string) bool {
if extension == "" {
return true
}
_, ok := ep.AllowedExtensions[extension]
_, ok := ep.allowedExtensions[extension]
return ok
}

Expand Down
2 changes: 1 addition & 1 deletion protocol/chainlib/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (apip *GrpcChainParser) SetSpec(spec spectypes.Spec) {

// extract server and tagged apis from spec
internalPaths, serverApis, taggedApis, apiCollections, headers, verifications := getServiceApis(spec, spectypes.APIInterfaceGrpc)
apip.BaseChainParser.Construct(spec, internalPaths, taggedApis, serverApis, apiCollections, headers, verifications, apip.BaseChainParser.extensionParser)
apip.BaseChainParser.Construct(spec, internalPaths, taggedApis, serverApis, apiCollections, headers, verifications)
}

// DataReliabilityParams returns data reliability params from spec (spec.enabled and spec.dataReliabilityThreshold)
Expand Down
2 changes: 1 addition & 1 deletion protocol/chainlib/jsonRPC.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func (apip *JsonRPCChainParser) SetSpec(spec spectypes.Spec) {

// extract server and tagged apis from spec
internalPaths, serverApis, taggedApis, apiCollections, headers, verifications := getServiceApis(spec, spectypes.APIInterfaceJsonRPC)
apip.BaseChainParser.Construct(spec, internalPaths, taggedApis, serverApis, apiCollections, headers, verifications, apip.BaseChainParser.extensionParser)
apip.BaseChainParser.Construct(spec, internalPaths, taggedApis, serverApis, apiCollections, headers, verifications)
}

func (apip *JsonRPCChainParser) GetInternalPaths() map[string]struct{} {
Expand Down
2 changes: 1 addition & 1 deletion protocol/chainlib/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (apip *RestChainParser) SetSpec(spec spectypes.Spec) {

// extract server and tagged apis from spec
internalPaths, serverApis, taggedApis, apiCollections, headers, verifications := getServiceApis(spec, spectypes.APIInterfaceRest)
apip.BaseChainParser.Construct(spec, internalPaths, taggedApis, serverApis, apiCollections, headers, verifications, apip.BaseChainParser.extensionParser)
apip.BaseChainParser.Construct(spec, internalPaths, taggedApis, serverApis, apiCollections, headers, verifications)
}

// DataReliabilityParams returns data reliability params from spec (spec.enabled and spec.dataReliabilityThreshold)
Expand Down
2 changes: 1 addition & 1 deletion protocol/chainlib/tendermintRPC.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (apip *TendermintChainParser) SetSpec(spec spectypes.Spec) {

// extract server and tagged apis from spec
internalPaths, serverApis, taggedApis, apiCollections, headers, verifications := getServiceApis(spec, spectypes.APIInterfaceTendermintRPC)
apip.BaseChainParser.Construct(spec, internalPaths, taggedApis, serverApis, apiCollections, headers, verifications, apip.BaseChainParser.extensionParser)
apip.BaseChainParser.Construct(spec, internalPaths, taggedApis, serverApis, apiCollections, headers, verifications)
}

// DataReliabilityParams returns data reliability params from spec (spec.enabled and spec.dataReliabilityThreshold)
Expand Down

0 comments on commit f4cc0bf

Please sign in to comment.