Skip to content

Commit

Permalink
chore: use latest connect-go library
Browse files Browse the repository at this point in the history
  • Loading branch information
fedragon committed Dec 6, 2024
1 parent 8c4691f commit 5c42bb2
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 59 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.PHONY: install-protoc-gen
install-protoc-gen:
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install connectrpc.com/connect/cmd/protoc-gen-connect-go@latest

.PHONY: generate
generate:
rm -rf gen
Expand All @@ -22,4 +27,4 @@ build-server-nas:

.PHONY: test
test:
go test -race -count=1 ./...
go test -race -count=1 ./...
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ There are of course plenty of applications on the market that can manage an arch
- I'm going to consider a file to be the duplicate of another one if and only if hashing them yields the same result: no other attributes (e.g. file name, creation date, ...) are taken into account
- I'm going to compute file hashes using the [go porting](https://github.com/lukechampine/blake3) of the BLAKE3 cryptographic hash function, because of its performance
- Server and client will communicate over gRPC: this enables them to run on different machines and to leverage HTTP/2 to stream files over the network
- Instead of vanilla gRPC, I'm going to use the [connect-go](https://github.com/bufbuild/connect-go) library, primarily to experiment with it
- Instead of vanilla gRPC, I'm going to use the [connect-go](https://connectrpc.com/connect) library, primarily to experiment with it
- Clients will authenticate their requests using JWT tokens, leveraging connect-go's [interceptors](https://connect.build/docs/go/interceptors)
- I'm going to report some key metrics to [Prometheus](https://prometheus.io/docs/introduction/overview/) to measure the system's performance
- I'm going to store file metadata (e.g. path, hash, ...) in a [Redis](https://redis.io/) database
Expand Down
11 changes: 4 additions & 7 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
version: v1

managed:
enabled: true
version: v2
plugins:
- plugin: buf.build/protocolbuffers/go
- local: protoc-gen-go
out: gen
opt: paths=source_relative
- plugin: buf.build/bufbuild/connect-go
- local: protoc-gen-connect-go
out: gen
opt: paths=source_relative
opt: paths=source_relative
3 changes: 0 additions & 3 deletions buf.work.yaml

This file was deleted.

4 changes: 3 additions & 1 deletion buf.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
version: v1
version: v2
modules:
- path: api
breaking:
use:
- FILE
Expand Down
2 changes: 1 addition & 1 deletion cmd/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/fedragon/ark/internal/auth"
"github.com/fedragon/ark/internal/importer"

"github.com/bufbuild/connect-go"
"connectrpc.com/connect"
"github.com/kelseyhightower/envconfig"
"github.com/mitchellh/go-homedir"
"github.com/urfave/cli/v2"
Expand Down
2 changes: 1 addition & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/fedragon/ark/internal/db"
"github.com/fedragon/ark/internal/server"

"github.com/bufbuild/connect-go"
"connectrpc.com/connect"
"github.com/kelseyhightower/envconfig"
"github.com/mitchellh/go-homedir"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand Down
36 changes: 22 additions & 14 deletions gen/ark/v1/arkv1connect/rpc.connect.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 5 additions & 10 deletions gen/ark/v1/rpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ module github.com/fedragon/ark
go 1.23

