@@ -3,86 +3,28 @@ package proto6server
33import (
44 "context"
55
6- "github.com/hashicorp/terraform-plugin-framework/diag"
76 "github.com/hashicorp/terraform-plugin-framework/internal/fromproto6"
87 "github.com/hashicorp/terraform-plugin-framework/internal/fwserver"
98 "github.com/hashicorp/terraform-plugin-framework/internal/toproto6"
109 "github.com/hashicorp/terraform-plugin-go/tfprotov6"
1110)
1211
13- type ResourceSchemaNotFoundError struct {
14- TypeName string
15- }
16-
17- func (e * ResourceSchemaNotFoundError ) Error () string {
18- return "resource schema not found for type: " + e .TypeName
19- }
20-
21- func (e * ResourceSchemaNotFoundError ) Is (err error ) bool {
22- compatibleErr , ok := err .(* ResourceSchemaNotFoundError )
23- if ! ok {
24- return false
25- }
26-
27- return e .TypeName == compatibleErr .TypeName
28- }
29-
30- type ResourceIdentitySchemaNotFoundError struct {
31- TypeName string
32- }
33-
34- func (e * ResourceIdentitySchemaNotFoundError ) Error () string {
35- return "resource identity schema not found for type: " + e .TypeName
36- }
37-
38- func (e * ResourceIdentitySchemaNotFoundError ) Is (err error ) bool {
39- compatibleErr , ok := err .(* ResourceIdentitySchemaNotFoundError )
40- if ! ok {
41- return false
42- }
43-
44- return e .TypeName == compatibleErr .TypeName
45- }
46-
47- type ListResourceSchemaNotFoundError struct {
48- TypeName string
49- }
50-
51- func (e * ListResourceSchemaNotFoundError ) Error () string {
52- return "list resource schema not found for type: " + e .TypeName
53- }
12+ func (s * Server ) ListResource (ctx context.Context , proto6Req * tfprotov6.ListResourceRequest ) (* tfprotov6.ListResourceServerStream , error ) {
13+ // proto6Stream := &tfprotov6.ListResourceServerStream{Results: tfprotov6.NoListResults}
14+ proto6Stream := & tfprotov6.ListResourceServerStream {Results : func (func (tfprotov6.ListResourceResult ) bool ) {}}
5415
55- func ( e * ListResourceSchemaNotFoundError ) Is ( err error ) bool {
56- compatibleErr , ok := err .( * ListResourceSchemaNotFoundError )
57- if ! ok {
58- return false
16+ // TODO: extract fromproto6.ListResourceConfig
17+ listResourceSchema , diags := s . FrameworkServer . ListResourceSchema ( ctx , proto6Req . TypeName )
18+ if diags . HasError () {
19+ return proto6Stream , & ListResourceSchemaNotFoundError { TypeName : proto6Req . TypeName }
5920 }
6021
61- return e .TypeName == compatibleErr .TypeName
62- }
63-
64- type ListResourceConfigError struct {
65- TypeName string
66- Diagnostics diag.Diagnostics
67- }
68-
69- func (e * ListResourceConfigError ) Error () string {
70- return "list resource config error for type: " + e .TypeName // + ": " + e.Diagnostics.Error()
71- }
72-
73- func (e * ListResourceConfigError ) Is (err error ) bool {
74- compatibleErr , ok := err .(* ListResourceConfigError )
75- if ! ok {
76- return false
22+ config , diags := fromproto6 .Config (ctx , proto6Req .Config , listResourceSchema )
23+ if diags .HasError () {
24+ return proto6Stream , & ListResourceConfigError {TypeName : proto6Req .TypeName , Diagnostics : diags }
7725 }
7826
79- return e .TypeName != compatibleErr .TypeName
80- }
81-
82- func (s * Server ) ListResource (ctx context.Context , proto6Req * tfprotov6.ListResourceRequest ) (* tfprotov6.ListResourceServerStream , error ) {
83- // proto6Stream := &tfprotov6.ListResourceServerStream{Results: tfprotov6.NoListResults}
84- proto6Stream := & tfprotov6.ListResourceServerStream {Results : func (func (tfprotov6.ListResourceResult ) bool ) {}}
85-
27+ // TODO: extract fromproto6.ListRequest
8628 listResource , err := s .FrameworkServer .ListResourceOrError (ctx , proto6Req .TypeName )
8729 if err != nil {
8830 return proto6Stream , err
@@ -98,16 +40,6 @@ func (s *Server) ListResource(ctx context.Context, proto6Req *tfprotov6.ListReso
9840 return proto6Stream , & ResourceIdentitySchemaNotFoundError {TypeName : proto6Req .TypeName }
9941 }
10042
101- listResourceSchema , diags := s .FrameworkServer .ListResourceSchema (ctx , proto6Req .TypeName )
102- if diags .HasError () {
103- return proto6Stream , & ListResourceSchemaNotFoundError {TypeName : proto6Req .TypeName }
104- }
105-
106- config , diags := fromproto6 .Config (ctx , proto6Req .Config , listResourceSchema )
107- if diags .HasError () {
108- return proto6Stream , & ListResourceConfigError {TypeName : proto6Req .TypeName , Diagnostics : diags }
109- }
110-
11143 req := & fwserver.ListRequest {
11244 Config : * config ,
11345 ListResource : listResource ,
0 commit comments