Documentation
¶
Overview ¶
Package grpc is a generated GoMock package.
Package grpc pkg/grpc/server.go
Index ¶
- Constants
- func GenerateTestCertificates(dir string) error
- func LoggingInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, ...) (interface{}, error)
- func RecoveryInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, ...) (resp interface{}, err error)
- func RetryInterceptor(maxRetries int) grpc.UnaryClientInterceptor
- type CertificateManager
- type Client
- type ClientConfig
- type MTLSProvider
- type MockSecurityProvider
- func (m *MockSecurityProvider) Close() error
- func (m *MockSecurityProvider) EXPECT() *MockSecurityProviderMockRecorder
- func (m *MockSecurityProvider) GetClientCredentials(ctx context.Context) (grpc.DialOption, error)
- func (m *MockSecurityProvider) GetServerCredentials(ctx context.Context) (grpc.ServerOption, error)
- type MockSecurityProviderMockRecorder
- type NoSecurityProvider
- type SecurityProvider
- type Server
- type ServerOption
- type SpiffeProvider
Constants ¶
const ( SecurityModeNone models.SecurityMode = "none" SecurityModeSpiffe models.SecurityMode = "spiffe" SecurityModeMTLS models.SecurityMode = "mtls" )
Variables ¶
This section is empty.
Functions ¶
func GenerateTestCertificates ¶
GenerateTestCertificates creates a CA, server, and client certificates in the specified directory. Generates: root.pem (CA), server.pem (server auth), client.pem (client auth).
func LoggingInterceptor ¶
func LoggingInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)
LoggingInterceptor logs RPC calls.
func RecoveryInterceptor ¶
func RecoveryInterceptor( ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error)
RecoveryInterceptor handles panics in RPC handlers.
func RetryInterceptor ¶
func RetryInterceptor(maxRetries int) grpc.UnaryClientInterceptor
RetryInterceptor provides basic retry logic.
Types ¶
type CertificateManager ¶
type CertificateManager struct {
// contains filtered or unexported fields
}
CertificateManager helps manage TLS certificates.
func NewCertificateManager ¶
func NewCertificateManager(config *models.SecurityConfig) *CertificateManager
func (*CertificateManager) EnsureCertificateDirectory ¶
func (cm *CertificateManager) EnsureCertificateDirectory() error
func (*CertificateManager) ValidateCertificates ¶
func (cm *CertificateManager) ValidateCertificates(mutual bool) error
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client manages a gRPC client connection.
func NewClient ¶
func NewClient(ctx context.Context, cfg ClientConfig) (*Client, error)
NewClient creates a new gRPC client.
func (*Client) CheckHealth ¶
CheckHealth performs a health check on the specified service.
func (*Client) GetConnection ¶
func (c *Client) GetConnection() *grpc.ClientConn
GetConnection returns the underlying gRPC connection.
type ClientConfig ¶
type ClientConfig struct { Address string SecurityProvider SecurityProvider MaxRetries int }
ClientConfig holds configuration for the gRPC client.
type MTLSProvider ¶
type MTLSProvider struct {
// contains filtered or unexported fields
}
MTLSProvider implements SecurityProvider with mutual TLS.
func NewMTLSProvider ¶
func NewMTLSProvider(config *models.SecurityConfig) (*MTLSProvider, error)
NewMTLSProvider creates a new MTLSProvider with the given configuration.
func (*MTLSProvider) Close ¶
func (p *MTLSProvider) Close() error
func (*MTLSProvider) GetClientCredentials ¶
func (p *MTLSProvider) GetClientCredentials(_ context.Context) (grpc.DialOption, error)
func (*MTLSProvider) GetServerCredentials ¶
func (p *MTLSProvider) GetServerCredentials(_ context.Context) (grpc.ServerOption, error)
type MockSecurityProvider ¶
type MockSecurityProvider struct {
// contains filtered or unexported fields
}
MockSecurityProvider is a mock of SecurityProvider interface.
func NewMockSecurityProvider ¶
func NewMockSecurityProvider(ctrl *gomock.Controller) *MockSecurityProvider
NewMockSecurityProvider creates a new mock instance.
func (*MockSecurityProvider) Close ¶
func (m *MockSecurityProvider) Close() error
Close mocks base method.
func (*MockSecurityProvider) EXPECT ¶
func (m *MockSecurityProvider) EXPECT() *MockSecurityProviderMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockSecurityProvider) GetClientCredentials ¶
func (m *MockSecurityProvider) GetClientCredentials(ctx context.Context) (grpc.DialOption, error)
GetClientCredentials mocks base method.
func (*MockSecurityProvider) GetServerCredentials ¶
func (m *MockSecurityProvider) GetServerCredentials(ctx context.Context) (grpc.ServerOption, error)
GetServerCredentials mocks base method.
type MockSecurityProviderMockRecorder ¶
type MockSecurityProviderMockRecorder struct {
// contains filtered or unexported fields
}
MockSecurityProviderMockRecorder is the mock recorder for MockSecurityProvider.
func (*MockSecurityProviderMockRecorder) Close ¶
func (mr *MockSecurityProviderMockRecorder) Close() *gomock.Call
Close indicates an expected call of Close.
func (*MockSecurityProviderMockRecorder) GetClientCredentials ¶
func (mr *MockSecurityProviderMockRecorder) GetClientCredentials(ctx any) *gomock.Call
GetClientCredentials indicates an expected call of GetClientCredentials.
func (*MockSecurityProviderMockRecorder) GetServerCredentials ¶
func (mr *MockSecurityProviderMockRecorder) GetServerCredentials(ctx any) *gomock.Call
GetServerCredentials indicates an expected call of GetServerCredentials.
type NoSecurityProvider ¶
type NoSecurityProvider struct{}
NoSecurityProvider implements SecurityProvider with no security (development only).
func (*NoSecurityProvider) Close ¶
func (*NoSecurityProvider) Close() error
func (*NoSecurityProvider) GetClientCredentials ¶
func (*NoSecurityProvider) GetClientCredentials(context.Context) (grpc.DialOption, error)
func (*NoSecurityProvider) GetServerCredentials ¶
func (*NoSecurityProvider) GetServerCredentials(context.Context) (grpc.ServerOption, error)
type SecurityProvider ¶
type SecurityProvider interface { // GetClientCredentials returns credentials for client connections GetClientCredentials(ctx context.Context) (grpc.DialOption, error) // GetServerCredentials returns credentials for server connections GetServerCredentials(ctx context.Context) (grpc.ServerOption, error) // Close cleans up any resources Close() error }
SecurityProvider defines the interface for gRPC security providers.
func NewSecurityProvider ¶
func NewSecurityProvider(ctx context.Context, config *models.SecurityConfig) (SecurityProvider, error)
NewSecurityProvider creates the appropriate security provider based on mode.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server wraps a gRPC server with additional functionality.
func NewServer ¶
func NewServer(addr string, opts ...ServerOption) *Server
NewServer creates a new gRPC server with the given configuration.
func (*Server) GetGRPCServer ¶
GetGRPCServer returns the underlying gRPC server.
func (*Server) GetHealthCheck ¶
GetHealthCheck returns the health server instance.
func (*Server) RegisterHealthServer ¶
RegisterHealthServer registers the health server if not already registered.
func (*Server) RegisterService ¶
func (s *Server) RegisterService(desc *grpc.ServiceDesc, impl interface{})
RegisterService registers a service with the gRPC server.
type ServerOption ¶
type ServerOption func(*Server)
ServerOption is a function type that modifies Server configuration.
func WithMaxRecvSize ¶
func WithMaxRecvSize(size int) ServerOption
WithMaxRecvSize sets the maximum receive message size.
func WithMaxSendSize ¶
func WithMaxSendSize(size int) ServerOption
WithMaxSendSize sets the maximum send message size.
func WithServerOptions ¶
func WithServerOptions(opt ...grpc.ServerOption) ServerOption
WithServerOptions adds gRPC server options.
type SpiffeProvider ¶
type SpiffeProvider struct {
// contains filtered or unexported fields
}
SpiffeProvider implements SecurityProvider using SPIFFE workload API.
func NewSpiffeProvider ¶
func NewSpiffeProvider(ctx context.Context, config *models.SecurityConfig) (*SpiffeProvider, error)
func (*SpiffeProvider) Close ¶
func (p *SpiffeProvider) Close() error
func (*SpiffeProvider) GetClientCredentials ¶
func (p *SpiffeProvider) GetClientCredentials(_ context.Context) (grpc.DialOption, error)
func (*SpiffeProvider) GetServerCredentials ¶
func (p *SpiffeProvider) GetServerCredentials(_ context.Context) (grpc.ServerOption, error)