Skip to content

Commit

Permalink
feat: add support for GCP Storage connector (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
reugn authored Sep 14, 2024
1 parent 825f6a3 commit d2f45f1
Show file tree
Hide file tree
Showing 10 changed files with 656 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Supported Connectors:
* [Apache Kafka](https://kafka.apache.org/)
* [Apache Pulsar](https://pulsar.apache.org/)
* AWS ([S3](https://aws.amazon.com/s3/))
* GCP ([Storage](https://cloud.google.com/storage/))
* [NATS](https://nats.io/)
* [Redis](https://redis.io/)

Expand Down
1 change: 1 addition & 0 deletions examples/gcp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/storage/storage
3 changes: 3 additions & 0 deletions examples/gcp/data/test-bucket/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"data": "test"
}
55 changes: 55 additions & 0 deletions examples/gcp/storage/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package main

import (
"context"
"fmt"
"log"
"time"

"cloud.google.com/go/storage"
"github.com/reugn/go-streams/flow"
connector "github.com/reugn/go-streams/gcp"
"google.golang.org/api/option"
)

// docker run --rm --name fake-gcs-server -p 4443:4443 -v ${PWD}/data:/data \
// fsouza/fake-gcs-server -scheme http

// curl http://0.0.0.0:4443/storage/v1/b
// curl http://0.0.0.0:4443/storage/v1/b/test-bucket/o
func main() {
ctx := context.Background()
client, err := storage.NewClient(
ctx,
option.WithEndpoint("http://localhost:4443/storage/v1/"),
option.WithoutAuthentication(),
storage.WithJSONReads(),
)
if err != nil {
log.Fatal(err)
}

sourceConfig := &connector.StorageSourceConfig{
Bucket: "test-bucket",
// Prefix: "source",
}
source := connector.NewStorageSource(ctx, client, sourceConfig, nil)

mapObjects := flow.NewMap(transform, 1)

sinkConfig := &connector.StorageSinkConfig{
Bucket: "test-bucket",
}
sink := connector.NewStorageSink(ctx, client, sinkConfig, nil)

source.
Via(mapObjects).
To(sink)

time.Sleep(time.Second)
}

var transform = func(object *connector.StorageObject) *connector.StorageObject {
object.Key = fmt.Sprintf("sink/%s", object.Key)
return object
}
25 changes: 25 additions & 0 deletions examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/reugn/go-streams/examples
go 1.21.0

require (
cloud.google.com/go/storage v1.43.0
github.com/IBM/sarama v1.43.3
github.com/aerospike/aerospike-client-go/v7 v7.6.1
github.com/apache/pulsar-client-go v0.13.1
Expand All @@ -16,14 +17,21 @@ require (
github.com/reugn/go-streams v0.10.0
github.com/reugn/go-streams/aerospike v0.0.0
github.com/reugn/go-streams/aws v0.0.0
github.com/reugn/go-streams/gcp v0.0.0
github.com/reugn/go-streams/kafka v0.0.0
github.com/reugn/go-streams/nats v0.0.0
github.com/reugn/go-streams/pulsar v0.0.0
github.com/reugn/go-streams/redis v0.0.0
github.com/reugn/go-streams/websocket v0.0.0
google.golang.org/api v0.188.0
)

require (
cloud.google.com/go v0.115.0 // indirect
cloud.google.com/go/auth v0.7.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect
cloud.google.com/go/compute/metadata v0.4.0 // indirect
cloud.google.com/go/iam v1.1.10 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.2 // indirect
github.com/AthenZ/athenz v1.11.63 // indirect
Expand Down Expand Up @@ -56,15 +64,22 @@ require (
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-jose/go-jose/v4 v4.0.3 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.5 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/hamba/avro/v2 v2.22.2-0.20240625062549-66aad10411d9 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
Expand Down Expand Up @@ -100,6 +115,12 @@ require (
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/yuin/gopher-lua v1.1.1 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/mod v0.20.0 // indirect
Expand All @@ -109,6 +130,9 @@ require (
golang.org/x/sys v0.24.0 // indirect
golang.org/x/term v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/genproto v0.0.0-20240708141625-4ad9e859172b // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
Expand All @@ -126,6 +150,7 @@ require (
replace (
github.com/reugn/go-streams/aerospike => ../aerospike
github.com/reugn/go-streams/aws => ../aws
github.com/reugn/go-streams/gcp => ../gcp
github.com/reugn/go-streams/kafka => ../kafka
github.com/reugn/go-streams/nats => ../nats
github.com/reugn/go-streams/pulsar => ../pulsar
Expand Down
Loading

0 comments on commit d2f45f1

Please sign in to comment.