require (
github.com/bufbuild/connect-go v1.10.0
connectrpc.com/connect v1.17.0
github.com/docker/go-connections v0.4.0
github.com/dsoprea/go-exif/v2 v2.0.0-20230826092837-6579e82b732d
github.com/dsoprea/go-heic-exif-extractor v0.0.0-20210512044107-62067e44c235
github.com/dsoprea/go-jpeg-image-structure v0.0.0-20221012074422-4f3f7e934102
github.com/dsoprea/go-utility v0.0.0-20221003172846-a3e1774ef349
github.com/fedragon/tiff-parser v0.2.0
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/kelseyhightower/envconfig v1.4.0
github.com/mitchellh/go-homedir v1.1.0
Expand Down Expand Up @@ -43,7 +44,6 @@ require (
github.com/dsoprea/go-iptc v0.0.0-20200610044640-bc9ca208b413 // indirect
github.com/dsoprea/go-logging v0.0.0-20200710184922-b02d349568dd // indirect
github.com/dsoprea/go-photoshop-info-format v0.0.0-20200610045659-121dd752914d // indirect
github.com/fedragon/tiff-parser v0.2.0 // indirect
github.com/go-errors/errors v1.5.1 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-xmlfmt/xmlfmt v1.1.2 // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2k
cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw=
cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw=
cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos=
connectrpc.com/connect v1.17.0 h1:W0ZqMhtVzn9Zhn2yATuUokDLO5N+gIuBWMOnsQrfmZk=
connectrpc.com/connect v1.17.0/go.mod h1:0292hj1rnx8oFrStN7cB4jjVBeqs+Yx5yDIC2prWDO8=
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
Expand All @@ -33,8 +35,6 @@ github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
github.com/bufbuild/connect-go v1.10.0 h1:QAJ3G9A1OYQW2Jbk3DeoJbkCxuKArrvZgDt47mjdTbg=
github.com/bufbuild/connect-go v1.10.0/go.mod h1:CAIePUgkDR5pAFaylSMtNK45ANQjp9JvpluG20rhpV8=
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down Expand Up @@ -92,8 +92,6 @@ github.com/dsoprea/go-utility v0.0.0-20221003172846-a3e1774ef349/go.mod h1:KVK+/
github.com/dsoprea/go-utility/v2 v2.0.0-20200717064901-2fccff4aa15e/go.mod h1:uAzdkPTub5Y9yQwXe8W4m2XuP0tK4a9Q/dantD0+uaU=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fedragon/tiff-parser v0.1.0 h1:Wu7FiKxfzvSflxBu4ymzqyPAtW05S0/3/FOjZQKzadQ=
github.com/fedragon/tiff-parser v0.1.0/go.mod h1:YBJnorsx1hBQkvw4r9VpFppMHuIcG/APTL22WGEUx/8=
github.com/fedragon/tiff-parser v0.2.0 h1:yvnoOa3u+Sp4E7BVq1TNIUDTsdB1fnNak8pDzxCRSWo=
github.com/fedragon/tiff-parser v0.2.0/go.mod h1:YBJnorsx1hBQkvw4r9VpFppMHuIcG/APTL22WGEUx/8=
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
Expand Down
2 changes: 1 addition & 1 deletion internal/auth/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"time"

"github.com/bufbuild/connect-go"
"connectrpc.com/connect"
"github.com/golang-jwt/jwt/v5"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/importer/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/fedragon/ark/internal/db"
"github.com/fedragon/ark/internal/fs"

"github.com/bufbuild/connect-go"
"connectrpc.com/connect"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
"google.golang.org/protobuf/types/known/timestamppb"
Expand Down
2 changes: 1 addition & 1 deletion internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/fedragon/ark/internal/header"
"github.com/fedragon/ark/internal/metrics"

"github.com/bufbuild/connect-go"
"connectrpc.com/connect"
)

type Handler struct {
Expand Down
2 changes: 1 addition & 1 deletion test/client_stage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/fedragon/ark/internal/importer"
_ "github.com/fedragon/ark/testing"

"github.com/bufbuild/connect-go"
"connectrpc.com/connect"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
)
Expand Down
21 changes: 11 additions & 10 deletions test/server_stage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import (
"github.com/fedragon/ark/internal/server"
_ "github.com/fedragon/ark/testing"

"github.com/bufbuild/connect-go"
"connectrpc.com/connect"
"github.com/redis/go-redis/v9"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/timestamppb"
)

Expand Down Expand Up @@ -79,10 +80,10 @@ func (s *ServerStage) FileExists() *ServerStage {

func (s *ServerStage) ClientUploadsFile(path string) *ServerStage {
data, err := os.ReadFile(path)
assert.NoError(s.t, err)
require.NoError(s.t, err)

hash, err := fs.Hash(path)
assert.NoError(s.t, err)
require.NoError(s.t, err)

stream := s.client.UploadFile(context.Background())

Expand All @@ -96,7 +97,7 @@ func (s *ServerStage) ClientUploadsFile(path string) *ServerStage {
},
},
})
assert.NoError(s.t, err)
require.NoError(s.t, err)

err = stream.Send(&arkv1.UploadFileRequest{
File: &arkv1.UploadFileRequest_Chunk{
Expand All @@ -105,18 +106,18 @@ func (s *ServerStage) ClientUploadsFile(path string) *ServerStage {
},
},
})
assert.NoError(s.t, err)
require.NoError(s.t, err)
_, s.uploadError = stream.CloseAndReceive()

return s
}

func (s *ServerStage) ClientUploadsFileAgain(path string) *ServerStage {
data, err := os.ReadFile(path)
assert.NoError(s.t, err)
require.NoError(s.t, err)

hash, err := fs.Hash(path)
assert.NoError(s.t, err)
require.NoError(s.t, err)

stream := s.client.UploadFile(context.Background())
err = stream.Send(&arkv1.UploadFileRequest{
Expand All @@ -129,21 +130,21 @@ func (s *ServerStage) ClientUploadsFileAgain(path string) *ServerStage {
},
},
})
assert.NoError(s.t, err)
require.NoError(s.t, err)
_, s.uploadError = stream.CloseAndReceive()

return s
}

func (s *ServerStage) UploadSucceeds() *ServerStage {
assert.NoError(s.t, s.uploadError)
require.NoError(s.t, s.uploadError)
return s
}

func (s *ServerStage) UploadIsSkipped() *ServerStage {
target := &connect.Error{}
if assert.Error(s.t, s.uploadError) && assert.ErrorAs(s.t, s.uploadError, &target) {
assert.Equal(s.t, connect.CodeAlreadyExists, target.Code(), target.Error())
require.Equal(s.t, connect.CodeAlreadyExists, target.Code(), target.Error())
} else {
s.t.FailNow()
}
Expand Down

0 comments on commit 5c42bb2

Please sign in to comment.