Skip to content

Commit b19f337

Browse files
authored
Merge pull request #33 from aep-dev/aep_lib-go
2 parents 8545f6e + b90ef38 commit b19f337

8 files changed

Lines changed: 29 additions & 170 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/hashicorp/terraform-provider-scaffolding
33
go 1.22.7
44

55
require (
6-
github.com/aep-dev/aep-lib-go v0.0.0-20250217200129-e8cdedc0dfd4
6+
github.com/aep-dev/aep-lib-go v0.0.0-20250227061249-02eeb4203b67
77
github.com/google/go-cmp v0.6.0
88
github.com/hashicorp/terraform-plugin-framework v1.13.0
99
github.com/hashicorp/terraform-plugin-go v0.25.0

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc
44
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
55
github.com/ProtonMail/go-crypto v1.1.0-alpha.2 h1:bkyFVUP+ROOARdgCiJzNQo2V2kiB97LyUpzH9P6Hrlg=
66
github.com/ProtonMail/go-crypto v1.1.0-alpha.2/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE=
7-
github.com/aep-dev/aep-lib-go v0.0.0-20250121233519-8bc026ce637e h1:fwCEENQV0LVH/HEkn6Egznu9FzsifNwnIW7qoYvs5jw=
8-
github.com/aep-dev/aep-lib-go v0.0.0-20250121233519-8bc026ce637e/go.mod h1:M+h1D6T2uIUPelmaEsJbjR6JhqKsTlPX3lxp25zQQsk=
9-
github.com/aep-dev/aep-lib-go v0.0.0-20250217200129-e8cdedc0dfd4 h1:+5Me30mM/iyK0A8AGWRL+eF4+eJ8UqD9LbXnLPc3Y0M=
10-
github.com/aep-dev/aep-lib-go v0.0.0-20250217200129-e8cdedc0dfd4/go.mod h1:M+h1D6T2uIUPelmaEsJbjR6JhqKsTlPX3lxp25zQQsk=
7+
github.com/aep-dev/aep-lib-go v0.0.0-20250227013155-1df76ad81681 h1:17h4mgcjtrJcawH942nsHbIJj9utyQrgp8W43wTOYbE=
8+
github.com/aep-dev/aep-lib-go v0.0.0-20250227013155-1df76ad81681/go.mod h1:72nIxfdAGG//z6PMaCIDx5gZMQDm76qoYNCo2Ic6bU0=
9+
github.com/aep-dev/aep-lib-go v0.0.0-20250227061249-02eeb4203b67 h1:2NPewByVzDetGegk1LxaEa3olJLnyy9iEtarc5vXe7k=
10+
github.com/aep-dev/aep-lib-go v0.0.0-20250227061249-02eeb4203b67/go.mod h1:72nIxfdAGG//z6PMaCIDx5gZMQDm76qoYNCo2Ic6bU0=
1111
github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE=
1212
github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
1313
github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec=

internal/provider/client.go

Lines changed: 0 additions & 146 deletions
This file was deleted.

internal/provider/example_resource.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ package provider
66
import (
77
"context"
88
"fmt"
9-
"net/http"
109

1110
"github.com/aep-dev/aep-lib-go/pkg/api"
11+
"github.com/aep-dev/aep-lib-go/pkg/client"
1212
"github.com/hashicorp/terraform-plugin-framework/path"
1313
"github.com/hashicorp/terraform-plugin-framework/resource"
1414
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
@@ -41,7 +41,7 @@ type ExampleResource struct {
4141
name string
4242

4343
// Client will be configured at plan/apply time in the Configure() function.
44-
client *http.Client
44+
client *client.Client
4545
}
4646

4747
func (r *ExampleResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
@@ -68,7 +68,7 @@ func (r *ExampleResource) Configure(ctx context.Context, req resource.ConfigureR
6868
return
6969
}
7070

71-
client, ok := req.ProviderData.(*http.Client)
71+
client, ok := req.ProviderData.(*client.Client)
7272

7373
if !ok {
7474
resp.Diagnostics.AddError(
@@ -104,7 +104,7 @@ func (r *ExampleResource) Create(ctx context.Context, req resource.CreateRequest
104104
return
105105
}
106106

107-
a, err := Create(ctx, r.resource, r.client, r.api.ServerURL, body, parameters)
107+
a, err := r.client.Create(ctx, r.resource, r.api.ServerURL, body, parameters)
108108

109109
if err != nil {
110110
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to create example, got error: %s", err))
@@ -148,7 +148,7 @@ func (r *ExampleResource) Read(ctx context.Context, req resource.ReadRequest, re
148148
return
149149
}
150150

151-
a, err := Read(ctx, r.client, r.api.ServerURL, path)
151+
a, err := r.client.Get(ctx, r.api.ServerURL, path)
152152
if err != nil {
153153
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read example, got error: %s", err))
154154
return
@@ -194,14 +194,14 @@ func (r *ExampleResource) Update(ctx context.Context, req resource.UpdateRequest
194194

195195
}
196196

197-
err = Update(ctx, r.client, r.api.ServerURL, *s.String, body)
197+
err = r.client.Update(ctx, r.api.ServerURL, *s.String, body)
198198

199199
if err != nil {
200200
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to update example, got error: %s", err))
201201
return
202202
}
203203

204-
a, err := Read(ctx, r.client, r.api.ServerURL, *s.String)
204+
a, err := r.client.Get(ctx, r.api.ServerURL, *s.String)
205205
if err != nil {
206206
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read example, got error: %s", err))
207207
return
@@ -240,7 +240,7 @@ func (r *ExampleResource) Delete(ctx context.Context, req resource.DeleteRequest
240240

241241
}
242242

243-
err := Delete(ctx, r.client, r.api.ServerURL, *s.String)
243+
err := r.client.Delete(ctx, r.api.ServerURL, *s.String)
244244
if err != nil {
245245
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to delete example, got error: %s", err))
246246
return

internal/provider/provider.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ package provider
55

66
import (
77
"context"
8-
"net/http"
98

9+
"github.com/aep-dev/aep-lib-go/pkg/client"
1010
"github.com/hashicorp/terraform-plugin-framework/datasource"
1111
"github.com/hashicorp/terraform-plugin-framework/function"
1212
"github.com/hashicorp/terraform-plugin-framework/provider"
@@ -28,7 +28,7 @@ type ScaffoldingProvider struct {
2828
// generator is set to the information created from the OpenAPI spec.
2929
generator *GeneratedProviderData
3030

31-
client *http.Client
31+
client *client.Client
3232

3333
config ProviderConfig
3434
}
@@ -75,7 +75,7 @@ func (p *ScaffoldingProvider) Functions(ctx context.Context) []func() function.F
7575
return []func() function.Function{}
7676
}
7777

78-
func New(version string, g *GeneratedProviderData, client *http.Client, config ProviderConfig) func() provider.Provider {
78+
func New(version string, g *GeneratedProviderData, client *client.Client, config ProviderConfig) func() provider.Provider {
7979
return func() provider.Provider {
8080
return &ScaffoldingProvider{
8181
version: version,

internal/provider/provider_data.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ type GeneratedProviderData struct {
1212
api *api.API
1313
}
1414

15-
func CreateGeneratedProviderData(path string) (*GeneratedProviderData, error) {
15+
func CreateGeneratedProviderData(path string, pathPrefix string) (*GeneratedProviderData, error) {
1616
oas, err := openapi.FetchOpenAPI(path)
1717
if err != nil {
1818
return nil, err
1919
}
2020

21-
a, err := api.GetAPI(oas, "", "")
21+
a, err := api.GetAPI(oas, "", pathPrefix)
2222
if err != nil {
2323
return nil, err
2424
}

internal/provider/provider_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"strings"
1111
"testing"
1212

13+
"github.com/aep-dev/aep-lib-go/pkg/client"
1314
"github.com/hashicorp/terraform-plugin-framework/providerserver"
1415
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
1516
"github.com/jarcoal/httpmock"
@@ -21,11 +22,11 @@ import (
2122
// reattach.
2223
var testAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){
2324
"scaffolding": func() (tfprotov6.ProviderServer, error) {
24-
gen, err := CreateGeneratedProviderData("testdata/oas.yaml")
25+
gen, err := CreateGeneratedProviderData("testdata/oas.yaml", "")
2526
if err != nil {
2627
return nil, fmt.Errorf("unable to create generated data %v", err)
2728
}
28-
mockClient := &http.Client{}
29+
mockClient := client.NewClient(&http.Client{})
2930
providerConfig := ProviderConfig{
3031
OpenAPIPath: "http://localhost:8081/openapi.json",
3132
ProviderPrefix: "scaffolding",

main.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ import (
99
"log"
1010
"net/http"
1111

12+
"github.com/aep-dev/aep-lib-go/pkg/client"
1213
"github.com/hashicorp/terraform-plugin-framework/providerserver"
1314
"github.com/hashicorp/terraform-provider-scaffolding/internal/provider"
1415
)
1516

1617
var (
1718
// these will be set by the goreleaser configuration
1819
// to appropriate values for the compiled binary.
19-
version string = "dev"
20-
path string = "http://localhost:8081/openapi.json"
20+
version string = "dev"
21+
path string = "http://localhost:8081/openapi.json"
22+
pathPrefix string = ""
2123

2224
// goreleaser can pass other information to the main package, such as the specific commit
2325
// https://goreleaser.com/cookbooks/using-main.version/
@@ -37,12 +39,14 @@ func main() {
3739
Debug: debug,
3840
}
3941

40-
gen, err := provider.CreateGeneratedProviderData(path)
42+
gen, err := provider.CreateGeneratedProviderData(path, pathPrefix)
4143
if err != nil {
4244
log.Fatal(err.Error())
4345
}
4446

45-
err = providerserver.Serve(context.Background(), provider.New(version, gen, http.DefaultClient, provider.NewProviderConfig()), opts)
47+
c := client.NewClient(http.DefaultClient)
48+
49+
err = providerserver.Serve(context.Background(), provider.New(version, gen, c, provider.NewProviderConfig()), opts)
4650

4751
if err != nil {
4852
log.Fatal(err.Error())

0 commit comments

Comments
 (0)