Skip to content
Open
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
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ require (
go.fd.io/govpp/extras v0.1.1-0.20261019084134-c02eb51f8588
golang.org/x/net v0.61.0
golang.org/x/sys v0.49.0
google.golang.org/genproto/googleapis/api v0.0.0-20261026165753-2ffab32bce7e
google.golang.org/grpc v1.84.0
google.golang.org/genproto/googleapis/api v0.0.0-20261104224025-d1e00e9f33ab
google.golang.org/grpc v1.85.0
google.golang.org/protobuf v1.36.12
modernc.org/sqlite v1.61.0
)
Expand All @@ -27,6 +27,7 @@ require (
github.com/miekg/dns v1.1.73
github.com/onsi/ginkgo/v2 v2.34.0
github.com/onsi/gomega v1.44.0
github.com/voidstarit/kouja v0.0.0-20261107022657-5dd27b7c76f0
)

require (
Expand Down Expand Up @@ -58,7 +59,7 @@ require (
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
golang.org/x/mod v0.42.0 // indirect
golang.org/x/sync v0.24.0 // indirect
golang.org/x/time v0.7.0 // indirect
golang.org/x/time v0.15.0 // indirect
golang.org/x/tools v0.52.0 // indirect
)

Expand Down Expand Up @@ -92,7 +93,7 @@ require (
golang.org/x/crypto v0.58.0 // indirect
golang.org/x/term v0.47.0 // indirect
golang.org/x/text v0.43.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20261019180522-ce908d29299b // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20261019180522-ce908d29299b
gvisor.dev/gvisor v0.0.0-20250503011706-39ed1f5ac29c
modernc.org/libc v1.79.0 // indirect
modernc.org/mathutil v1.7.1 // indirect
Expand Down
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IU
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
github.com/voidstarit/kouja v0.0.0-20261107022657-5dd27b7c76f0 h1:+HjRG4ohgOVq3+lfXC1tVUtAW4bT8C+AbtapkIoHBjY=
github.com/voidstarit/kouja v0.0.0-20261107022657-5dd27b7c76f0/go.mod h1:SjdnoRUyB7vwAmvs3fVU/XIPzqYdt2hQ0C4RULcftxM=
github.com/x-cray/logrus-prefixed-formatter v0.5.2 h1:00txxvfBM9muc0jiLIEAkAcIMJzfthRT6usrui8uGmg=
github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7VPsoEPHyzalCE06qoARUCeBBE=
go.fd.io/govpp v0.13.0 h1:MnjH9I5K+X0860CeeuBcMSu3uyUKA6X9AenKzdiGpnA=
Expand Down Expand Up @@ -230,20 +232,20 @@ golang.org/x/term v0.47.0/go.mod h1:efAfAuG6RKABvg1ArGebRkvX6LXul14SM67o2e4mUCY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.43.0 h1:1QivrlhwAsnMOcqgOdl9my7s9OyZl8O5/UGUTJVXoWc=
golang.org/x/text v0.43.0/go.mod h1:hbSIYA/amXcRXTFSZqh8tWHEoqRvvbKPJ2uz/KU+a+s=
golang.org/x/time v0.7.0 h1:ntUhktv3OPE6TgYxXWv9vKvUSJyIFJlyohwbkEwPrKQ=
golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U=
golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.52.0 h1:ryxg4U63oaUYk7uOLTF37n43f4qgtGvqV4Ioit1BaEs=
golang.org/x/tools v0.52.0/go.mod h1:ItcP5UNaVGG+Yc4eIYmaFLNJ4soEopkx5Y2d4lcEurs=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4=
gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E=
google.golang.org/genproto/googleapis/api v0.0.0-20261026165753-2ffab32bce7e h1:e789sLZjeTdc02ZCQGTSzHOu0fR73+dwPQVKUp67Z88=
google.golang.org/genproto/googleapis/api v0.0.0-20261026165753-2ffab32bce7e/go.mod h1:vHV3wJM9WZyfV7GyB+OQGq5dWVrFwCDxapPK4WlRD88=
google.golang.org/genproto/googleapis/api v0.0.0-20261104224025-d1e00e9f33ab h1:n6IDWZ1RzI/NberLoLLFNrjl1H45uhc4+WYsUf5lPPc=
google.golang.org/genproto/googleapis/api v0.0.0-20261104224025-d1e00e9f33ab/go.mod h1:vHV3wJM9WZyfV7GyB+OQGq5dWVrFwCDxapPK4WlRD88=
google.golang.org/genproto/googleapis/rpc v0.0.0-20261019180522-ce908d29299b h1:6WNWHZk91dp4gZ25642OALkuG1UVNZbwENJD19DnB8k=
google.golang.org/genproto/googleapis/rpc v0.0.0-20261019180522-ce908d29299b/go.mod h1:OaIUM3+LpYcK2GXM4FTmhWoIq371Owdr+Cc7/BsYHHc=
google.golang.org/grpc v1.84.0 h1:soMyaPJ8pAak5PIQ0DGBUir0XRo2fRoMqhNWMLlLxO0=
google.golang.org/grpc v1.84.0/go.mod h1:ljCht0DrxQrXBDRTZp52Qxh3Ffk8CdYm2sj4O2QN2C0=
google.golang.org/grpc v1.85.0 h1:BPBCfuVRQ1qvBhKDOq9uvQllMvO59rKsYhXpp7Dd8vw=
google.golang.org/grpc v1.85.0/go.mod h1:0rQrOD58yjal/0EaVbGBANindixsCZNQPDV3VKtaKuQ=
google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc=
google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
76 changes: 76 additions & 0 deletions internal/kouja/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package kouja

import (
"context"

koujacli "github.com/voidstarit/kouja/gen/client"
koujav1 "github.com/voidstarit/kouja/gen/kouja/v1"
"google.golang.org/grpc"

"github.com/voidstarit/rookery/internal/store"
)

// API is the subset of the kouja VolumeService used by Rookery.
type API interface {
CreateVolume(context.Context, *koujav1.CreateVolumeRequest, ...grpc.CallOption) (*koujav1.CreateVolumeResponse, error)
GetVolume(context.Context, *koujav1.GetVolumeRequest, ...grpc.CallOption) (*koujav1.GetVolumeResponse, error)
GetCredential(context.Context, *koujav1.GetCredentialRequest, ...grpc.CallOption) (*koujav1.GetCredentialResponse, error)
UnexportVolume(context.Context, *koujav1.UnexportVolumeRequest, ...grpc.CallOption) (*koujav1.UnexportVolumeResponse, error)
DeleteVolume(context.Context, *koujav1.DeleteVolumeRequest, ...grpc.CallOption) (*koujav1.DeleteVolumeResponse, error)
GetInfo(context.Context, *koujav1.GetInfoRequest, ...grpc.CallOption) (*koujav1.GetInfoResponse, error)
ListStorageClasses(context.Context, *koujav1.ListStorageClassesRequest, ...grpc.CallOption) (*koujav1.ListStorageClassesResponse, error)
}

// Client is a kouja VolumeService client with an owned connection.
type Client struct {
API
close func() error
}

// NewClient creates a kouja mTLS client for cfg.
func NewClient(cfg Config) (*Client, error) {
tlsConfig, err := koujacli.LoadTLSConfig(cfg.ClientCertFile, cfg.ClientKeyFile, cfg.CAFile)
if err != nil {
return nil, err
}
if cfg.ServerName != "" {
tlsConfig.ServerName = cfg.ServerName
}
grpcClient, err := koujacli.NewGRPC(cfg.Endpoint, tlsConfig)
if err != nil {
return nil, err
}
return &Client{API: grpcClient, close: grpcClient.Close}, nil
}

// NewClientFromService wraps an existing service client. It is intended for
// tests and for callers that own the gRPC connection.
func NewClientFromService(service API) *Client {
return &Client{API: service}
}

// Close closes the owned gRPC connection, if any.
func (c *Client) Close() error {
if c == nil || c.close == nil {
return nil
}
return c.close()
}

// Factory builds a client per backend. It never shares a connection between
// backends with different endpoints or certificate identities.
type Factory struct{}

// New constructs a client for a backend.
func (Factory) New(backend store.StorageBackend) (*Client, error) {
cfg, err := ParseBackend(backend)
if err != nil {
return nil, err
}
return NewClient(cfg)
}

// NewClientForBackend is a convenience wrapper around Factory.New.
func NewClientForBackend(backend store.StorageBackend) (*Client, error) {
return Factory{}.New(backend)
}
65 changes: 65 additions & 0 deletions internal/kouja/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package kouja

import (
"testing"

"github.com/voidstarit/rookery/internal/store"
)

func TestNewClientAndFactory(t *testing.T) {
cfg, err := ParseConfig(testKoujaConfig(t))
if err != nil {
t.Fatal(err)
}
client, err := NewClient(cfg)
if err != nil {
t.Fatalf("NewClient() = %v", err)
}
if client.API == nil {
t.Fatal("NewClient() returned a nil API")
}
if err := client.Close(); err != nil {
t.Fatalf("Close() = %v", err)
}

backend := store.StorageBackend{Config: testKoujaConfig(t)}
factoryClient, err := Factory{}.New(backend)
if err != nil {
t.Fatalf("Factory.New() = %v", err)
}
if err := factoryClient.Close(); err != nil {
t.Fatal(err)
}
convenience, err := NewClientForBackend(backend)
if err != nil {
t.Fatal(err)
}
if err := convenience.Close(); err != nil {
t.Fatal(err)
}
}

func TestNewClientFromServiceAndNilClose(t *testing.T) {
client := NewClientFromService(&fakeAPI{})
if client == nil || client.API == nil {
t.Fatal("NewClientFromService() returned nil")
}
if err := client.Close(); err != nil {
t.Fatal(err)
}
var nilClient *Client
if err := nilClient.Close(); err != nil {
t.Fatal(err)
}
}

func TestNewClientInvalidTLS(t *testing.T) {
cfg := Config{
Endpoint: "10.0.0.1:9443",
CAFile: "/does/not/exist/ca.crt", ClientCertFile: "/does/not/exist/client.crt",
ClientKeyFile: "/does/not/exist/client.key",
}
if _, err := NewClient(cfg); err == nil {
t.Fatal("NewClient() accepted missing TLS files")
}
}
Loading
Loading