Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from jeromewir/feat/sdk-upgrade-v4
Browse files Browse the repository at this point in the history
Update plugin SDK from V3 to V4
  • Loading branch information
jeromewir authored Jun 14, 2024
2 parents a0bc06b + fd3ee07 commit a76de8b
Show file tree
Hide file tree
Showing 26 changed files with 623 additions and 136 deletions.
9 changes: 4 additions & 5 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package client

import (
"context"
"encoding/json"
"fmt"
"strings"

"github.com/cloudquery/plugin-pb-go/specs"
"github.com/cloudquery/plugin-sdk/v3/plugins/source"
"github.com/cloudquery/plugin-sdk/v3/schema"
"github.com/hashicorp/go-retryablehttp"
"github.com/plaid/plaid-go/v10/plaid"
"github.com/rs/zerolog"
Expand All @@ -19,6 +17,7 @@ type Client struct {
ClientId string
Secret string
AccessToken string
Spec Spec
}

func (c *Client) ID() string {
Expand All @@ -37,10 +36,10 @@ func (l httpLogger) Printf(format string, v ...interface{}) {
}
}

func New(ctx context.Context, logger zerolog.Logger, s specs.Source, opts source.Options) (schema.ClientMeta, error) {
func New(ctx context.Context, logger zerolog.Logger, s []byte) (*Client, error) {
var pluginSpec Spec

if err := s.UnmarshalSpec(&pluginSpec); err != nil {
if err := json.Unmarshal(s, &pluginSpec); err != nil {
return nil, fmt.Errorf("failed to unmarshal plugin spec: %w", err)
}

Expand Down
2 changes: 1 addition & 1 deletion client/resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

"github.com/cloudquery/plugin-sdk/v3/schema"
"github.com/cloudquery/plugin-sdk/v4/schema"
"github.com/plaid/plaid-go/v10/plaid"
"github.com/thoas/go-funk"
)
Expand Down
101 changes: 59 additions & 42 deletions client/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (
"testing"
"time"

"github.com/cloudquery/plugin-pb-go/specs"
"github.com/cloudquery/plugin-sdk/v3/plugins/source"
"github.com/cloudquery/plugin-sdk/v3/schema"
"github.com/cloudquery/plugin-sdk/v4/plugin"
"github.com/cloudquery/plugin-sdk/v4/scheduler"
"github.com/cloudquery/plugin-sdk/v4/schema"
"github.com/cloudquery/plugin-sdk/v4/transformers"
"github.com/plaid/plaid-go/v10/plaid"
"github.com/rs/zerolog"
)
Expand All @@ -28,49 +29,65 @@ func TestServer(t *testing.T, data any) *httptest.Server {
return ts
}

func remove(s schema.ColumnList, i string) schema.ColumnList {
for j, c := range s {
if c.Name == i {
return append(s[:j], s[j+1:]...)
}
}

return s

}

func TestHelper(t *testing.T, table *schema.Table, ts *httptest.Server) {
version := "vDev"
table.IgnoreInTests = false
t.Helper()
l := zerolog.New(zerolog.NewTestWriter(t)).Output(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.StampMicro}).Level(zerolog.DebugLevel).With().Timestamp().Logger()

newTestExecutionClient := func(ctx context.Context, logger zerolog.Logger, spec specs.Source, opts source.Options) (schema.ClientMeta, error) {
configuration := plaid.NewConfiguration()
configuration.UseEnvironment(plaid.Development)
urlParts := strings.Split(ts.URL, "://")
configuration.Scheme = urlParts[0]
configuration.Host = urlParts[1]
client := plaid.NewAPIClient(configuration)
s := Spec{
ClientId: "test",
Secret: "test",
AccessToken: "test",
}
s.SetDefaults()
err := s.Validate()
if err != nil {
return nil, err
}
return &Client{
Logger: l,
Services: client,
ClientId: s.ClientId,
Secret: s.Secret,
}, nil
l := zerolog.New(zerolog.NewTestWriter(t)).Output(
zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.StampMicro},
).Level(zerolog.DebugLevel).With().Timestamp().Logger()
sched := scheduler.NewScheduler(scheduler.WithLogger(l))

configuration := plaid.NewConfiguration()
configuration.UseEnvironment(plaid.Development)
urlParts := strings.Split(ts.URL, "://")
configuration.Scheme = urlParts[0]
configuration.Host = urlParts[1]
client := plaid.NewAPIClient(configuration)
s := Spec{
ClientId: "test",
Secret: "test",
AccessToken: "test",
}
p := source.NewPlugin(
table.Name,
version,
[]*schema.Table{
table,
},
newTestExecutionClient)
p.SetLogger(l)
source.TestPluginSync(t, p, specs.Source{
Name: "dev",
Path: "cloudquery/dev",
Version: version,
Tables: []string{table.Name},
Destinations: []string{"mock-destination"},
s.SetDefaults()
err := s.Validate()
if err != nil {
t.Fatal(err)
}

c := &Client{
Logger: l,
Services: client,
ClientId: s.ClientId,
Secret: s.Secret,
AccessToken: s.AccessToken,
}

tables := schema.Tables{table}
if err := transformers.TransformTables(tables); err != nil {
t.Fatal(err)
}

// We need to remove additional_properties column from the table as faker cannot generate data with interface{} type
transformers.Apply(tables, func(table *schema.Table) error {
table.Columns = remove(table.Columns, "additional_properties")
return nil
})

messages, err := sched.SyncAll(context.Background(), c, tables)
if err != nil {
t.Fatalf("failed to sync: %v", err)
}
plugin.ValidateNoEmptyColumns(t, tables, messages)
}
6 changes: 3 additions & 3 deletions client/transformers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package client
import (
"reflect"

"github.com/apache/arrow/go/v13/arrow"
"github.com/cloudquery/plugin-sdk/v3/schema"
"github.com/cloudquery/plugin-sdk/v3/transformers"
"github.com/apache/arrow/go/v16/arrow"
"github.com/cloudquery/plugin-sdk/v4/schema"
"github.com/cloudquery/plugin-sdk/v4/transformers"
"github.com/plaid/plaid-go/v10/plaid"
)

Expand Down
139 changes: 108 additions & 31 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,62 +1,139 @@
module github.com/cloudquery/cq-source-plaid

go 1.19
go 1.21.5

toolchain go1.21.11

require (
github.com/apache/arrow/go/v13 v13.0.0-20230509040948-de6c3cd2b604
github.com/cloudquery/plugin-pb-go v1.0.8
github.com/apache/arrow/go/v13 v13.0.0-20230731205701-112f94971882
github.com/cloudquery/plugin-pb-go v1.19.18
github.com/cloudquery/plugin-sdk/v3 v3.6.7
github.com/hashicorp/go-retryablehttp v0.7.2
github.com/hashicorp/go-retryablehttp v0.7.5
github.com/plaid/plaid-go/v10 v10.3.0
github.com/rs/zerolog v1.29.0
github.com/rs/zerolog v1.33.0
github.com/thoas/go-funk v0.9.3
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53
golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc
)

replace github.com/apache/arrow/go/v13 => github.com/cloudquery/arrow/go/v13 v13.0.0-20230526062000-b3fdc24ed8d6

require (
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/apache/thrift v0.16.0 // indirect
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53 // indirect
github.com/CloudyKit/jet/v6 v6.2.0 // indirect
github.com/Joker/jade v1.1.3 // indirect
github.com/Shopify/goreferrer v0.0.0-20220729165902-8cddb4f5de06 // indirect
github.com/adrg/xdg v0.4.0 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/apache/arrow/go/v16 v16.1.0 // indirect
github.com/apache/thrift v0.19.0 // indirect
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/bytedance/sonic v1.10.2 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/cloudquery/cloudquery-api-go v1.11.3 // indirect
github.com/cloudquery/plugin-sdk/v2 v2.7.0 // indirect
github.com/cloudquery/plugin-sdk/v4 v4.44.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/getsentry/sentry-go v0.20.0 // indirect
github.com/deepmap/oapi-codegen v1.15.0 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/flosch/pongo2/v4 v4.0.2 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/getsentry/sentry-go v0.28.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/goccy/go-json v0.9.11 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.9.1 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/flatbuffers v2.0.8+incompatible // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gomarkdown/markdown v0.0.0-20231222211730-1d6d20845b47 // indirect
github.com/google/flatbuffers v24.3.25+incompatible // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware/providers/zerolog/v2 v2.0.0-rc.3 // indirect
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.3 // indirect
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/invopop/jsonschema v0.12.0 // indirect
github.com/iris-contrib/schema v0.0.6 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kataras/blocks v0.0.8 // indirect
github.com/kataras/golog v0.1.11 // indirect
github.com/kataras/iris/v12 v12.2.10 // indirect
github.com/kataras/pio v0.0.13 // indirect
github.com/kataras/sitemap v0.0.6 // indirect
github.com/kataras/tunnel v0.0.4 // indirect
github.com/klauspost/asmfmt v1.3.2 // indirect
github.com/klauspost/compress v1.16.0 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/labstack/echo/v4 v4.11.4 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mailgun/raymond/v2 v2.0.48 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/microcosm-cc/bluemonday v1.0.26 // indirect
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 // indirect
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3 // indirect
github.com/pierrec/lz4/v4 v4.1.15 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 // indirect
github.com/schollz/closestmatch v2.1.0+incompatible // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cobra v1.6.1 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.8.2 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/tdewolff/minify/v2 v2.20.18 // indirect
github.com/tdewolff/parse/v2 v2.7.12 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
github.com/yosssi/ace v0.0.5 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/oauth2 v0.4.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/tools v0.6.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/appengine v1.6.7 // indirect
go.opentelemetry.io/otel v1.27.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0 // indirect
go.opentelemetry.io/otel/metric v1.27.0 // indirect
go.opentelemetry.io/otel/sdk v1.27.0 // indirect
go.opentelemetry.io/otel/trace v1.27.0 // indirect
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/oauth2 v0.20.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.21.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/grpc v1.54.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
google.golang.org/grpc v1.64.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit a76de8b

Please sign in to comment.