Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 40 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,50 @@
.PHONY: generate
generate: fetch-protos format go-gen

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

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

init-git-hooks:
git config --local core.hooksPath .githooks/
.PHONY: go-gen
go-gen: clean
@find ./proto -type f -iname '*.proto' -exec \
protoc -I./proto -I./vendor-proto \
--go_out=./proto \
--go_opt=paths=import \
--go_opt=module=github.com/openkcm/api-sdk/proto \
--go-grpc_out=./proto \
--go-grpc_opt=paths=import \
--go-grpc_opt=module=github.com/openkcm/api-sdk/proto \
{} +
@go mod tidy

buf-gen: init-git-hooks
buf dep update
./buf.gen.yaml
.PHONY: install-tools
install-tools:
brew install protobuf
go install \
google.golang.org/protobuf/cmd/protoc-gen-go@latest \
google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
brew install bufbuild/buf/buf
npm install -g @coralogix/protofetch

format: buf-gen
buf format -w
.PHONY: validate
validate: format lint breaking

.PHONY: test
test:
go test -race -coverprofile cover.out ./...
# On a Mac, you can use the following command to open the coverage report in the browser
# go tool cover -html=cover.out -o cover.html && open cover.html
.PHONY: lint
lint:
@buf lint

.PHONY: breaking
breaking:
@buf breaking --against https://github.com/openkcm/api-sdk.git#branch=main

.PHONY: format
format:
@buf format -w

.PHONY: reuse-lint
reuse-lint:
Expand Down
71 changes: 56 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,77 @@

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

## Generate protobuf code
## Pre-requisites

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

```sh
brew install bufbuild/buf/buf
1. **`protoc compiler`**: see the instruction on the official [web site](https://protobuf.dev/installation) or install using homebrew `brew install protobuf`.
2. **`protoc-gen-go`**: install via `go install google.golang.org/protobuf/cmd/protoc-gen-go@latest`.
3. **`protoc-gen-go-grpc`**: install via `go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest`.
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.

## Optional tools

Optionally, the [`buf` CLI](https://github.com/bufbuild/buf) tool can be used to validate, detect breaking changes, and format `.proto` files:

- **`buf breaking --against https://github.com/openkcm/api-sdk.git#branch=main`**: detect breaking changes against the main branch of the remote repository.
- **`buf format -w`**: format `.proto` files.
- **`buf lint`**: lint `.proto` files.

## Makefile

There are several `make` targets defined in the `Makefile`:

- **`fetch-protos`**: download `.proto` dependencies using `protofetch`.
- **`generate`**: fetches `.proto` dependencies, formats `.proto` files, and generates Go code.
- **`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.
- **`validate`**: formats and lints `.proto` files, detects breaking changes.

For the rest `make` targets see `Makefile`.

## Dependencies

`.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.

For instance, a dependency on the [`protovalidate`](https://github.com/bufbuild/protovalidate) proto definitions can be specified as follow:

``` toml
name = "github.com/openkcm/api-sdk"
description = "API proto definitions and Go generated code used in the openkcm project"

[protovalidate]
url = "github.com/bufbuild/protovalidate"
revision = "v1.1.1"
content_roots = ["/proto/protovalidate"]
allow_policies = ["buf/validate/*"]
```

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

```sh
make generate
``` sh
$ protofetch -o vendor-proto fetch
```

---
## Generate Go code from the .proto definitions

The code can be generated with executing the following Make target

```sh
$ make generate
```

## Using a specific branch

Ensure that the GOPRIVATE environment variable is set up:

```sh
go env -w GOPRIVATE="github.com/*"
```
```sh
$ go env -w GOPRIVATE="github.com/openkcm/*"
```

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

> go get github.com/openkcm/api-sdk/proto/kms/api/cmk/registry/system/v1@<branch-name>
> go get github.com/openkcm/api-sdk/proto/kms/api/cmk/registry/system/v1@\<branch-name\>

To switch back to the default branch, follow these steps:

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

```sh
go mod tidy
$ go mod tidy
```

## Support, Feedback, Contributing
Expand Down
23 changes: 0 additions & 23 deletions buf.gen.yaml

This file was deleted.

3 changes: 3 additions & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
version: v2
modules:
- path: proto
- path: vendor-proto
lint:
use:
- STANDARD
ignore:
- vendor-proto
ignore_only:
# To not break existing APIs.
ENUM_FIRST_VALUE_ZERO:
Expand Down
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ module github.com/openkcm/api-sdk

go 1.24.2

tool (
google.golang.org/grpc/cmd/protoc-gen-go-grpc
google.golang.org/protobuf/cmd/protoc-gen-go
)

require (
google.golang.org/grpc v1.80.0
google.golang.org/protobuf v1.36.11
Expand All @@ -12,4 +17,5 @@ require (
golang.org/x/sys v0.40.0 // indirect
golang.org/x/text v0.33.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260120221211-b8f7ae30c516 // indirect
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.6.1 // indirect
Comment thread
alienvspredator marked this conversation as resolved.
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20260120221211-b8f7ae30c516 h1:
google.golang.org/genproto/googleapis/rpc v0.0.0-20260120221211-b8f7ae30c516/go.mod h1:j9x/tPzZkyxcgEFkiKEEGxfvyumM01BEtsW8xzOahRQ=
google.golang.org/grpc v1.80.0 h1:Xr6m2WmWZLETvUNvIUmeD5OAagMw3FiKmMlTdViWsHM=
google.golang.org/grpc v1.80.0/go.mod h1:ho/dLnxwi3EDJA4Zghp7k2Ec1+c2jqup0bFkw07bwF4=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.6.1 h1:/WILD1UcXj/ujCxgoL/DvRgt2CP3txG8+FwkUbb9110=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.6.1/go.mod h1:YNKnb2OAApgYn2oYY47Rn7alMr1zWjb2U8Q0aoGWiNc=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
5 changes: 2 additions & 3 deletions proto/kms/api/cmk/eventprocessor/task/v1/task.pb.go

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

Loading
Loading