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