Skip to content

Commit ddf08da

Browse files
authored
feat!: Upgrade Alicloud plugin to plugin SDK v4 (#12054)
BEGIN_COMMIT_OVERRIDE feat!: Upgrades the alicloud source plugin to use plugin-sdk v4. This version contains no user-facing breaking changes, but because it is now using CloudQuery gRPC protocol v3, it does require use of a destination plugin that also supports protocol v3. All recent destination plugin versions support this. END_COMMIT_OVERRIDE Closes #11931
1 parent 858b9c6 commit ddf08da

34 files changed

+189
-123
lines changed

plugins/source/alicloud/client/client.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
package client
22

33
import (
4-
"context"
5-
"fmt"
64
"strings"
75

8-
"github.com/cloudquery/plugin-pb-go/specs"
9-
"github.com/cloudquery/plugin-sdk/v3/plugins/source"
10-
"github.com/cloudquery/plugin-sdk/v3/schema"
6+
"github.com/cloudquery/plugin-sdk/v4/schema"
117
"github.com/rs/zerolog"
128
)
139

@@ -41,17 +37,8 @@ func (c *Client) WithAccountIDAndRegion(accountID, region string) *Client {
4137
}
4238
}
4339

44-
func New(_ context.Context, logger zerolog.Logger, s specs.Source, _ source.Options) (schema.ClientMeta, error) {
45-
var spec Spec
46-
err := s.UnmarshalSpec(&spec)
47-
if err != nil {
48-
return nil, fmt.Errorf("failed to unmarshal alicloud spec: %w", err)
49-
}
50-
spec.SetDefaults()
51-
if err := spec.Validate(); err != nil {
52-
return nil, err
53-
}
54-
40+
func New(logger zerolog.Logger, spec Spec) (schema.ClientMeta, error) {
41+
var err error
5542
services := make(map[string]map[string]*Services)
5643
for _, account := range spec.Accounts {
5744
for _, region := range account.Regions {

plugins/source/alicloud/client/multiplexers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"sort"
66

7-
"github.com/cloudquery/plugin-sdk/v3/schema"
7+
"github.com/cloudquery/plugin-sdk/v4/schema"
88
)
99

1010
// Extract region from service list

plugins/source/alicloud/client/resolvers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"time"
66

7-
"github.com/cloudquery/plugin-sdk/v3/schema"
7+
"github.com/cloudquery/plugin-sdk/v4/schema"
88
"github.com/thoas/go-funk"
99
)
1010

plugins/source/alicloud/client/spec.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import "fmt"
55
type Spec struct {
66
Accounts []AccountSpec `json:"accounts,omitempty"`
77
BillHistoryMonths int `json:"bill_history_months,omitempty"`
8+
Concurrency int `json:"concurrency,omitempty"`
9+
DeterministicCQID bool `json:"deterministic_cq_id,omitempty"`
810
}
911

1012
type AccountSpec struct {

plugins/source/alicloud/client/testing.go

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,57 @@ package client
22

33
import (
44
"context"
5-
"fmt"
65
"os"
76
"testing"
87
"time"
98

10-
"github.com/cloudquery/plugin-pb-go/specs"
11-
"github.com/cloudquery/plugin-sdk/v3/plugins/source"
12-
"github.com/cloudquery/plugin-sdk/v3/schema"
9+
"github.com/cloudquery/plugin-sdk/v4/scheduler"
10+
"github.com/cloudquery/plugin-sdk/v4/schema"
11+
"github.com/cloudquery/plugin-sdk/v4/transformers"
1312
"github.com/golang/mock/gomock"
1413
"github.com/rs/zerolog"
1514
)
1615

1716
type TestOptions struct{}
1817

1918
func MockTestHelper(t *testing.T, table *schema.Table, builder func(*testing.T, *gomock.Controller) Services, _ TestOptions) {
20-
version := "vDev"
21-
2219
table.IgnoreInTests = false
2320
t.Helper()
2421
ctrl := gomock.NewController(t)
2522
l := zerolog.New(zerolog.NewTestWriter(t)).Output(
2623
zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.StampMicro},
2724
).Level(zerolog.DebugLevel).With().Timestamp().Logger()
28-
29-
newTestExecutionClient := func(ctx context.Context, logger zerolog.Logger, spec specs.Source, _ source.Options) (schema.ClientMeta, error) {
30-
var aliSpec Spec
31-
if err := spec.UnmarshalSpec(&aliSpec); err != nil {
32-
return nil, fmt.Errorf("failed to unmarshal alicloud spec: %w", err)
33-
}
34-
35-
c, err := New(ctx, l, spec, source.Options{})
36-
if err != nil {
37-
return nil, err
38-
}
39-
c.(*Client).updateServices(builder(t, ctrl))
40-
return c, nil
41-
}
42-
43-
p := source.NewPlugin(
44-
table.Name,
45-
version,
46-
[]*schema.Table{
47-
table,
48-
},
49-
newTestExecutionClient)
50-
p.SetLogger(l)
51-
source.TestPluginSync(t, p, specs.Source{
52-
Name: "dev",
53-
Path: "cloudquery/dev",
54-
Version: version,
55-
Tables: []string{table.Name},
56-
Destinations: []string{"mock-destination"},
57-
Spec: Spec{
58-
Accounts: []AccountSpec{
59-
{Name: "test-account", Regions: []string{"cn-hangzhou"}, AccessKey: "test-access-key", SecretKey: "test-secret-key"},
25+
spec := Spec{
26+
Accounts: []AccountSpec{
27+
{
28+
Name: "test-account",
29+
Regions: []string{"cn-hangzhou"},
30+
AccessKey: "test-access-key",
31+
SecretKey: "test-secret-key",
6032
},
6133
},
62-
})
34+
BillHistoryMonths: 0,
35+
Concurrency: 0,
36+
DeterministicCQID: false,
37+
}
38+
schedulerClient, err := New(l, spec)
39+
if err != nil {
40+
t.Fatal(err)
41+
}
42+
schedulerClient.(*Client).updateServices(builder(t, ctrl))
43+
tables := schema.Tables{table}
44+
if err := transformers.TransformTables(tables); err != nil {
45+
t.Fatal(err)
46+
}
47+
sc := scheduler.NewScheduler(scheduler.WithLogger(l))
48+
messages, err := sc.SyncAll(context.Background(), schedulerClient, tables)
49+
if err != nil {
50+
t.Fatal(err)
51+
}
52+
inserts := messages.GetInserts()
53+
records := inserts.GetRecordsForTable(table)
54+
emptyColumns := schema.FindEmptyColumns(table, records)
55+
if len(emptyColumns) > 0 {
56+
t.Fatalf("empty columns: %v", emptyColumns)
57+
}
6358
}

plugins/source/alicloud/go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ require (
77
github.com/aliyun/aliyun-oss-go-sdk v2.2.7+incompatible
88
github.com/apache/arrow/go/v13 v13.0.0-20230630125530-5a06b2ec2a8e
99
github.com/cloudquery/codegen v0.2.1
10-
github.com/cloudquery/plugin-pb-go v1.6.0
11-
github.com/cloudquery/plugin-sdk/v3 v3.10.6
10+
github.com/cloudquery/plugin-sdk/v4 v4.8.1-rc1
1211
github.com/golang/mock v1.5.0
1312
github.com/pkg/errors v0.9.1
1413
github.com/rs/zerolog v1.29.1
@@ -18,6 +17,7 @@ require (
1817
replace github.com/apache/arrow/go/v13 => github.com/cloudquery/arrow/go/v13 v13.0.0-20230703001435-df3b664a289d
1918

2019
require (
20+
github.com/cloudquery/plugin-pb-go v1.6.0 // indirect
2121
github.com/cloudquery/plugin-sdk v1.45.0 // indirect
2222
github.com/cloudquery/plugin-sdk/v2 v2.7.0 // indirect
2323
github.com/davecgh/go-spew v1.1.1 // indirect
@@ -32,16 +32,16 @@ require (
3232
github.com/inconshreveable/mousetrap v1.1.0 // indirect
3333
github.com/jmespath/go-jmespath v0.4.0 // indirect
3434
github.com/json-iterator/go v1.1.12 // indirect
35-
github.com/klauspost/compress v1.16.0 // indirect
35+
github.com/klauspost/compress v1.16.6 // indirect
3636
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
37+
github.com/kr/pretty v0.3.0 // indirect
3738
github.com/mattn/go-colorable v0.1.13 // indirect
3839
github.com/mattn/go-isatty v0.0.19 // indirect
3940
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4041
github.com/modern-go/reflect2 v1.0.2 // indirect
4142
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
4243
github.com/pierrec/lz4/v4 v4.1.17 // indirect
4344
github.com/pmezard/go-difflib v1.0.0 // indirect
44-
github.com/spf13/cast v1.5.0 // indirect
4545
github.com/spf13/cobra v1.6.1 // indirect
4646
github.com/spf13/pflag v1.0.5 // indirect
4747
github.com/stretchr/testify v1.8.4 // indirect

plugins/source/alicloud/go.sum

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ github.com/cloudquery/plugin-sdk v1.45.0 h1:5vrfQZtaO1dp6ebKt8ouXDmPC7eeLuOB3JMd
5353
github.com/cloudquery/plugin-sdk v1.45.0/go.mod h1:9KGuuTGjTCKgh9amKwS+7Zrrqq7/M6lormteOyqoKwg=
5454
github.com/cloudquery/plugin-sdk/v2 v2.7.0 h1:hRXsdEiaOxJtsn/wZMFQC9/jPfU1MeMK3KF+gPGqm7U=
5555
github.com/cloudquery/plugin-sdk/v2 v2.7.0/go.mod h1:pAX6ojIW99b/Vg4CkhnsGkRIzNaVEceYMR+Bdit73ug=
56-
github.com/cloudquery/plugin-sdk/v3 v3.10.6 h1:KqTsLZ6OA1h8BUMeMcU6BAD6TBW6ojgQaC4zDZMgvu0=
57-
github.com/cloudquery/plugin-sdk/v3 v3.10.6/go.mod h1:QhBaVgiNyQ3P6uAzJWOYpYykHXL+WDZffwg1riTwv60=
56+
github.com/cloudquery/plugin-sdk/v4 v4.8.1-rc1 h1:23MfOXbCXzoHuXbEGPTomneiPWAAucq8M+BaAaSi/6Q=
57+
github.com/cloudquery/plugin-sdk/v4 v4.8.1-rc1/go.mod h1:Y5HzxesZrpmSTUrbvR8EmGCK5wXDAhqSqzNEXC2ouvI=
5858
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
5959
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
6060
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
6161
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
6262
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
63+
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
6364
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6465
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
6566
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -68,7 +69,6 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m
6869
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
6970
github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
7071
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
71-
github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
7272
github.com/getsentry/sentry-go v0.20.0 h1:bwXW98iMRIWxn+4FgPW7vMrjmbym6HblXALmhjHmQaQ=
7373
github.com/getsentry/sentry-go v0.20.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY=
7474
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
@@ -164,15 +164,17 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1
164164
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
165165
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
166166
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
167-
github.com/klauspost/compress v1.16.0 h1:iULayQNOReoYUe+1qtKOqw9CwJv3aNQu8ivo7lw1HU4=
168-
github.com/klauspost/compress v1.16.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
167+
github.com/klauspost/compress v1.16.6 h1:91SKEy4K37vkp255cJ8QesJhjyRO0hn9i9G0GoUwLsk=
168+
github.com/klauspost/compress v1.16.6/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
169169
github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg=
170170
github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
171171
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
172172
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
173+
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
173174
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
174175
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
175176
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
177+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
176178
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
177179
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
178180
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
@@ -199,15 +201,14 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
199201
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
200202
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
201203
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
204+
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
202205
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
203206
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
204207
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
205208
github.com/rs/zerolog v1.19.0/go.mod h1:IzD0RJ65iWH0w97OQQebJEvTZYvsCUm9WVLWBQrJRjo=
206209
github.com/rs/zerolog v1.29.1 h1:cO+d60CHkknCbvzEWxP0S9K6KqyTjrCNUy1LdQLCGPc=
207210
github.com/rs/zerolog v1.29.1/go.mod h1:Le6ESbR7hc+DP6Lt1THiV8CQSdkkNrd3R0XbEgp3ZBU=
208211
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
209-
github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w=
210-
github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU=
211212
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
212213
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
213214
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=

plugins/source/alicloud/main.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
package main
22

33
import (
4+
"context"
5+
"log"
6+
47
"github.com/cloudquery/cloudquery/plugins/source/alicloud/resources/plugin"
5-
"github.com/cloudquery/plugin-sdk/v3/serve"
8+
"github.com/cloudquery/plugin-sdk/v4/serve"
69
)
710

811
const sentryDSN = "https://[email protected]/4504530915557376"
912

1013
func main() {
11-
serve.Source(plugin.Plugin(), serve.WithSourceSentryDSN(sentryDSN))
14+
p := serve.Plugin(plugin.Plugin(), serve.WithPluginSentryDSN(sentryDSN))
15+
err := p.Serve(context.Background())
16+
if err != nil {
17+
log.Fatalf("failed to serve plugin: %v", err)
18+
}
1219
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package plugin
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
8+
"github.com/cloudquery/cloudquery/plugins/source/alicloud/client"
9+
"github.com/cloudquery/cloudquery/plugins/source/alicloud/resources/services/bss"
10+
"github.com/cloudquery/cloudquery/plugins/source/alicloud/resources/services/ecs"
11+
"github.com/cloudquery/cloudquery/plugins/source/alicloud/resources/services/oss"
12+
"github.com/cloudquery/plugin-sdk/v4/message"
13+
"github.com/cloudquery/plugin-sdk/v4/plugin"
14+
"github.com/cloudquery/plugin-sdk/v4/scheduler"
15+
"github.com/cloudquery/plugin-sdk/v4/schema"
16+
"github.com/cloudquery/plugin-sdk/v4/transformers"
17+
"github.com/rs/zerolog"
18+
)
19+
20+
type Client struct {
21+
logger zerolog.Logger
22+
config client.Spec
23+
tables schema.Tables
24+
scheduler *scheduler.Scheduler
25+
plugin.UnimplementedDestination
26+
}
27+
28+
func (c *Client) Logger() *zerolog.Logger {
29+
return &c.logger
30+
}
31+
32+
func (c *Client) Sync(ctx context.Context, options plugin.SyncOptions, res chan<- message.SyncMessage) error {
33+
tt, err := c.tables.FilterDfs(options.Tables, options.SkipTables, options.SkipDependentTables)
34+
if err != nil {
35+
return err
36+
}
37+
38+
schedulerClient, err := client.New(c.logger, c.config)
39+
if err != nil {
40+
return err
41+
}
42+
43+
return c.scheduler.Sync(ctx, schedulerClient, tt, res, scheduler.WithSyncDeterministicCQID(options.DeterministicCQID))
44+
}
45+
46+
func (c *Client) Tables(ctx context.Context, options plugin.TableOptions) (schema.Tables, error) {
47+
return c.tables.FilterDfs(options.Tables, options.SkipTables, options.SkipDependentTables)
48+
}
49+
50+
func (*Client) Close(ctx context.Context) error {
51+
return nil
52+
}
53+
func getTables() []*schema.Table {
54+
tables := []*schema.Table{
55+
bss.BillOverview(),
56+
bss.Bill(),
57+
bss.BillDetails(),
58+
ecs.Instances(),
59+
oss.Buckets(),
60+
}
61+
err := transformers.TransformTables(tables)
62+
if err != nil {
63+
panic(err)
64+
}
65+
for i := range tables {
66+
schema.AddCqIDs(tables[i])
67+
}
68+
return tables
69+
}
70+
71+
func Configure(ctx context.Context, logger zerolog.Logger, spec []byte, options plugin.NewClientOptions) (plugin.Client, error) {
72+
if options.NoConnection {
73+
return &Client{
74+
logger: logger,
75+
tables: getTables(),
76+
}, nil
77+
}
78+
79+
config := client.Spec{}
80+
if err := json.Unmarshal(spec, &config); err != nil {
81+
return nil, fmt.Errorf("failed to unmarshal spec: %w", err)
82+
}
83+
config.SetDefaults()
84+
err := config.Validate()
85+
if err != nil {
86+
return nil, fmt.Errorf("failed to validate spec: %w", err)
87+
}
88+
sc := scheduler.NewScheduler(
89+
scheduler.WithLogger(logger),
90+
scheduler.WithConcurrency(config.Concurrency),
91+
)
92+
return &Client{
93+
logger: logger,
94+
config: config,
95+
tables: getTables(),
96+
scheduler: sc,
97+
UnimplementedDestination: plugin.UnimplementedDestination{},
98+
}, nil
99+
}

0 commit comments

Comments
 (0)