Skip to content

Commit

Permalink
feature(Partner SDK): Add V2 examples for SourceConnector (#80)
Browse files Browse the repository at this point in the history
* v2_examples folder

* proto changes

* java example change

* setup form change

* configuration form response changes

* python example

* nodejs example changes

* golang examples change

* v1 golang example change

---------

Co-authored-by: Satvik Patil <[email protected]>
  • Loading branch information
fivetran-satvikpatil and Satvik Patil authored Jan 9, 2025
1 parent 09a813c commit 3825371
Show file tree
Hide file tree
Showing 35 changed files with 2,249 additions and 13 deletions.
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@ destination_run/
connector_run/
**/__pycache__/
v1_examples/**/node_modules/
v1_examples/**/package-lock.json
v1_examples/**/package-lock.json
v2_examples/*/**/*.proto
v2_examples/**/*.pb.go
v2_examples/**/*pb2.py
v2_examples/**/*pb2.pyi
v2_examples/**/*pb2_grpc.py
v2_examples/**/node_modules/
v2_examples/**/package-lock.json
23 changes: 11 additions & 12 deletions v1_examples/connector/golang/golang_connector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
pb "fivetran.com/fivetran_sdk/proto"
"google.golang.org/grpc"
_ "google.golang.org/grpc/encoding/gzip"

)

const INFO = "INFO"
Expand Down Expand Up @@ -146,7 +145,7 @@ func (s *server) Update(in *pb.UpdateRequest, stream pb.Connector_UpdateServer)
},
})

LogMessage(SEVERE, "Sample severe message: Update call completed")
LogMessage(SEVERE, "Sample severe message: Update call completed")
// End the RPC call
return nil
}
Expand Down Expand Up @@ -226,10 +225,10 @@ func (s *server) ConfigurationForm(ctx context.Context, in *pb.ConfigurationForm
},
},
{
Name: "isPublic",
Label: "Public?",
Name: "isPublic",
Label: "Public?",
Description: &toggleDescription,
Required: false,
Required: false,
Type: &pb.FormField_ToggleField{
ToggleField: &pb.ToggleField{},
},
Expand Down Expand Up @@ -273,13 +272,13 @@ func (s *server) Test(ctx context.Context, in *pb.TestRequest) (*pb.TestResponse
}

func LogMessage(level string, message string) {
log := map[string]interface{}{
"level": level,
"message": message,
"message-origin": "sdk_connector",
}
logJSON, _ := json.Marshal(log)
fmt.Println(string(logJSON))
log := map[string]interface{}{
"level": level,
"message": message,
"message-origin": "sdk_connector",
}
logJSON, _ := json.Marshal(log)
fmt.Println(string(logJSON))
}

func main() {
Expand Down
166 changes: 166 additions & 0 deletions v2_examples/common_v2.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
syntax = "proto3";
option optimize_for = SPEED;
option java_multiple_files = true;
option go_package = "fivetran.com/fivetran_sdk_v2";
package fivetran_sdk.v2;

import "google/protobuf/timestamp.proto";

message ConfigurationFormRequest {}

message ConfigurationFormResponse {
bool schema_selection_supported = 1;
bool table_selection_supported = 2;
repeated FormField fields = 3;
repeated ConfigurationTest tests = 4;
}

message FormField {
string name = 1;
string label = 2;
optional bool required = 3;
optional string description = 4;
oneof type {
TextField text_field = 5;
DropdownField dropdown_field = 6;
ToggleField toggle_field = 7;
ConditionalFields conditional_fields = 10;
}
optional string default_value = 8;
optional string placeholder = 9;
}

message ConditionalFields {
VisibilityCondition condition = 1;
repeated FormField fields = 2;
}

message VisibilityCondition {
string condition_field = 1;
oneof visible_when {
bool bool_value = 2;
string string_value = 3;
bool empty_value = 4;
}
}

message DropdownField {
repeated string dropdown_field = 1;
}

message ToggleField {}

enum TextField {
PlainText = 0;
Password = 1;
Hidden = 2;
}

message ConfigurationTest {
string name = 1; // unique identifier for the test
string label = 2; // A few words indicating what we are testing, e.g. 'Connecting to database'
}

message TestRequest {
string name = 1;
map<string, string> configuration = 2;
}

message TestResponse {
oneof response {
bool success = 1;
string failure = 2;
}
}

message SchemaList {
repeated Schema schemas = 1;
}

message TableList {
repeated Table tables = 1;
}

message Schema {
string name = 1;
repeated Table tables = 2;
}

enum DataType {
UNSPECIFIED = 0;
BOOLEAN = 1;
SHORT = 2;
INT = 3;
LONG = 4;
DECIMAL = 5;
FLOAT = 6;
DOUBLE = 7;
NAIVE_DATE = 8;
NAIVE_DATETIME = 9;
UTC_DATETIME = 10;
BINARY = 11;
XML = 12;
STRING = 13;
JSON = 14;
NAIVE_TIME = 15;
}

message DataTypeParams {
oneof params {
DecimalParams decimal = 1;
int32 string_byte_length = 2;
}
}

message DecimalParams {
uint32 precision = 1;
uint32 scale = 2;
}

enum RecordType {
UPSERT = 0;
UPDATE = 1;
DELETE = 2;
TRUNCATE = 3;
}

message ValueType {
oneof inner {
bool null = 1;
bool bool = 2;
int32 short = 3;
int32 int = 4;
int64 long = 5;
float float = 6;
double double = 7;
google.protobuf.Timestamp naive_date = 8;
google.protobuf.Timestamp naive_datetime = 9;
google.protobuf.Timestamp utc_datetime = 10;
string decimal = 11;
bytes binary = 12;
string string = 13;
string json = 14;
string xml = 15;
google.protobuf.Timestamp naive_time = 16;
}
}

message Table {
string name = 1;
repeated Column columns = 2;
}

message Column {
string name = 1;
DataType type = 2;
bool primary_key = 3;
optional DataTypeParams params = 4;
}

message Warning {
string message = 1;
}

message Task {
string message = 1;
}
20 changes: 20 additions & 0 deletions v2_examples/connector/golang/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM golang:1.18-alpine

WORKDIR /app

# We want to populate the module cache based on the go.{mod,sum} files.
COPY go.mod .
COPY go.sum .

RUN go mod download

COPY . .

# Build the Go app
RUN go build -o ./out/golang_connector ./golang_connector

# This container exposes port to the outside world
EXPOSE 50051

# Run the binary program produced by `go install`
CMD ["./out/golang_connector"]
11 changes: 11 additions & 0 deletions v2_examples/connector/golang/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# GoLang Connector gRPC Server
Run all commands from the golang folder root

## Steps
```
> cd examples/connector/golang
> scripts/copy_protos.sh
> scripts/compile_protos.sh
> scripts/build.sh
> ./main
```
15 changes: 15 additions & 0 deletions v2_examples/connector/golang/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module fivetran.com/fivetran_sdk

go 1.21

require (
google.golang.org/grpc v1.65.0
google.golang.org/protobuf v1.35.1
)

require (
golang.org/x/net v0.30.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 // indirect
)
14 changes: 14 additions & 0 deletions v2_examples/connector/golang/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 h1:zciRKQ4kBpFgpfC5QQCVtnnNAcLIqweL7plyZRQHVpI=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI=
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
Loading

0 comments on commit 3825371

Please sign in to comment.