@@ -661,47 +661,10 @@ func (pgb *standardPlanGraphBuilder) handleRegistry(pbi planbuilderinput.PlanBui
661661 return err
662662 }
663663 pr := primitive .NewLocalPrimitive (
664- //nolint:revive // acceptable for now
665664 func (pc primitive.IPrimitiveCtx ) internaldto.ExecutorOutput {
666665 switch at := strings .ToLower (node .ActionType ); at {
667666 case "pull" :
668- providerVersion := node .ProviderVersion
669- if providerVersion == "" {
670- providerVersion , err = reg .GetLatestPublishedVersion (node .ProviderId )
671- if err != nil {
672- return internaldto .NewErroneousExecutorOutput (err )
673- }
674- }
675-
676- // Get all existing versions from local filesystem
677- localProviders := reg .ListLocallyAvailableProviders ()
678- if providerDesc , exists := localProviders [node .ProviderId ]; exists {
679- // Remove all existing versions
680- for _ , version := range providerDesc .Versions {
681- if err := reg .RemoveProviderVersion (node .ProviderId , version ); err != nil {
682- return internaldto .NewErroneousExecutorOutput (err )
683- }
684- }
685- }
686-
687- // Clear provider cache before pulling new version
688- if err := reg .ClearProviderCache (node .ProviderId ); err != nil {
689- return internaldto .NewErroneousExecutorOutput (err )
690- }
691-
692- // Pull and persist the requested version
693- if err := reg .PullAndPersistProviderArchive (node .ProviderId , providerVersion ); err != nil {
694- return internaldto .NewErroneousExecutorOutput (err )
695- }
696-
697- return util .PrepareResultSet (
698- internaldto .NewPrepareResultSetPlusRawDTO (
699- nil , nil , nil , nil , nil ,
700- internaldto .NewBackendMessages ([]string {fmt .Sprintf (
701- "%s provider, version '%s' successfully installed" ,
702- node .ProviderId , providerVersion )}),
703- nil ,
704- pbi .GetHandlerCtx ().GetTypingConfig ()))
667+ return pgb .handleRegistryPull (reg , node , pbi )
705668 case "list" :
706669 var colz []string
707670 var provz map [string ]anysdk.ProviderDescription
@@ -751,10 +714,56 @@ func (pgb *standardPlanGraphBuilder) handleRegistry(pbi planbuilderinput.PlanBui
751714 },
752715 )
753716 pgb .planGraphHolder .CreatePrimitiveNode (pr )
754-
755717 return nil
756718}
757719
720+ // handleRegistryPull is a helper function that pulls a provider version from the registry and persists it locally.
721+ func (pgb * standardPlanGraphBuilder ) handleRegistryPull (
722+ reg anysdk.RegistryAPI ,
723+ node * sqlparser.Registry ,
724+ pbi planbuilderinput.PlanBuilderInput ,
725+ ) internaldto.ExecutorOutput {
726+ providerVersion := node .ProviderVersion
727+ var err error
728+ if providerVersion == "" {
729+ providerVersion , err = reg .GetLatestPublishedVersion (node .ProviderId )
730+ if err != nil {
731+ return internaldto .NewErroneousExecutorOutput (err )
732+ }
733+ }
734+ // Get all existing versions from local filesystem
735+ localProviders := reg .ListLocallyAvailableProviders ()
736+ // Handle special case for google provider
737+ providerID := node .ProviderId
738+ if providerID == "google" {
739+ providerID = "googleapis.com"
740+ }
741+ if providerDesc , exists := localProviders [providerID ]; exists {
742+ // Remove all existing versions
743+ for _ , version := range providerDesc .Versions {
744+ if err = reg .RemoveProviderVersion (providerID , version ); err != nil {
745+ return internaldto .NewErroneousExecutorOutput (err )
746+ }
747+ }
748+ }
749+ // Clear provider cache before pulling new version
750+ if err = reg .ClearProviderCache (providerID ); err != nil {
751+ return internaldto .NewErroneousExecutorOutput (err )
752+ }
753+ // Pull and persist the requested version
754+ if err = reg .PullAndPersistProviderArchive (node .ProviderId , providerVersion ); err != nil {
755+ return internaldto .NewErroneousExecutorOutput (err )
756+ }
757+ return util .PrepareResultSet (
758+ internaldto .NewPrepareResultSetPlusRawDTO (
759+ nil , nil , nil , nil , nil ,
760+ internaldto .NewBackendMessages ([]string {fmt .Sprintf (
761+ "%s provider, version '%s' successfully installed" ,
762+ node .ProviderId , providerVersion )}),
763+ nil ,
764+ pbi .GetHandlerCtx ().GetTypingConfig ()))
765+ }
766+
758767func (pgb * standardPlanGraphBuilder ) handlePurge (pbi planbuilderinput.PlanBuilderInput ) error {
759768 handlerCtx := pbi .GetHandlerCtx ()
760769 node , ok := pbi .GetPurge ()
0 commit comments