From 5b5e2efbfafa765d6949a75b43b118417fd06441 Mon Sep 17 00:00:00 2001 From: FZambia Date: Thu, 18 Jul 2024 08:46:36 +0300 Subject: [PATCH 1/3] work on adding to BSR --- buf.yaml | 16 ++++++ internal/apiproto/readme.md | 55 +------------------ .../apiproto/{ => swagger}/api.swagger.json | 0 .../apiproto/{ => swagger}/api.swagger.proto | 0 .../{ => swagger}/generate_swagger.sh | 0 .../google/api/annotations.proto | 0 .../{ => swagger}/google/api/http.proto | 0 .../options/annotations.proto | 0 .../options/openapiv2.proto | 0 misc/scripts/generate.sh | 3 + misc/scripts/update_swagger_web.sh | 2 +- 11 files changed, 21 insertions(+), 55 deletions(-) create mode 100644 buf.yaml rename internal/apiproto/{ => swagger}/api.swagger.json (100%) rename internal/apiproto/{ => swagger}/api.swagger.proto (100%) rename internal/apiproto/{ => swagger}/generate_swagger.sh (100%) mode change 100755 => 100644 rename internal/apiproto/{ => swagger}/google/api/annotations.proto (100%) rename internal/apiproto/{ => swagger}/google/api/http.proto (100%) rename internal/apiproto/{ => swagger}/protoc-gen-openapiv2/options/annotations.proto (100%) rename internal/apiproto/{ => swagger}/protoc-gen-openapiv2/options/openapiv2.proto (100%) diff --git a/buf.yaml b/buf.yaml new file mode 100644 index 0000000000..c9fdab2db9 --- /dev/null +++ b/buf.yaml @@ -0,0 +1,16 @@ +version: v2 +modules: + - path: internal/apiproto + name: buf.build/centrifugal/apiproto + excludes: + - internal/apiproto/swagger + - path: internal/unigrpc/unistream + name: buf.build/centrifugal/unistream +lint: + use: + - DEFAULT + ignore: + - internal/apiproto/swagger/api.swagger.proto +breaking: + use: + - FILE diff --git a/internal/apiproto/readme.md b/internal/apiproto/readme.md index ba9aa7607c..91e3a4b894 100644 --- a/internal/apiproto/readme.md +++ b/internal/apiproto/readme.md @@ -1,54 +1 @@ -## Generate HTTP API libraries from swagger spec: - -``` -git clone --depth 1 -b master https://github.com/swagger-api/swagger-codegen.git -cd swagger-codegen -cp /path/to/api.swagger.json ./api.swagger.json -``` - -### Go library: - -``` -./run-in-docker.sh generate -i api.swagger.json -l go -o /gen/out/go-centrifugo -DpackageName=centrifugo -ls out/go-centrifugo -``` - -Then: - -```go -package main - -import ( - "context" - "fmt" - "net/http" - "time" - - "test_project/centrifugo" -) - -func main() { - httpClient := &http.Client{Transport: &http.Transport{ - MaxIdleConnsPerHost: 100, - }, Timeout: time.Second} - client := centrifugo.NewAPIClient(¢rifugo.Configuration{ - BasePath: "http://localhost:8000/api", - DefaultHeader: map[string]string{"Authorization": "apikey "}, - HTTPClient: httpClient, - }) - reply, resp, err := client.PublicationApi.CentrifugoApiPublish(context.Background(), centrifugo.PublishRequest{ - Channel: "test", - Data: map[string]string{}, - }) - if err != nil { - panic(err) - } - if resp.StatusCode != 200 { - panic(resp.StatusCode) - } - if reply.Error_ != nil { - panic(reply.Error_.Message) - } - fmt.Println("ok") -} -``` +Centrifugo server API Protobuf definitions. diff --git a/internal/apiproto/api.swagger.json b/internal/apiproto/swagger/api.swagger.json similarity index 100% rename from internal/apiproto/api.swagger.json rename to internal/apiproto/swagger/api.swagger.json diff --git a/internal/apiproto/api.swagger.proto b/internal/apiproto/swagger/api.swagger.proto similarity index 100% rename from internal/apiproto/api.swagger.proto rename to internal/apiproto/swagger/api.swagger.proto diff --git a/internal/apiproto/generate_swagger.sh b/internal/apiproto/swagger/generate_swagger.sh old mode 100755 new mode 100644 similarity index 100% rename from internal/apiproto/generate_swagger.sh rename to internal/apiproto/swagger/generate_swagger.sh diff --git a/internal/apiproto/google/api/annotations.proto b/internal/apiproto/swagger/google/api/annotations.proto similarity index 100% rename from internal/apiproto/google/api/annotations.proto rename to internal/apiproto/swagger/google/api/annotations.proto diff --git a/internal/apiproto/google/api/http.proto b/internal/apiproto/swagger/google/api/http.proto similarity index 100% rename from internal/apiproto/google/api/http.proto rename to internal/apiproto/swagger/google/api/http.proto diff --git a/internal/apiproto/protoc-gen-openapiv2/options/annotations.proto b/internal/apiproto/swagger/protoc-gen-openapiv2/options/annotations.proto similarity index 100% rename from internal/apiproto/protoc-gen-openapiv2/options/annotations.proto rename to internal/apiproto/swagger/protoc-gen-openapiv2/options/annotations.proto diff --git a/internal/apiproto/protoc-gen-openapiv2/options/openapiv2.proto b/internal/apiproto/swagger/protoc-gen-openapiv2/options/openapiv2.proto similarity index 100% rename from internal/apiproto/protoc-gen-openapiv2/options/openapiv2.proto rename to internal/apiproto/swagger/protoc-gen-openapiv2/options/openapiv2.proto diff --git a/misc/scripts/generate.sh b/misc/scripts/generate.sh index 93d386ba31..3569f04008 100644 --- a/misc/scripts/generate.sh +++ b/misc/scripts/generate.sh @@ -8,6 +8,9 @@ fi cd internal/apiproto bash generate.sh +cd - + +cd internal/apiproto/swagger bash generate_swagger.sh cd - diff --git a/misc/scripts/update_swagger_web.sh b/misc/scripts/update_swagger_web.sh index 8ba1431f58..64f770478a 100755 --- a/misc/scripts/update_swagger_web.sh +++ b/misc/scripts/update_swagger_web.sh @@ -14,7 +14,7 @@ cleanup_exit() { } git clone -c advice.detachedHead=false --depth 1 --branch v4.18.1 --single-branch https://github.com/swagger-api/swagger-ui.git "$TMP_WORK_DIR" -cp internal/apiproto/api.swagger.json "$TMP_WORK_DIR"/dist/swagger.json +cp internal/apiproto/swagger/api.swagger.json "$TMP_WORK_DIR"/dist/swagger.json oldString="https://petstore.swagger.io/v2/" newString="./" From 4a41b85f278b52c33e0ce315a21765fd7b9809ac Mon Sep 17 00:00:00 2001 From: FZambia Date: Thu, 18 Jul 2024 09:11:15 +0300 Subject: [PATCH 2/3] use centrifugo org on buf --- .github/workflows/release.yml | 8 ++++++++ buf.yaml | 4 ++-- internal/apiproto/swagger/api.swagger.json | 3 --- internal/apiproto/swagger/api.swagger.proto | 3 --- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 77f3d40bcd..4c15e03734 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,6 +17,10 @@ jobs: with: go-version: ${{ matrix.go-version }} + - uses: bufbuild/buf-setup-action@v1 + with: + version: "1.34.0" + - name: Checkout code uses: actions/checkout@v4 @@ -55,3 +59,7 @@ jobs: env: PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }} run: misc/scripts/release_packagecloud.sh + + - uses: bufbuild/buf-push-action@v1 + with: + buf_token: ${{ secrets.BUF_TOKEN }} diff --git a/buf.yaml b/buf.yaml index c9fdab2db9..784d873a15 100644 --- a/buf.yaml +++ b/buf.yaml @@ -1,11 +1,11 @@ version: v2 modules: - path: internal/apiproto - name: buf.build/centrifugal/apiproto + name: buf.build/centrifugo/apiproto excludes: - internal/apiproto/swagger - path: internal/unigrpc/unistream - name: buf.build/centrifugal/unistream + name: buf.build/centrifugo/unistream lint: use: - DEFAULT diff --git a/internal/apiproto/swagger/api.swagger.json b/internal/apiproto/swagger/api.swagger.json index 872c215454..22f1411a2a 100644 --- a/internal/apiproto/swagger/api.swagger.json +++ b/internal/apiproto/swagger/api.swagger.json @@ -32,9 +32,6 @@ { "name": "push notification" }, - { - "name": "rate limiting" - }, { "name": "batch" } diff --git a/internal/apiproto/swagger/api.swagger.proto b/internal/apiproto/swagger/api.swagger.proto index 7a9f66ec07..e966f19ffd 100644 --- a/internal/apiproto/swagger/api.swagger.proto +++ b/internal/apiproto/swagger/api.swagger.proto @@ -48,9 +48,6 @@ option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { { name: "push notification" }, - { - name: "rate limiting" - }, { name: "batch" } From ab65f5963b93684219b20231da633d3108c7e385 Mon Sep 17 00:00:00 2001 From: FZambia Date: Thu, 18 Jul 2024 09:30:05 +0300 Subject: [PATCH 3/3] add proxyproto --- buf.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/buf.yaml b/buf.yaml index 784d873a15..60aa397035 100644 --- a/buf.yaml +++ b/buf.yaml @@ -4,6 +4,8 @@ modules: name: buf.build/centrifugo/apiproto excludes: - internal/apiproto/swagger + - path: internal/proxyproto + name: buf.build/centrifugo/proxyproto - path: internal/unigrpc/unistream name: buf.build/centrifugo/unistream lint: