|
| 1 | +package tfprotov5server |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + "github.com/hashicorp/terraform-plugin-go/tfprotov5" |
| 7 | + "github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/fromproto" |
| 8 | + "github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5" |
| 9 | + "github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/toproto" |
| 10 | +) |
| 11 | + |
| 12 | +type server struct { |
| 13 | + downstream tfprotov5.ProviderServer |
| 14 | +} |
| 15 | + |
| 16 | +func New(serve tfprotov5.ProviderServer) tfplugin5.ProviderServer { |
| 17 | + return server{ |
| 18 | + downstream: serve, |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +func (s server) GetSchema(ctx context.Context, req *tfplugin5.GetProviderSchema_Request) (*tfplugin5.GetProviderSchema_Response, error) { |
| 23 | + r, err := fromproto.GetProviderSchemaRequest(*req) |
| 24 | + if err != nil { |
| 25 | + return nil, err |
| 26 | + } |
| 27 | + resp, err := s.downstream.GetProviderSchema(ctx, &r) |
| 28 | + if err != nil { |
| 29 | + return nil, err |
| 30 | + } |
| 31 | + ret, err := toproto.GetProviderSchema_Response(*resp) |
| 32 | + if err != nil { |
| 33 | + return nil, err |
| 34 | + } |
| 35 | + return &ret, nil |
| 36 | +} |
| 37 | + |
| 38 | +func (s server) PrepareProviderConfig(ctx context.Context, req *tfplugin5.PrepareProviderConfig_Request) (*tfplugin5.PrepareProviderConfig_Response, error) { |
| 39 | + r, err := fromproto.PrepareProviderConfigRequest(*req) |
| 40 | + if err != nil { |
| 41 | + return nil, err |
| 42 | + } |
| 43 | + resp, err := s.downstream.PrepareProviderConfig(ctx, &r) |
| 44 | + if err != nil { |
| 45 | + return nil, err |
| 46 | + } |
| 47 | + ret, err := toproto.PrepareProviderConfig_Response(*resp) |
| 48 | + if err != nil { |
| 49 | + return nil, err |
| 50 | + } |
| 51 | + return &ret, nil |
| 52 | +} |
| 53 | + |
| 54 | +func (s server) Configure(ctx context.Context, req *tfplugin5.Configure_Request) (*tfplugin5.Configure_Response, error) { |
| 55 | + r, err := fromproto.ConfigureProviderRequest(*req) |
| 56 | + if err != nil { |
| 57 | + return nil, err |
| 58 | + } |
| 59 | + resp, err := s.downstream.ConfigureProvider(ctx, &r) |
| 60 | + if err != nil { |
| 61 | + return nil, err |
| 62 | + } |
| 63 | + ret, err := toproto.Configure_Response(*resp) |
| 64 | + if err != nil { |
| 65 | + return nil, err |
| 66 | + } |
| 67 | + return &ret, nil |
| 68 | +} |
| 69 | + |
| 70 | +func (s server) Stop(ctx context.Context, req *tfplugin5.Stop_Request) (*tfplugin5.Stop_Response, error) { |
| 71 | + r, err := fromproto.StopProviderRequest(*req) |
| 72 | + if err != nil { |
| 73 | + return nil, err |
| 74 | + } |
| 75 | + resp, err := s.downstream.StopProvider(ctx, &r) |
| 76 | + if err != nil { |
| 77 | + return nil, err |
| 78 | + } |
| 79 | + ret, err := toproto.Stop_Response(*resp) |
| 80 | + if err != nil { |
| 81 | + return nil, err |
| 82 | + } |
| 83 | + return &ret, nil |
| 84 | +} |
| 85 | + |
| 86 | +func (s server) ValidateDataSourceConfig(ctx context.Context, req *tfplugin5.ValidateDataSourceConfig_Request) (*tfplugin5.ValidateDataSourceConfig_Response, error) { |
| 87 | + r, err := fromproto.ValidateDataSourceConfigRequest(*req) |
| 88 | + if err != nil { |
| 89 | + return nil, err |
| 90 | + } |
| 91 | + resp, err := s.downstream.ValidateDataSourceConfig(ctx, &r) |
| 92 | + if err != nil { |
| 93 | + return nil, err |
| 94 | + } |
| 95 | + ret, err := toproto.ValidateDataSourceConfig_Response(*resp) |
| 96 | + if err != nil { |
| 97 | + return nil, err |
| 98 | + } |
| 99 | + return &ret, nil |
| 100 | +} |
| 101 | + |
| 102 | +func (s server) ReadDataSource(ctx context.Context, req *tfplugin5.ReadDataSource_Request) (*tfplugin5.ReadDataSource_Response, error) { |
| 103 | + r, err := fromproto.ReadDataSourceRequest(*req) |
| 104 | + if err != nil { |
| 105 | + return nil, err |
| 106 | + } |
| 107 | + resp, err := s.downstream.ReadDataSource(ctx, &r) |
| 108 | + if err != nil { |
| 109 | + return nil, err |
| 110 | + } |
| 111 | + ret, err := toproto.ReadDataSource_Response(*resp) |
| 112 | + if err != nil { |
| 113 | + return nil, err |
| 114 | + } |
| 115 | + return &ret, nil |
| 116 | +} |
| 117 | + |
| 118 | +func (s server) ValidateResourceTypeConfig(ctx context.Context, req *tfplugin5.ValidateResourceTypeConfig_Request) (*tfplugin5.ValidateResourceTypeConfig_Response, error) { |
| 119 | + r, err := fromproto.ValidateResourceTypeConfigRequest(*req) |
| 120 | + if err != nil { |
| 121 | + return nil, err |
| 122 | + } |
| 123 | + resp, err := s.downstream.ValidateResourceTypeConfig(ctx, &r) |
| 124 | + if err != nil { |
| 125 | + return nil, err |
| 126 | + } |
| 127 | + ret, err := toproto.ValidateResourceTypeConfig_Response(*resp) |
| 128 | + if err != nil { |
| 129 | + return nil, err |
| 130 | + } |
| 131 | + return &ret, nil |
| 132 | +} |
| 133 | + |
| 134 | +func (s server) UpgradeResourceState(ctx context.Context, req *tfplugin5.UpgradeResourceState_Request) (*tfplugin5.UpgradeResourceState_Response, error) { |
| 135 | + r, err := fromproto.UpgradeResourceStateRequest(*req) |
| 136 | + if err != nil { |
| 137 | + return nil, err |
| 138 | + } |
| 139 | + resp, err := s.downstream.UpgradeResourceState(ctx, &r) |
| 140 | + if err != nil { |
| 141 | + return nil, err |
| 142 | + } |
| 143 | + ret, err := toproto.UpgradeResourceState_Response(*resp) |
| 144 | + if err != nil { |
| 145 | + return nil, err |
| 146 | + } |
| 147 | + return &ret, nil |
| 148 | +} |
| 149 | + |
| 150 | +func (s server) ReadResource(ctx context.Context, req *tfplugin5.ReadResource_Request) (*tfplugin5.ReadResource_Response, error) { |
| 151 | + r, err := fromproto.ReadResourceRequest(*req) |
| 152 | + if err != nil { |
| 153 | + return nil, err |
| 154 | + } |
| 155 | + resp, err := s.downstream.ReadResource(ctx, &r) |
| 156 | + if err != nil { |
| 157 | + return nil, err |
| 158 | + } |
| 159 | + ret, err := toproto.ReadResource_Response(*resp) |
| 160 | + if err != nil { |
| 161 | + return nil, err |
| 162 | + } |
| 163 | + return &ret, nil |
| 164 | +} |
| 165 | + |
| 166 | +func (s server) PlanResourceChange(ctx context.Context, req *tfplugin5.PlanResourceChange_Request) (*tfplugin5.PlanResourceChange_Response, error) { |
| 167 | + r, err := fromproto.PlanResourceChangeRequest(*req) |
| 168 | + if err != nil { |
| 169 | + return nil, err |
| 170 | + } |
| 171 | + resp, err := s.downstream.PlanResourceChange(ctx, &r) |
| 172 | + if err != nil { |
| 173 | + return nil, err |
| 174 | + } |
| 175 | + ret, err := toproto.PlanResourceChange_Response(*resp) |
| 176 | + if err != nil { |
| 177 | + return nil, err |
| 178 | + } |
| 179 | + return &ret, nil |
| 180 | +} |
| 181 | + |
| 182 | +func (s server) ApplyResourceChange(ctx context.Context, req *tfplugin5.ApplyResourceChange_Request) (*tfplugin5.ApplyResourceChange_Response, error) { |
| 183 | + r, err := fromproto.ApplyResourceChangeRequest(*req) |
| 184 | + if err != nil { |
| 185 | + return nil, err |
| 186 | + } |
| 187 | + resp, err := s.downstream.ApplyResourceChange(ctx, &r) |
| 188 | + if err != nil { |
| 189 | + return nil, err |
| 190 | + } |
| 191 | + ret, err := toproto.ApplyResourceChange_Response(*resp) |
| 192 | + if err != nil { |
| 193 | + return nil, err |
| 194 | + } |
| 195 | + return &ret, nil |
| 196 | +} |
| 197 | + |
| 198 | +func (s server) ImportResourceState(ctx context.Context, req *tfplugin5.ImportResourceState_Request) (*tfplugin5.ImportResourceState_Response, error) { |
| 199 | + r, err := fromproto.ImportResourceStateRequest(*req) |
| 200 | + if err != nil { |
| 201 | + return nil, err |
| 202 | + } |
| 203 | + resp, err := s.downstream.ImportResourceState(ctx, &r) |
| 204 | + if err != nil { |
| 205 | + return nil, err |
| 206 | + } |
| 207 | + ret, err := toproto.ImportResourceState_Response(*resp) |
| 208 | + if err != nil { |
| 209 | + return nil, err |
| 210 | + } |
| 211 | + return &ret, nil |
| 212 | +} |
0 commit comments