The official Go SDK for the Kessel inventory and authorization service. This SDK provides gRPC client implementation for secure communication.
- gRPC client support - High-performance gRPC communication
- Type-safe API - Generated from protobuf definitions
- Production ready - Built with security, performance, and reliability in mind
go get github.com/project-kessel/kessel-sdk-gopackage main
import (
"context"
"fmt"
"log"
"github.com/project-kessel/kessel-sdk-go/kessel/config"
v1beta2 "github.com/project-kessel/kessel-sdk-go/kessel/inventory/v1beta2"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/status"
)
func main() {
ctx := context.Background()
grpcConfig := config.NewCompatibilityConfig(
config.WithGRPCEndpoint("your-kessel-server:9000"),
config.WithGRPCInsecure(true),
)
// Using insecure credentials for local development
var dialOpts []grpc.DialOption
dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
dialOpts = append(dialOpts,
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(grpcConfig.MaxReceiveMessageSize)),
grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(grpcConfig.MaxSendMessageSize)),
)
conn, err := grpc.NewClient(grpcConfig.Url, dialOpts...)
if err != nil {
log.Fatal("Failed to create gRPC client:", err)
}
defer func() {
if closeErr := conn.Close(); closeErr != nil {
log.Printf("Failed to close gRPC client: %v", closeErr)
}
}()
inventoryClient := v1beta2.NewKesselInventoryServiceClient(conn)
// Example request using the external API types
checkRequest := &v1beta2.CheckRequest{
Object: &v1beta2.ResourceReference{
ResourceType: "host",
ResourceId: "server-123",
Reporter: &v1beta2.ReporterReference{
Type: "HBI",
},
},
Relation: "member",
Subject: &v1beta2.SubjectReference{
Resource: &v1beta2.ResourceReference{
ResourceType: "user",
ResourceId: "alice",
},
},
}
response, err := inventoryClient.Check(ctx, checkRequest)
if err != nil {
if st, ok := status.FromError(err); ok {
switch st.Code() {
case codes.Unavailable:
log.Fatal("Service unavailable: ", err)
case codes.PermissionDenied:
log.Fatal("Permission denied: ", err)
default:
log.Fatal("gRPC connection error: ", err)
}
} else {
log.Fatal("Unknown error: ", err)
}
}
log.Printf("Check result: %v", response.Allowed)
}Specify the gRPC endpoint:
grpcConfig := config.NewCompatibilityConfig(
config.WithGRPCEndpoint("your-kessel-server:9000"),
config.WithGRPCInsecure(true),
)The SDK uses standard gRPC status codes:
response, err := inventoryClient.Check(ctx, checkRequest)
if err != nil {
if st, ok := status.FromError(err); ok {
switch st.Code() {
case codes.Unavailable:
log.Fatal("Service unavailable:", err)
case codes.PermissionDenied:
log.Fatal("Permission denied:", err)
default:
log.Fatal("gRPC connection error:", err)
}
} else {
log.Fatal("Unknown error:", err)
}
}Complete examples are available in the examples/ directory:
examples/grpc/main.go- gRPC client usage
To run the examples:
# Build examples
make build
# Run gRPC example
./bin/grpc-example- Go 1.23 or later
- Docker or Podman (for linting)
- Protocol Buffers compiler (for code generation)
# Install dependencies
go mod download
# Run linting
make lint
# Run tests
make test
# Build examples
make build
# Run tests with coverage
make test-coverage| Target | Description |
|---|---|
make help |
Display all available targets |
This section provides step-by-step instructions for maintainers to release a new version of the Kessel SDK for Go.
This project follows Semantic Versioning 2.0.0. Version numbers use the format MAJOR.MINOR.PATCH:
- MAJOR: Increment for incompatible API changes
- MINOR: Increment for backward-compatible functionality additions
- PATCH: Increment for backward-compatible bug fixes
Note: SDK versions across different languages (Ruby, Python, Go, etc.) do not need to be synchronized. Each language SDK can evolve independently based on its specific requirements and release schedule.
- Write access to the GitHub repository
- Ensure quality checks are passing
- Review and update CHANGELOG or release notes as needed
- Go 1.23 or higher
- buf for protobuf/gRPC code generation:
# On macOS brew install bufbuild/buf/buf # On Linux curl -sSL "https://github.com/bufbuild/buf/releases/latest/download/buf-$(uname -s)-$(uname -m)" -o "/usr/local/bin/buf" && chmod +x "/usr/local/bin/buf"
- Update Dependencies (if needed)
# Regenerate gRPC code if there are updates to the Kessel Inventory API
make generate- Run Quality Checks
# Run linting
make lint
# Run tests
make test
# Build examples
make build- Tag the Release
# Create and push a git tag
git tag -a vX.Y.Z -m "Release version X.Y.Z"
git push origin vX.Y.Z- Create GitHub Release
- Go to the GitHub Releases page
- Click "Create a new release"
- Select the tag you just created
- Add release notes describing the changes
- Publish the release
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.