Skip to content

Commit e4f49e9

Browse files
authored
feat: Generate full example configs from within SDK (#61)
1 parent e3c3458 commit e4f49e9

26 files changed

+1099
-472
lines changed

clients/destination.go

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ import (
1515
type DestinationClient struct {
1616
pbClient pb.DestinationClient
1717
// this can be used if we have a plugin which is compiled in, so we don't need to do any grpc requests
18-
localClient plugins.DestinationPlugin
18+
localClient *plugins.DestinationPlugin
19+
}
20+
21+
// DestinationExampleConfigOptions can be used to override default example values.
22+
type DestinationExampleConfigOptions struct {
23+
Path string
24+
Registry specs.Registry
1925
}
2026

2127
func NewDestinationClient(cc grpc.ClientConnInterface) *DestinationClient {
@@ -24,7 +30,7 @@ func NewDestinationClient(cc grpc.ClientConnInterface) *DestinationClient {
2430
}
2531
}
2632

27-
func NewLocalDestinationClient(p plugins.DestinationPlugin) *DestinationClient {
33+
func NewLocalDestinationClient(p *plugins.DestinationPlugin) *DestinationClient {
2834
return &DestinationClient{
2935
localClient: p,
3036
}
@@ -52,17 +58,6 @@ func (c *DestinationClient) Version(ctx context.Context) (string, error) {
5258
return res.Version, nil
5359
}
5460

55-
func (c *DestinationClient) GetExampleConfig(ctx context.Context) (string, error) {
56-
if c.localClient != nil {
57-
return c.localClient.ExampleConfig(), nil
58-
}
59-
res, err := c.pbClient.GetExampleConfig(ctx, &pb.GetExampleConfig_Request{})
60-
if err != nil {
61-
return "", err
62-
}
63-
return res.Config, nil
64-
}
65-
6661
func (c *DestinationClient) Initialize(ctx context.Context, spec specs.Destination) error {
6762
if c.localClient != nil {
6863
return c.localClient.Initialize(ctx, spec)
@@ -80,6 +75,23 @@ func (c *DestinationClient) Initialize(ctx context.Context, spec specs.Destinati
8075
return nil
8176
}
8277

78+
func (c *DestinationClient) GetExampleConfig(ctx context.Context, opts DestinationExampleConfigOptions) (string, error) {
79+
if c.localClient != nil {
80+
return c.localClient.ExampleConfig(plugins.DestinationExampleConfigOptions{
81+
Registry: opts.Registry,
82+
Path: opts.Path,
83+
})
84+
}
85+
res, err := c.pbClient.GetExampleConfig(ctx, &pb.GetDestinationExampleConfig_Request{
86+
Registry: opts.Registry.String(),
87+
Path: opts.Path,
88+
})
89+
if err != nil {
90+
return "", err
91+
}
92+
return res.Config, nil
93+
}
94+
8395
func (c *DestinationClient) Migrate(ctx context.Context, tables []*schema.Table) error {
8496
if c.localClient != nil {
8597
return c.localClient.Migrate(ctx, tables)

clients/source.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ type FetchResultMessage struct {
2222
Resource []byte
2323
}
2424

25+
// SourceExampleConfigOptions can be used to override default example values.
26+
type SourceExampleConfigOptions struct {
27+
Path string
28+
Registry specs.Registry
29+
}
30+
2531
func NewSourceClient(cc grpc.ClientConnInterface) *SourceClient {
2632
return &SourceClient{
2733
pbClient: pb.NewSourceClient(cc),
@@ -44,8 +50,11 @@ func (c *SourceClient) Version(ctx context.Context) (string, error) {
4450
return res.Version, nil
4551
}
4652

47-
func (c *SourceClient) ExampleConfig(ctx context.Context) (string, error) {
48-
res, err := c.pbClient.GetExampleConfig(ctx, &pb.GetExampleConfig_Request{})
53+
func (c *SourceClient) ExampleConfig(ctx context.Context, opts SourceExampleConfigOptions) (string, error) {
54+
res, err := c.pbClient.GetExampleConfig(ctx, &pb.GetSourceExampleConfig_Request{
55+
Registry: opts.Registry.String(),
56+
Path: opts.Path,
57+
})
4958
if err != nil {
5059
return "", fmt.Errorf("failed to get example config: %w", err)
5160
}

codegen/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
//codgen helps autogenerate cloudquery plugins configured by definition
1+
// codgen helps autogenerate cloudquery plugins configured by definition
22
package codegen

docs/source_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package docs
22

33
import (
44
"context"
5-
"io/ioutil"
65
"os"
76
"path"
87
"testing"
@@ -100,7 +99,7 @@ func TestGenerateSourcePluginDocs(t *testing.T) {
10099

101100
for _, exp := range expectFiles {
102101
output := path.Join(tmpdir, exp.Name)
103-
got, err := ioutil.ReadFile(output)
102+
got, err := os.ReadFile(output)
104103
if err != nil {
105104
t.Fatalf("error reading %q: %v ", exp.Name, err)
106105
}

0 commit comments

Comments
 (0)