Skip to content

Commit cbe1ae1

Browse files
chore: migrate to protoc (#93)
1 parent a5894da commit cbe1ae1

48 files changed

Lines changed: 5229 additions & 7955 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,50 @@
11
.PHONY: generate
2+
generate: fetch-protos format go-gen
23

3-
generate: patch-swagger-doc format
4-
go mod tidy
5-
go mod vendor
4+
.PHONY: clean
5+
clean:
6+
@find ./proto -type f -name '*.go' -exec rm {} +
67

7-
patch-swagger-doc: buf-gen
8-
#./scripts/update_swagger.sh docs/openapiv2/apidocs.swagger.json
8+
.PHONY: fetch-protos
9+
fetch-protos:
10+
@protofetch -o vendor-proto fetch
911

10-
init-git-hooks:
11-
git config --local core.hooksPath .githooks/
12+
.PHONY: go-gen
13+
go-gen: clean
14+
@find ./proto -type f -iname '*.proto' -exec \
15+
protoc -I./proto -I./vendor-proto \
16+
--go_out=./proto \
17+
--go_opt=paths=import \
18+
--go_opt=module=github.com/openkcm/api-sdk/proto \
19+
--go-grpc_out=./proto \
20+
--go-grpc_opt=paths=import \
21+
--go-grpc_opt=module=github.com/openkcm/api-sdk/proto \
22+
{} +
23+
@go mod tidy
1224

13-
buf-gen: init-git-hooks
14-
buf dep update
15-
./buf.gen.yaml
25+
.PHONY: install-tools
26+
install-tools:
27+
brew install protobuf
28+
go install \
29+
google.golang.org/protobuf/cmd/protoc-gen-go@latest \
30+
google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
31+
brew install bufbuild/buf/buf
32+
npm install -g @coralogix/protofetch
1633

17-
format: buf-gen
18-
buf format -w
34+
.PHONY: validate
35+
validate: format lint breaking
1936

20-
.PHONY: test
21-
test:
22-
go test -race -coverprofile cover.out ./...
23-
# On a Mac, you can use the following command to open the coverage report in the browser
24-
# go tool cover -html=cover.out -o cover.html && open cover.html
37+
.PHONY: lint
38+
lint:
39+
@buf lint
40+
41+
.PHONY: breaking
42+
breaking:
43+
@buf breaking --against https://github.com/openkcm/api-sdk.git#branch=main
44+
45+
.PHONY: format
46+
format:
47+
@buf format -w
2548

2649
.PHONY: reuse-lint
2750
reuse-lint:

README.md

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,77 @@
44

55
Have all service definitions and code generated stubs for OpenKCM APIs.
66

7-
## Generate protobuf code
7+
## Pre-requisites
88

9-
1. **Install `buf`:** If you haven't already, install `buf` by following the instructions on
10-
the [Buf website](https://buf.build/docs/installation/).
11-
You can install buf on macOS or Linux using Homebrew:
9+
Several tools are required to generate the code:
1210

13-
```sh
14-
brew install bufbuild/buf/buf
11+
1. **`protoc compiler`**: see the instruction on the official [web site](https://protobuf.dev/installation) or install using homebrew `brew install protobuf`.
12+
2. **`protoc-gen-go`**: install via `go install google.golang.org/protobuf/cmd/protoc-gen-go@latest`.
13+
3. **`protoc-gen-go-grpc`**: install via `go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest`.
14+
4. **`protofetch`**: download from the [releases page](https://github.com/coralogix/protofetch/releases/latest) of [the GitHub repository](https://github.com/coralogix/protofetch) or install via `cargo install protofetch` or `npm install -g @coralogix/protofetch`, or using any similar tool compatible with the npm registry.
15+
16+
## Optional tools
17+
18+
Optionally, the [`buf` CLI](https://github.com/bufbuild/buf) tool can be used to validate, detect breaking changes, and format `.proto` files:
19+
20+
- **`buf breaking --against https://github.com/openkcm/api-sdk.git#branch=main`**: detect breaking changes against the main branch of the remote repository.
21+
- **`buf format -w`**: format `.proto` files.
22+
- **`buf lint`**: lint `.proto` files.
23+
24+
## Makefile
25+
26+
There are several `make` targets defined in the `Makefile`:
27+
28+
- **`fetch-protos`**: download `.proto` dependencies using `protofetch`.
29+
- **`generate`**: fetches `.proto` dependencies, formats `.proto` files, and generates Go code.
30+
- **`install-tools`**: installs the tools (including optional) from the following sources: Homebrew, Go registry (via `go install`), NPM registry (via `npm install -g`). See the target definition for the details.
31+
- **`validate`**: formats and lints `.proto` files, detects breaking changes.
32+
33+
For the rest `make` targets see `Makefile`.
34+
35+
## Dependencies
36+
37+
`.proto` dependencies are managed with the [`protofetch`](https://github.com/coralogix/protofetch) tool. This tool downloads `.proto` files from a specified location of a git repository and places them into the `vendor-proto` directory. The dependencies are specified in the `protofetch.toml` file.
38+
39+
For instance, a dependency on the [`protovalidate`](https://github.com/bufbuild/protovalidate) proto definitions can be specified as follow:
40+
41+
``` toml
42+
name = "github.com/openkcm/api-sdk"
43+
description = "API proto definitions and Go generated code used in the openkcm project"
44+
45+
[protovalidate]
46+
url = "github.com/bufbuild/protovalidate"
47+
revision = "v1.1.1"
48+
content_roots = ["/proto/protovalidate"]
49+
allow_policies = ["buf/validate/*"]
1550
```
1651

17-
2. **Generate code:** Use the ```sh make generate``` command to run the entire process.
52+
In order to fetch dependencies, execute:
1853

19-
```sh
20-
make generate
54+
``` sh
55+
$ protofetch -o vendor-proto fetch
2156
```
2257

23-
---
58+
## Generate Go code from the .proto definitions
59+
60+
The code can be generated with executing the following Make target
61+
62+
```sh
63+
$ make generate
64+
```
2465

2566
## Using a specific branch
2667

2768
Ensure that the GOPRIVATE environment variable is set up:
2869

29-
```sh
30-
go env -w GOPRIVATE="github.com/*"
31-
```
70+
```sh
71+
$ go env -w GOPRIVATE="github.com/openkcm/*"
72+
```
3273

3374
To use a specific branch of a repository in your Go project, you can use the `go get` command with the branch name.
3475
Here's an example:
3576

36-
> go get github.com/openkcm/api-sdk/proto/kms/api/cmk/registry/system/v1@<branch-name>
77+
> go get github.com/openkcm/api-sdk/proto/kms/api/cmk/registry/system/v1@\<branch-name\>
3778
3879
To switch back to the default branch, follow these steps:
3980

@@ -44,7 +85,7 @@ To switch back to the default branch, follow these steps:
4485
2. Clean up:
4586

4687
```sh
47-
go mod tidy
88+
$ go mod tidy
4889
```
4990

5091
## Support, Feedback, Contributing

buf.gen.yaml

Lines changed: 0 additions & 23 deletions
This file was deleted.

buf.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
version: v2
22
modules:
33
- path: proto
4+
- path: vendor-proto
45
lint:
56
use:
67
- STANDARD
8+
ignore:
9+
- vendor-proto
710
ignore_only:
811
# To not break existing APIs.
912
ENUM_FIRST_VALUE_ZERO:

go.mod

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ module github.com/openkcm/api-sdk
22

33
go 1.24.2
44

5+
tool (
6+
google.golang.org/grpc/cmd/protoc-gen-go-grpc
7+
google.golang.org/protobuf/cmd/protoc-gen-go
8+
)
9+
510
require (
611
google.golang.org/grpc v1.80.0
712
google.golang.org/protobuf v1.36.11
@@ -12,4 +17,5 @@ require (
1217
golang.org/x/sys v0.40.0 // indirect
1318
golang.org/x/text v0.33.0 // indirect
1419
google.golang.org/genproto/googleapis/rpc v0.0.0-20260120221211-b8f7ae30c516 // indirect
20+
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.6.1 // indirect
1521
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,7 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20260120221211-b8f7ae30c516 h1:
3434
google.golang.org/genproto/googleapis/rpc v0.0.0-20260120221211-b8f7ae30c516/go.mod h1:j9x/tPzZkyxcgEFkiKEEGxfvyumM01BEtsW8xzOahRQ=
3535
google.golang.org/grpc v1.80.0 h1:Xr6m2WmWZLETvUNvIUmeD5OAagMw3FiKmMlTdViWsHM=
3636
google.golang.org/grpc v1.80.0/go.mod h1:ho/dLnxwi3EDJA4Zghp7k2Ec1+c2jqup0bFkw07bwF4=
37+
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.6.1 h1:/WILD1UcXj/ujCxgoL/DvRgt2CP3txG8+FwkUbb9110=
38+
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.6.1/go.mod h1:YNKnb2OAApgYn2oYY47Rn7alMr1zWjb2U8Q0aoGWiNc=
3739
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
3840
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=

proto/kms/api/cmk/eventprocessor/task/v1/task.pb.go

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)