|
| 1 | +package provider |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + "github.com/hashicorp/terraform-plugin-go/tfprotov6" |
| 7 | + "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" |
| 8 | +) |
| 9 | + |
| 10 | +func NewWrappedProviderServer(old func() tfprotov6.ProviderServer) func() tfprotov6.ProviderServer { |
| 11 | + return func() tfprotov6.ProviderServer { |
| 12 | + return &WrappedProviderServer{ |
| 13 | + OldServer: old(), |
| 14 | + } |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +type WrappedProviderServer struct { |
| 19 | + OldServer tfprotov6.ProviderServer |
| 20 | +} |
| 21 | + |
| 22 | +func (s *WrappedProviderServer) GetMetadata(ctx context.Context, req *tfprotov6.GetMetadataRequest) (*tfprotov6.GetMetadataResponse, error) { |
| 23 | + return s.OldServer.GetMetadata(ctx, req) |
| 24 | +} |
| 25 | + |
| 26 | +func (s *WrappedProviderServer) GetProviderSchema(ctx context.Context, req *tfprotov6.GetProviderSchemaRequest) (*tfprotov6.GetProviderSchemaResponse, error) { |
| 27 | + return s.OldServer.GetProviderSchema(ctx, req) |
| 28 | +} |
| 29 | + |
| 30 | +func (s *WrappedProviderServer) GetResourceIdentitySchemas(ctx context.Context, req *tfprotov6.GetResourceIdentitySchemasRequest) (*tfprotov6.GetResourceIdentitySchemasResponse, error) { |
| 31 | + return s.OldServer.GetResourceIdentitySchemas(ctx, req) |
| 32 | +} |
| 33 | + |
| 34 | +func (s *WrappedProviderServer) ValidateProviderConfig(ctx context.Context, req *tfprotov6.ValidateProviderConfigRequest) (*tfprotov6.ValidateProviderConfigResponse, error) { |
| 35 | + return s.OldServer.ValidateProviderConfig(ctx, req) |
| 36 | +} |
| 37 | + |
| 38 | +func (s *WrappedProviderServer) ConfigureProvider(ctx context.Context, req *tfprotov6.ConfigureProviderRequest) (*tfprotov6.ConfigureProviderResponse, error) { |
| 39 | + return s.OldServer.ConfigureProvider(ctx, req) |
| 40 | +} |
| 41 | + |
| 42 | +func (s *WrappedProviderServer) StopProvider(ctx context.Context, req *tfprotov6.StopProviderRequest) (*tfprotov6.StopProviderResponse, error) { |
| 43 | + return s.OldServer.StopProvider(ctx, req) |
| 44 | +} |
| 45 | + |
| 46 | +func (s *WrappedProviderServer) ValidateResourceConfig(ctx context.Context, req *tfprotov6.ValidateResourceConfigRequest) (*tfprotov6.ValidateResourceConfigResponse, error) { |
| 47 | + ctx = context.WithValue(ctx, config.ContextKeyTFSrc, req.TypeName) |
| 48 | + return s.OldServer.ValidateResourceConfig(ctx, req) |
| 49 | +} |
| 50 | + |
| 51 | +func (s *WrappedProviderServer) UpgradeResourceState(ctx context.Context, req *tfprotov6.UpgradeResourceStateRequest) (*tfprotov6.UpgradeResourceStateResponse, error) { |
| 52 | + ctx = context.WithValue(ctx, config.ContextKeyTFSrc, "upgrade."+req.TypeName) |
| 53 | + return s.OldServer.UpgradeResourceState(ctx, req) |
| 54 | +} |
| 55 | + |
| 56 | +func (s *WrappedProviderServer) ReadResource(ctx context.Context, req *tfprotov6.ReadResourceRequest) (*tfprotov6.ReadResourceResponse, error) { |
| 57 | + ctx = context.WithValue(ctx, config.ContextKeyTFSrc, req.TypeName) |
| 58 | + return s.OldServer.ReadResource(ctx, req) |
| 59 | +} |
| 60 | + |
| 61 | +func (s *WrappedProviderServer) PlanResourceChange(ctx context.Context, req *tfprotov6.PlanResourceChangeRequest) (*tfprotov6.PlanResourceChangeResponse, error) { |
| 62 | + ctx = context.WithValue(ctx, config.ContextKeyTFSrc, req.TypeName) |
| 63 | + return s.OldServer.PlanResourceChange(ctx, req) |
| 64 | +} |
| 65 | + |
| 66 | +func (s *WrappedProviderServer) ApplyResourceChange(ctx context.Context, req *tfprotov6.ApplyResourceChangeRequest) (*tfprotov6.ApplyResourceChangeResponse, error) { |
| 67 | + ctx = context.WithValue(ctx, config.ContextKeyTFSrc, req.TypeName) |
| 68 | + return s.OldServer.ApplyResourceChange(ctx, req) |
| 69 | +} |
| 70 | + |
| 71 | +func (s *WrappedProviderServer) ImportResourceState(ctx context.Context, req *tfprotov6.ImportResourceStateRequest) (*tfprotov6.ImportResourceStateResponse, error) { |
| 72 | + ctx = context.WithValue(ctx, config.ContextKeyTFSrc, "import."+req.TypeName) |
| 73 | + return s.OldServer.ImportResourceState(ctx, req) |
| 74 | +} |
| 75 | + |
| 76 | +func (s *WrappedProviderServer) MoveResourceState(ctx context.Context, req *tfprotov6.MoveResourceStateRequest) (*tfprotov6.MoveResourceStateResponse, error) { |
| 77 | + ctx = context.WithValue(ctx, config.ContextKeyTFSrc, "move."+req.TargetTypeName) |
| 78 | + return s.OldServer.MoveResourceState(ctx, req) |
| 79 | +} |
| 80 | + |
| 81 | +func (s *WrappedProviderServer) UpgradeResourceIdentity(ctx context.Context, req *tfprotov6.UpgradeResourceIdentityRequest) (*tfprotov6.UpgradeResourceIdentityResponse, error) { |
| 82 | + ctx = context.WithValue(ctx, config.ContextKeyTFSrc, req.TypeName) |
| 83 | + return s.OldServer.UpgradeResourceIdentity(ctx, req) |
| 84 | +} |
| 85 | + |
| 86 | +func (s *WrappedProviderServer) ValidateDataResourceConfig(ctx context.Context, req *tfprotov6.ValidateDataResourceConfigRequest) (*tfprotov6.ValidateDataResourceConfigResponse, error) { |
| 87 | + ctx = context.WithValue(ctx, config.ContextKeyTFSrc, "data."+req.TypeName) |
| 88 | + return s.OldServer.ValidateDataResourceConfig(ctx, req) |
| 89 | +} |
| 90 | + |
| 91 | +func (s *WrappedProviderServer) ReadDataSource(ctx context.Context, req *tfprotov6.ReadDataSourceRequest) (*tfprotov6.ReadDataSourceResponse, error) { |
| 92 | + ctx = context.WithValue(ctx, config.ContextKeyTFSrc, "data."+req.TypeName) |
| 93 | + return s.OldServer.ReadDataSource(ctx, req) |
| 94 | +} |
| 95 | + |
| 96 | +func (s *WrappedProviderServer) CallFunction(ctx context.Context, req *tfprotov6.CallFunctionRequest) (*tfprotov6.CallFunctionResponse, error) { |
| 97 | + ctx = context.WithValue(ctx, config.ContextKeyTFSrc, "func."+req.Name) |
| 98 | + return s.OldServer.CallFunction(ctx, req) |
| 99 | +} |
| 100 | + |
| 101 | +func (s *WrappedProviderServer) GetFunctions(ctx context.Context, req *tfprotov6.GetFunctionsRequest) (*tfprotov6.GetFunctionsResponse, error) { |
| 102 | + return s.OldServer.GetFunctions(ctx, req) |
| 103 | +} |
| 104 | + |
| 105 | +func (s *WrappedProviderServer) ValidateEphemeralResourceConfig(ctx context.Context, req *tfprotov6.ValidateEphemeralResourceConfigRequest) (*tfprotov6.ValidateEphemeralResourceConfigResponse, error) { |
| 106 | + ctx = context.WithValue(ctx, config.ContextKeyTFSrc, req.TypeName) |
| 107 | + return s.OldServer.ValidateEphemeralResourceConfig(ctx, req) |
| 108 | +} |
| 109 | + |
| 110 | +func (s *WrappedProviderServer) OpenEphemeralResource(ctx context.Context, req *tfprotov6.OpenEphemeralResourceRequest) (*tfprotov6.OpenEphemeralResourceResponse, error) { |
| 111 | + ctx = context.WithValue(ctx, config.ContextKeyTFSrc, req.TypeName) |
| 112 | + return s.OldServer.OpenEphemeralResource(ctx, req) |
| 113 | +} |
| 114 | + |
| 115 | +func (s *WrappedProviderServer) RenewEphemeralResource(ctx context.Context, req *tfprotov6.RenewEphemeralResourceRequest) (*tfprotov6.RenewEphemeralResourceResponse, error) { |
| 116 | + ctx = context.WithValue(ctx, config.ContextKeyTFSrc, req.TypeName) |
| 117 | + return s.OldServer.RenewEphemeralResource(ctx, req) |
| 118 | +} |
| 119 | + |
| 120 | +func (s *WrappedProviderServer) CloseEphemeralResource(ctx context.Context, req *tfprotov6.CloseEphemeralResourceRequest) (*tfprotov6.CloseEphemeralResourceResponse, error) { |
| 121 | + ctx = context.WithValue(ctx, config.ContextKeyTFSrc, req.TypeName) |
| 122 | + return s.OldServer.CloseEphemeralResource(ctx, req) |
| 123 | +} |
0 commit comments