server

package
v0.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package server contains the gRPC server implementation.

Copyright (c) Ultraviolet SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAppendServerCA = errors.New("failed to append server ca to tls.Config")
	ErrAppendClientCA = errors.New("failed to append client ca to tls.Config")
)

Functions

func BuildMTLSDescription

func BuildMTLSDescription(serverCAFile, clientCAFile string) string

BuildMTLSDescription builds a description string for mTLS configuration.

func ConfigureCertificateAuthorities

func ConfigureCertificateAuthorities(tlsConfig *tls.Config, serverCAFile, clientCAFile string) (bool, error)

ConfigureCertificateAuthorities configures both root and client CAs for the TLS config Returns true if mTLS should be enabled (client CA is configured).

func ConfigureClientCA

func ConfigureClientCA(tlsConfig *tls.Config, clientCAFile string) (bool, error)

ConfigureClientCA configures the client CA certificates for the TLS config Returns true if client CA was configured, false otherwise.

func ConfigureRootCA

func ConfigureRootCA(tlsConfig *tls.Config, serverCAFile string) error

ConfigureRootCA configures the root CA certificates for the TLS config.

func LoadCertFile

func LoadCertFile(certFile string) ([]byte, error)

LoadCertFile loads certificate data from file path or returns empty byte slice if path is empty.

func LoadX509KeyPair

func LoadX509KeyPair(certfile, keyfile string) (tls.Certificate, error)

LoadX509KeyPair loads X.509 key pair from certificate and key files or data.

func ReadFileOrData

func ReadFileOrData(input string) ([]byte, error)

ReadFileOrData reads data from file if input looks like a file path, otherwise treats input as raw data.

func StopHandler

func StopHandler(ctx context.Context, cancel context.CancelFunc, logger *slog.Logger, svcName string, servers ...Server) error

Types

type AgentConfig

type AgentConfig struct {
	ServerConfig
	AttestedTLS bool `env:"ATTESTED_TLS"       envDefault:"false"`
}

func (AgentConfig) GetBaseConfig

func (a AgentConfig) GetBaseConfig() ServerConfig

type BaseServer

type BaseServer struct {
	Ctx      context.Context
	Cancel   context.CancelFunc
	Name     string
	Address  string
	Config   ServerConfiguration
	Logger   *slog.Logger
	Protocol string
}

func NewBaseServer

func NewBaseServer(
	ctx context.Context, cancel context.CancelFunc, name string, config ServerConfiguration, logger *slog.Logger,
) BaseServer

type Config

type Config struct {
	Host         string `env:"HOST"               envDefault:"localhost"`
	Port         string `env:"PORT"               envDefault:"7001"`
	ServerCAFile string `env:"SERVER_CA_CERTS"    envDefault:""`
	CertFile     string `env:"SERVER_CERT"        envDefault:""`
	KeyFile      string `env:"SERVER_KEY"         envDefault:""`
	ClientCAFile string `env:"CLIENT_CA_CERTS"    envDefault:""`
}

type Server

type Server interface {
	Start() error
	Stop() error
}

type ServerConfig

type ServerConfig struct {
	Config
}

func (ServerConfig) GetBaseConfig

func (s ServerConfig) GetBaseConfig() ServerConfig

type ServerConfiguration

type ServerConfiguration interface {
	GetBaseConfig() ServerConfig
}

type TLSSetupResult

type TLSSetupResult struct {
	Config *tls.Config
	MTLS   bool
}

TLSSetupResult contains the result of TLS configuration setup.

func SetupRegularTLS

func SetupRegularTLS(certFile, keyFile, serverCAFile, clientCAFile string) (*TLSSetupResult, error)

SetupRegularTLS sets up TLS configuration using regular certificates.

Directories

Path Synopsis
Package grpc contains the gRPC server implementation.
Package grpc contains the gRPC server implementation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL