diff --git a/Makefile b/Makefile index 471ced5..a1704b5 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ TEST_OPTIONS=-timeout 30s -parallel $(NCPU) default: build -build: +build: protobuf go build ./cmd/dewy server: build @@ -21,9 +21,12 @@ server: build assets: build ./dewy assets -r linyows/dewy-testapp -a dewy-testapp_darwin_amd64.tar.gz -l $(LOGLEVEL) +protobuf: deps + cd registry/grpc/proto && buf generate + deps: - go get golang.org/x/lint/golint - go get github.com/goreleaser/goreleaser + go install github.com/goreleaser/goreleaser@latest + go install github.com/bufbuild/buf/cmd/buf@latest test: go test $(TEST) $(TESTARGS) $(TEST_OPTIONS) diff --git a/dewy.go b/dewy.go index e80fca4..199923a 100644 --- a/dewy.go +++ b/dewy.go @@ -21,7 +21,9 @@ import ( "github.com/linyows/dewy/notice" "github.com/linyows/dewy/registry" ghrelease "github.com/linyows/dewy/registry/github_release" + grpcr "github.com/linyows/dewy/registry/grpc" "github.com/linyows/dewy/storage" + "google.golang.org/grpc" ) const ( @@ -125,7 +127,7 @@ func (d *Dewy) Run() error { defer cancel() // Get current - res, err := d.registry.Current(®istry.CurrentRequest{ + res, err := d.registry.Current(ctx, ®istry.CurrentRequest{ Arch: runtime.GOARCH, OS: runtime.GOOS, ArtifactName: d.config.ArtifactName, @@ -194,7 +196,7 @@ func (d *Dewy) Run() error { if !d.disableReport { log.Print("[DEBUG] Report shipping") - err := d.registry.Report(®istry.ReportRequest{ + err := d.registry.Report(ctx, ®istry.ReportRequest{ ID: res.ID, Tag: res.Tag, }) @@ -326,6 +328,14 @@ func newRegistry(urlstr string, preRelease bool, artifactName string) (registry. PreRelease: preRelease, } return ghrelease.New(c) + case grpcr.Scheme: + // TODO: handle tls + target := su[1] + cc, err := grpc.Dial(target) + if err != nil { + return nil, err + } + return grpcr.New(cc) } return nil, fmt.Errorf("unsupported registry: %s", urlstr) } diff --git a/go.mod b/go.mod index b5f4c5c..3e59396 100644 --- a/go.mod +++ b/go.mod @@ -10,10 +10,13 @@ require ( github.com/hashicorp/logutils v1.0.0 github.com/jessevdk/go-flags v1.5.0 github.com/k1LoW/go-github-client/v55 v55.0.11 + github.com/k1LoW/grpcstub v0.15.1 github.com/k1LoW/remote v0.1.0 github.com/lestrrat-go/server-starter v0.0.0-20210101230921-50cd1900b5bc github.com/lestrrat-go/slack v0.0.0-20190827134815-1aaae719550a github.com/mholt/archiver/v3 v3.5.1 + google.golang.org/grpc v1.57.0 + google.golang.org/protobuf v1.31.0 ) require ( @@ -25,7 +28,9 @@ require ( github.com/ProtonMail/go-crypto v0.0.0-20230626094100-7e9e0395ebec // indirect github.com/andybalholm/brotli v1.0.1 // indirect github.com/aws/aws-sdk-go v1.44.305 // indirect + github.com/bmatcuk/doublestar/v4 v4.6.0 // indirect github.com/bradleyfalzon/ghinstallation/v2 v2.7.0 // indirect + github.com/bufbuild/protocompile v0.6.0 // indirect github.com/cli/go-gh/v2 v2.3.0 // indirect github.com/cli/safeexec v1.0.1 // indirect github.com/cloudflare/circl v1.3.3 // indirect @@ -40,6 +45,7 @@ require ( github.com/google/uuid v1.3.0 // indirect github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect github.com/googleapis/gax-go/v2 v2.11.0 // indirect + github.com/jaswdr/faker v1.16.0 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/jszwec/s3fs v0.4.0 // indirect github.com/k1LoW/ghfs v1.1.0 // indirect @@ -48,16 +54,18 @@ require ( github.com/klauspost/pgzip v1.2.5 // indirect github.com/lestrrat-go/pdebug v0.0.0-20210111095411-35b07dbf089b // indirect github.com/mauri870/gcsfs v0.0.0-20220203135357-0da01ba4e96d // indirect + github.com/minio/pkg v1.6.5 // indirect github.com/nwaples/rardecode v1.1.0 // indirect github.com/pierrec/lz4/v4 v4.1.2 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/ulikunitz/xz v0.5.10 // indirect github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect go.opencensus.io v0.24.0 // indirect - golang.org/x/crypto v0.13.0 // indirect - golang.org/x/net v0.15.0 // indirect + golang.org/x/crypto v0.14.0 // indirect + golang.org/x/net v0.17.0 // indirect golang.org/x/oauth2 v0.12.0 // indirect - golang.org/x/sys v0.12.0 // indirect + golang.org/x/sync v0.3.0 // indirect + golang.org/x/sys v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect google.golang.org/api v0.126.0 // indirect @@ -65,7 +73,5 @@ require ( google.golang.org/genproto v0.0.0-20230530153820-e85fd2cbaebc // indirect google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect - google.golang.org/grpc v1.55.0 // indirect - google.golang.org/protobuf v1.31.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index f98e113..723fbf4 100644 --- a/go.sum +++ b/go.sum @@ -84,8 +84,12 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/bmatcuk/doublestar/v4 v4.6.0 h1:HTuxyug8GyFbRkrffIpzNCSK4luc0TY3wzXvzIZhEXc= +github.com/bmatcuk/doublestar/v4 v4.6.0/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc= github.com/bradleyfalzon/ghinstallation/v2 v2.7.0 h1:ranXaC3Zz/F6G/f0Joj3LrFp2OzOKfJZev5Q7OaMc88= github.com/bradleyfalzon/ghinstallation/v2 v2.7.0/go.mod h1:ymxfmloxXBFXvvF1KpeUhOQM6Dfz9NYtfvTiJyk82UE= +github.com/bufbuild/protocompile v0.6.0 h1:Uu7WiSQ6Yj9DbkdnOe7U4mNKp58y9WDMKDn28/ZlunY= +github.com/bufbuild/protocompile v0.6.0/go.mod h1:YNP35qEYoYGme7QMtz5SBCoN4kL4g12jTtjuzRNdjpE= github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/carlescere/scheduler v0.0.0-20170109141437-ee74d2f83d82 h1:9bAydALqAjBfPHd/eAiJBHnMZUYov8m2PkXVr+YGQeI= @@ -293,13 +297,21 @@ github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47 github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/jaswdr/faker v1.16.0 h1:5ZjusQbqIZwJnUymPirNKJI1yFCuozdSR9oeYPgD5Uk= +github.com/jaswdr/faker v1.16.0/go.mod h1:x7ZlyB1AZqwqKZgyQlnqEG8FDptmHlncA5u2zY/yi6w= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc= github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4= +github.com/jhump/protoreflect/v2 v2.0.0-20230705224148-00680b949112 h1:DKASUy0S/ca+GoYZJ77VQefLyID0wn4isJcoQ4pd/WY= +github.com/jhump/protoreflect/v2 v2.0.0-20230705224148-00680b949112/go.mod h1:PKDh3b1I/ISNmawcTX+YMYDYx3tA5zLUp3B1N2wmXWs= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= +github.com/josharian/mapfs v0.0.0-20210615234106-095c008854e6 h1:c+ctPFdISggaSNCfU1IueNBAsqetJSvMcpQlT+0OVdY= +github.com/josharian/mapfs v0.0.0-20210615234106-095c008854e6/go.mod h1:Rv/momJI8DgrWnBZip+SgagpcgORIZQE5SERlxNb8LY= +github.com/josharian/txtarfs v0.0.0-20210615234325-77aca6df5bca h1:a8xeK4GsWLE4LYo5VI4u1Cn7ZvT1NtXouXR3DdKLB8Q= +github.com/josharian/txtarfs v0.0.0-20210615234325-77aca6df5bca/go.mod h1:UbC32ft9G/jG+sZI8wLbIBNIrYr7vp/yqMDa9SxVBNA= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= @@ -315,6 +327,8 @@ github.com/k1LoW/go-github-client/v53 v53.2.11 h1:3EpAdfUjTQUtjZF5vPY4dxTWs9NiP/ github.com/k1LoW/go-github-client/v53 v53.2.11/go.mod h1:ZGCmYsG2ulDF+2qYzjH9ZpC5MhyYYb83UMTQWjBNmIQ= github.com/k1LoW/go-github-client/v55 v55.0.11 h1:vmgry8KN97AZcjzS0qJwFvbfOEHF6dbCmiK0b9jITNY= github.com/k1LoW/go-github-client/v55 v55.0.11/go.mod h1:91PQWyrMwQN7TqoI3/jqRuzmbjSkrkBxQH2QZUjtZ/I= +github.com/k1LoW/grpcstub v0.15.1 h1:PFdkn+YRgvhfV71ws9frfNlOOcVGtiY74tiyoO5Ylyw= +github.com/k1LoW/grpcstub v0.15.1/go.mod h1:PEKtK3SvFYlRF/t944vu8AXVJ8Mplp5kPYXeLk7k4XM= github.com/k1LoW/remote v0.1.0 h1:qdX+7f9+kWMO70LKJV/LohHQPLcbNDnTfU8RH/0qeWE= github.com/k1LoW/remote v0.1.0/go.mod h1:8ruOAe7LNwJ7ACjndBPMVhfNvIRgqaOLlFxGMovY8tU= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= @@ -329,7 +343,6 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= @@ -365,6 +378,8 @@ github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKju github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= github.com/migueleliasweb/go-github-mock v0.0.19 h1:z/88f6wPqZVFnE7s9DbwXMhCtmV/0FofNxc4M7FuSdU= github.com/migueleliasweb/go-github-mock v0.0.19/go.mod h1:dBoCB3W9NjzyABhoGkfI0iSlFpzulAXhI7M+9A4ONYI= +github.com/minio/pkg v1.6.5 h1:T9cRNcCLJTFFgQGH0Rzr1CtAWLAIchTsbE0lSztCf40= +github.com/minio/pkg v1.6.5/go.mod h1:0iX1IuJGSCnMvIvrEJauk1GgQSX9JdU6Kh0P3EQRGkI= github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= @@ -377,6 +392,8 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nwaples/rardecode v1.1.0 h1:vSxaY8vQhOcVr4mm5e8XllHWTiM4JF507A0Katqw7MQ= github.com/nwaples/rardecode v1.1.0/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= @@ -433,9 +450,12 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= +github.com/tenntenn/golden v0.5.1 h1:LQHiiTgbm+XwnTFnP8e/Nwjm2qYErQJzI1mbqfRLJi8= +github.com/tenntenn/golden v0.5.1/go.mod h1:0xI/4lpoHR65AUTmd1RKR9S1Uv0JR3yR2Q1Ob2bKqQA= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/ulikunitz/xz v0.5.9/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= @@ -481,8 +501,8 @@ golang.org/x/crypto v0.0.0-20220314234659-1baeb1ce4c0b/go.mod h1:IxCIyHEi3zRg3s0 golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= -golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck= -golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -570,8 +590,8 @@ golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= -golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -604,8 +624,8 @@ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= -golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -681,8 +701,8 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -769,6 +789,7 @@ golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -922,8 +943,8 @@ google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9K google.golang.org/grpc v1.40.1/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= google.golang.org/grpc v1.42.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ= -google.golang.org/grpc v1.55.0 h1:3Oj82/tFSCeUrRTg/5E/7d/W5A1tj6Ky1ABAuZuv5ag= -google.golang.org/grpc v1.55.0/go.mod h1:iYEXKGkEBhg1PjZQvoYEVPTDkHo1/bjTnfwTeGONTY8= +google.golang.org/grpc v1.57.0 h1:kfzNeI/klCGD2YPMUlaGNT3pxvYfga7smW3Vth8Zsiw= +google.golang.org/grpc v1.57.0/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= @@ -943,8 +964,9 @@ google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/registry/github_release/github_release.go b/registry/github_release/github_release.go index 6b991d1..35d3f5b 100644 --- a/registry/github_release/github_release.go +++ b/registry/github_release/github_release.go @@ -87,8 +87,8 @@ func (g *GithubRelease) URL() string { } // Current returns current artifact. -func (g *GithubRelease) Current(req *registry.CurrentRequest) (*registry.CurrentResponse, error) { - release, err := g.latest() +func (g *GithubRelease) Current(ctx context.Context, req *registry.CurrentRequest) (*registry.CurrentResponse, error) { + release, err := g.latest(ctx) if err != nil { return nil, err } @@ -156,8 +156,7 @@ func (g *GithubRelease) Current(req *registry.CurrentRequest) (*registry.Current }, nil } -func (g *GithubRelease) latest() (*github.RepositoryRelease, error) { - ctx := context.Background() +func (g *GithubRelease) latest(ctx context.Context) (*github.RepositoryRelease, error) { var r *github.RepositoryRelease if g.prerelease { opt := &github.ListOptions{Page: 1} @@ -180,11 +179,10 @@ func (g *GithubRelease) latest() (*github.RepositoryRelease, error) { } // Report report shipping. -func (g *GithubRelease) Report(req *registry.ReportRequest) error { +func (g *GithubRelease) Report(ctx context.Context, req *registry.ReportRequest) error { if req.Err != nil { return req.Err } - ctx := context.Background() now := time.Now().UTC().Format(ISO8601) hostname, _ := os.Hostname() info := fmt.Sprintf("shipped to %s at %s", strings.ToLower(hostname), now) diff --git a/registry/grpc/grpc.go b/registry/grpc/grpc.go new file mode 100644 index 0000000..cd5ad0e --- /dev/null +++ b/registry/grpc/grpc.go @@ -0,0 +1,68 @@ +package grpc + +import ( + "context" + + "github.com/linyows/dewy/registry" + dewypb "github.com/linyows/dewy/registry/grpc/proto/gen/dewy" + "google.golang.org/grpc" +) + +const ( + Scheme = "grpc" +) + +type Client struct { + cl dewypb.RegistryServiceClient +} + +var _ registry.Registry = (*Client)(nil) + +// New returns Client. +func New(cc grpc.ClientConnInterface) (*Client, error) { + cl := dewypb.NewRegistryServiceClient(cc) + return &Client{ + cl: cl, + }, nil +} + +// Current returns current artifact. +func (c *Client) Current(ctx context.Context, req *registry.CurrentRequest) (*registry.CurrentResponse, error) { + var an *string + if req.ArtifactName != "" { + an = &req.ArtifactName + } + creq := &dewypb.CurrentRequest{ + Arch: req.Arch, + Os: req.OS, + ArifactName: an, + } + cres, err := c.cl.Current(ctx, creq) + if err != nil { + return nil, err + } + res := ®istry.CurrentResponse{ + ID: cres.Id, + Tag: cres.Tag, + ArtifactURL: cres.ArtifactUrl, + } + return res, nil +} + +// Report report shipping. +func (c *Client) Report(ctx context.Context, req *registry.ReportRequest) error { + var perr *string + if req.Err != nil { + serr := req.Err.Error() + perr = &serr + } + creq := &dewypb.ReportRequest{ + Id: req.ID, + Tag: req.Tag, + Err: perr, + } + if _, err := c.cl.Report(ctx, creq); err != nil { + return err + } + return nil +} diff --git a/registry/grpc/grpc_test.go b/registry/grpc/grpc_test.go new file mode 100644 index 0000000..00e8e1e --- /dev/null +++ b/registry/grpc/grpc_test.go @@ -0,0 +1,94 @@ +package grpc + +import ( + "context" + "errors" + "testing" + + "github.com/google/go-cmp/cmp" + "github.com/k1LoW/grpcstub" + "github.com/linyows/dewy/registry" + dewypb "github.com/linyows/dewy/registry/grpc/proto/gen/dewy" + emptypb "google.golang.org/protobuf/types/known/emptypb" +) + +func TestCurrent(t *testing.T) { + ctx := context.Background() + ts := grpcstub.NewServer(t, "proto/dewy.proto") + t.Cleanup(func() { + ts.Close() + }) + ts.Method("Current").Response(&dewypb.CurrentResponse{ + Id: "1234567890", + Tag: "v1.0.0", + ArtifactUrl: "github_release://linyows/dewy", + }) + client, err := New(ts.ClientConn()) + if err != nil { + t.Fatal(err) + } + req := ®istry.CurrentRequest{ + Arch: "amd64", + OS: "linux", + } + t.Run("Response", func(t *testing.T) { + got, err := client.Current(ctx, req) + if err != nil { + t.Fatal(err) + } + want := ®istry.CurrentResponse{ + ID: "1234567890", + Tag: "v1.0.0", + ArtifactURL: "github_release://linyows/dewy", + } + if diff := cmp.Diff(got, want); diff != "" { + t.Error(diff) + } + }) + t.Run("Request", func(t *testing.T) { + if want := 1; len(ts.Requests()) != want { + t.Errorf("got %v, want %v", len(ts.Requests()), want) + } + want := grpcstub.Message{ + "arch": "amd64", + "os": "linux", + } + if diff := cmp.Diff(ts.Requests()[0].Message, want); diff != "" { + t.Error(diff) + } + }) +} + +func TestReport(t *testing.T) { + ctx := context.Background() + ts := grpcstub.NewServer(t, "proto/dewy.proto") + t.Cleanup(func() { + ts.Close() + }) + ts.Method("Report").Response(&emptypb.Empty{}) + client, err := New(ts.ClientConn()) + if err != nil { + t.Fatal(err) + } + req := ®istry.ReportRequest{ + ID: "1234567890", + Tag: "v1.0.0", + Err: errors.New("something error"), + } + if err := client.Report(ctx, req); err != nil { + t.Fatal(err) + } + t.Run("Request", func(t *testing.T) { + if want := 1; len(ts.Requests()) != want { + t.Errorf("got %v, want %v", len(ts.Requests()), want) + } + want := grpcstub.Message{ + "id": "1234567890", + "tag": "v1.0.0", + "err": "something error", + } + if diff := cmp.Diff(ts.Requests()[0].Message, want); diff != "" { + t.Error(diff) + } + }) +} diff --git a/registry/grpc/proto/buf.gen.yaml b/registry/grpc/proto/buf.gen.yaml new file mode 100644 index 0000000..80e8753 --- /dev/null +++ b/registry/grpc/proto/buf.gen.yaml @@ -0,0 +1,12 @@ +version: v1 +managed: + enabled: true + go_package_prefix: + default: github.com/linyows/dewy/registry/grpc/gen/dewy +plugins: + - plugin: buf.build/protocolbuffers/go + out: gen/dewy + opt: paths=source_relative + - plugin: buf.build/grpc/go + out: gen/dewy + opt: paths=source_relative diff --git a/registry/grpc/proto/buf.yaml b/registry/grpc/proto/buf.yaml new file mode 100644 index 0000000..1a51945 --- /dev/null +++ b/registry/grpc/proto/buf.yaml @@ -0,0 +1,7 @@ +version: v1 +breaking: + use: + - FILE +lint: + use: + - DEFAULT diff --git a/registry/grpc/proto/dewy.proto b/registry/grpc/proto/dewy.proto new file mode 100644 index 0000000..1a867b9 --- /dev/null +++ b/registry/grpc/proto/dewy.proto @@ -0,0 +1,33 @@ +syntax = "proto3"; + +import "google/protobuf/empty.proto"; + +package dewy; + +service RegistryService { + // Current returns the current artifact. + rpc Current (CurrentRequest) returns (CurrentResponse); + // Report reports the result of deploying the artifact. + rpc Report (ReportRequest) returns (google.protobuf.Empty); +} + +// CurrentRequest is the request to get the current artifact. +message CurrentRequest { + string arch = 1; // arch is the CPU architecture of deployment environment. + string os = 2; // os is the operating system of deployment environment. + optional string arifact_name = 3; // artifact_name is the name of the artifact to fetch. +} + +// CurrentResponse is the response to get the current artifact. +message CurrentResponse { + string id = 1; // id uniquely identifies the response. + string tag = 2; // tag uniquely identifies the artifact concerned. + string artifact_url = 3; // artifact_url is the URL to download the artifact. +} + +// ReportRequest is the request to report the result of deploying the artifact. +message ReportRequest { + string id = 1; // id is the ID of the response. + string tag = 2; // tag is the current tag of deployed artifact. + optional string err = 3; // err is the error that occurred during deployment. If Err is nil, the deployment is considered successful. +} diff --git a/registry/grpc/proto/gen/dewy/dewy.pb.go b/registry/grpc/proto/gen/dewy/dewy.pb.go new file mode 100644 index 0000000..534deca --- /dev/null +++ b/registry/grpc/proto/gen/dewy/dewy.pb.go @@ -0,0 +1,352 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc (unknown) +// source: dewy.proto + +package dewy + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + emptypb "google.golang.org/protobuf/types/known/emptypb" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// CurrentRequest is the request to get the current artifact. +type CurrentRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Arch string `protobuf:"bytes,1,opt,name=arch,proto3" json:"arch,omitempty"` // arch is the CPU architecture of deployment environment. + Os string `protobuf:"bytes,2,opt,name=os,proto3" json:"os,omitempty"` // os is the operating system of deployment environment. + ArifactName *string `protobuf:"bytes,3,opt,name=arifact_name,json=arifactName,proto3,oneof" json:"arifact_name,omitempty"` // artifact_name is the name of the artifact to fetch. +} + +func (x *CurrentRequest) Reset() { + *x = CurrentRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_dewy_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CurrentRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CurrentRequest) ProtoMessage() {} + +func (x *CurrentRequest) ProtoReflect() protoreflect.Message { + mi := &file_dewy_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CurrentRequest.ProtoReflect.Descriptor instead. +func (*CurrentRequest) Descriptor() ([]byte, []int) { + return file_dewy_proto_rawDescGZIP(), []int{0} +} + +func (x *CurrentRequest) GetArch() string { + if x != nil { + return x.Arch + } + return "" +} + +func (x *CurrentRequest) GetOs() string { + if x != nil { + return x.Os + } + return "" +} + +func (x *CurrentRequest) GetArifactName() string { + if x != nil && x.ArifactName != nil { + return *x.ArifactName + } + return "" +} + +// CurrentResponse is the response to get the current artifact. +type CurrentResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` // id uniquely identifies the response. + Tag string `protobuf:"bytes,2,opt,name=tag,proto3" json:"tag,omitempty"` // tag uniquely identifies the artifact concerned. + ArtifactUrl string `protobuf:"bytes,3,opt,name=artifact_url,json=artifactUrl,proto3" json:"artifact_url,omitempty"` // artifact_url is the URL to download the artifact. +} + +func (x *CurrentResponse) Reset() { + *x = CurrentResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_dewy_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CurrentResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CurrentResponse) ProtoMessage() {} + +func (x *CurrentResponse) ProtoReflect() protoreflect.Message { + mi := &file_dewy_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CurrentResponse.ProtoReflect.Descriptor instead. +func (*CurrentResponse) Descriptor() ([]byte, []int) { + return file_dewy_proto_rawDescGZIP(), []int{1} +} + +func (x *CurrentResponse) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *CurrentResponse) GetTag() string { + if x != nil { + return x.Tag + } + return "" +} + +func (x *CurrentResponse) GetArtifactUrl() string { + if x != nil { + return x.ArtifactUrl + } + return "" +} + +// ReportRequest is the request to report the result of deploying the artifact. +type ReportRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` // id is the ID of the response. + Tag string `protobuf:"bytes,2,opt,name=tag,proto3" json:"tag,omitempty"` // tag is the current tag of deployed artifact. + Err *string `protobuf:"bytes,3,opt,name=err,proto3,oneof" json:"err,omitempty"` // err is the error that occurred during deployment. If Err is nil, the deployment is considered successful. +} + +func (x *ReportRequest) Reset() { + *x = ReportRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_dewy_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ReportRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ReportRequest) ProtoMessage() {} + +func (x *ReportRequest) ProtoReflect() protoreflect.Message { + mi := &file_dewy_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ReportRequest.ProtoReflect.Descriptor instead. +func (*ReportRequest) Descriptor() ([]byte, []int) { + return file_dewy_proto_rawDescGZIP(), []int{2} +} + +func (x *ReportRequest) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *ReportRequest) GetTag() string { + if x != nil { + return x.Tag + } + return "" +} + +func (x *ReportRequest) GetErr() string { + if x != nil && x.Err != nil { + return *x.Err + } + return "" +} + +var File_dewy_proto protoreflect.FileDescriptor + +var file_dewy_proto_rawDesc = []byte{ + 0x0a, 0x0a, 0x64, 0x65, 0x77, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, 0x64, 0x65, + 0x77, 0x79, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, + 0x6d, 0x0a, 0x0e, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x72, 0x63, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x04, 0x61, 0x72, 0x63, 0x68, 0x12, 0x0e, 0x0a, 0x02, 0x6f, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x02, 0x6f, 0x73, 0x12, 0x26, 0x0a, 0x0c, 0x61, 0x72, 0x69, 0x66, 0x61, 0x63, 0x74, + 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x0b, 0x61, + 0x72, 0x69, 0x66, 0x61, 0x63, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x88, 0x01, 0x01, 0x42, 0x0f, 0x0a, + 0x0d, 0x5f, 0x61, 0x72, 0x69, 0x66, 0x61, 0x63, 0x74, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x56, + 0x0a, 0x0f, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, + 0x64, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x61, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, + 0x74, 0x61, 0x67, 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x72, 0x74, 0x69, 0x66, 0x61, 0x63, 0x74, 0x5f, + 0x75, 0x72, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x61, 0x72, 0x74, 0x69, 0x66, + 0x61, 0x63, 0x74, 0x55, 0x72, 0x6c, 0x22, 0x50, 0x0a, 0x0d, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x61, 0x67, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x74, 0x61, 0x67, 0x12, 0x15, 0x0a, 0x03, 0x65, 0x72, 0x72, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x03, 0x65, 0x72, 0x72, 0x88, 0x01, 0x01, + 0x42, 0x06, 0x0a, 0x04, 0x5f, 0x65, 0x72, 0x72, 0x32, 0x80, 0x01, 0x0a, 0x0f, 0x52, 0x65, 0x67, + 0x69, 0x73, 0x74, 0x72, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x36, 0x0a, 0x07, + 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x12, 0x14, 0x2e, 0x64, 0x65, 0x77, 0x79, 0x2e, 0x43, + 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, + 0x64, 0x65, 0x77, 0x79, 0x2e, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x35, 0x0a, 0x06, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x13, + 0x2e, 0x64, 0x65, 0x77, 0x79, 0x2e, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x42, 0x75, 0x0a, 0x08, 0x63, + 0x6f, 0x6d, 0x2e, 0x64, 0x65, 0x77, 0x79, 0x42, 0x09, 0x44, 0x65, 0x77, 0x79, 0x50, 0x72, 0x6f, + 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x2e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, + 0x2f, 0x6c, 0x69, 0x6e, 0x79, 0x6f, 0x77, 0x73, 0x2f, 0x64, 0x65, 0x77, 0x79, 0x2f, 0x72, 0x65, + 0x67, 0x69, 0x73, 0x74, 0x72, 0x79, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x67, 0x65, 0x6e, 0x2f, + 0x64, 0x65, 0x77, 0x79, 0xa2, 0x02, 0x03, 0x44, 0x58, 0x58, 0xaa, 0x02, 0x04, 0x44, 0x65, 0x77, + 0x79, 0xca, 0x02, 0x04, 0x44, 0x65, 0x77, 0x79, 0xe2, 0x02, 0x10, 0x44, 0x65, 0x77, 0x79, 0x5c, + 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x04, 0x44, 0x65, + 0x77, 0x79, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_dewy_proto_rawDescOnce sync.Once + file_dewy_proto_rawDescData = file_dewy_proto_rawDesc +) + +func file_dewy_proto_rawDescGZIP() []byte { + file_dewy_proto_rawDescOnce.Do(func() { + file_dewy_proto_rawDescData = protoimpl.X.CompressGZIP(file_dewy_proto_rawDescData) + }) + return file_dewy_proto_rawDescData +} + +var file_dewy_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_dewy_proto_goTypes = []interface{}{ + (*CurrentRequest)(nil), // 0: dewy.CurrentRequest + (*CurrentResponse)(nil), // 1: dewy.CurrentResponse + (*ReportRequest)(nil), // 2: dewy.ReportRequest + (*emptypb.Empty)(nil), // 3: google.protobuf.Empty +} +var file_dewy_proto_depIdxs = []int32{ + 0, // 0: dewy.RegistryService.Current:input_type -> dewy.CurrentRequest + 2, // 1: dewy.RegistryService.Report:input_type -> dewy.ReportRequest + 1, // 2: dewy.RegistryService.Current:output_type -> dewy.CurrentResponse + 3, // 3: dewy.RegistryService.Report:output_type -> google.protobuf.Empty + 2, // [2:4] is the sub-list for method output_type + 0, // [0:2] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_dewy_proto_init() } +func file_dewy_proto_init() { + if File_dewy_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_dewy_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CurrentRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_dewy_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CurrentResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_dewy_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ReportRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + file_dewy_proto_msgTypes[0].OneofWrappers = []interface{}{} + file_dewy_proto_msgTypes[2].OneofWrappers = []interface{}{} + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_dewy_proto_rawDesc, + NumEnums: 0, + NumMessages: 3, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_dewy_proto_goTypes, + DependencyIndexes: file_dewy_proto_depIdxs, + MessageInfos: file_dewy_proto_msgTypes, + }.Build() + File_dewy_proto = out.File + file_dewy_proto_rawDesc = nil + file_dewy_proto_goTypes = nil + file_dewy_proto_depIdxs = nil +} diff --git a/registry/grpc/proto/gen/dewy/dewy_grpc.pb.go b/registry/grpc/proto/gen/dewy/dewy_grpc.pb.go new file mode 100644 index 0000000..21f7369 --- /dev/null +++ b/registry/grpc/proto/gen/dewy/dewy_grpc.pb.go @@ -0,0 +1,151 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc (unknown) +// source: dewy.proto + +package dewy + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + emptypb "google.golang.org/protobuf/types/known/emptypb" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +const ( + RegistryService_Current_FullMethodName = "/dewy.RegistryService/Current" + RegistryService_Report_FullMethodName = "/dewy.RegistryService/Report" +) + +// RegistryServiceClient is the client API for RegistryService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type RegistryServiceClient interface { + // Current returns the current artifact. + Current(ctx context.Context, in *CurrentRequest, opts ...grpc.CallOption) (*CurrentResponse, error) + // Report reports the result of deploying the artifact. + Report(ctx context.Context, in *ReportRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) +} + +type registryServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewRegistryServiceClient(cc grpc.ClientConnInterface) RegistryServiceClient { + return ®istryServiceClient{cc} +} + +func (c *registryServiceClient) Current(ctx context.Context, in *CurrentRequest, opts ...grpc.CallOption) (*CurrentResponse, error) { + out := new(CurrentResponse) + err := c.cc.Invoke(ctx, RegistryService_Current_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *registryServiceClient) Report(ctx context.Context, in *ReportRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) { + out := new(emptypb.Empty) + err := c.cc.Invoke(ctx, RegistryService_Report_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// RegistryServiceServer is the server API for RegistryService service. +// All implementations must embed UnimplementedRegistryServiceServer +// for forward compatibility +type RegistryServiceServer interface { + // Current returns the current artifact. + Current(context.Context, *CurrentRequest) (*CurrentResponse, error) + // Report reports the result of deploying the artifact. + Report(context.Context, *ReportRequest) (*emptypb.Empty, error) + mustEmbedUnimplementedRegistryServiceServer() +} + +// UnimplementedRegistryServiceServer must be embedded to have forward compatible implementations. +type UnimplementedRegistryServiceServer struct { +} + +func (UnimplementedRegistryServiceServer) Current(context.Context, *CurrentRequest) (*CurrentResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Current not implemented") +} +func (UnimplementedRegistryServiceServer) Report(context.Context, *ReportRequest) (*emptypb.Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method Report not implemented") +} +func (UnimplementedRegistryServiceServer) mustEmbedUnimplementedRegistryServiceServer() {} + +// UnsafeRegistryServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to RegistryServiceServer will +// result in compilation errors. +type UnsafeRegistryServiceServer interface { + mustEmbedUnimplementedRegistryServiceServer() +} + +func RegisterRegistryServiceServer(s grpc.ServiceRegistrar, srv RegistryServiceServer) { + s.RegisterService(&RegistryService_ServiceDesc, srv) +} + +func _RegistryService_Current_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CurrentRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RegistryServiceServer).Current(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: RegistryService_Current_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RegistryServiceServer).Current(ctx, req.(*CurrentRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _RegistryService_Report_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ReportRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RegistryServiceServer).Report(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: RegistryService_Report_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RegistryServiceServer).Report(ctx, req.(*ReportRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// RegistryService_ServiceDesc is the grpc.ServiceDesc for RegistryService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var RegistryService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "dewy.RegistryService", + HandlerType: (*RegistryServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Current", + Handler: _RegistryService_Current_Handler, + }, + { + MethodName: "Report", + Handler: _RegistryService_Report_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "dewy.proto", +} diff --git a/registry/registry.go b/registry/registry.go index 45b6225..c68d511 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -1,10 +1,12 @@ package registry +import "context" + type Registry interface { // Current returns the current artifact. - Current(*CurrentRequest) (*CurrentResponse, error) + Current(context.Context, *CurrentRequest) (*CurrentResponse, error) // Report reports the result of deploying the artifact. - Report(*ReportRequest) error + Report(context.Context, *ReportRequest) error } // CurrentRequest is the request to get the current artifact.