common

package
v0.0.0-...-982e07a Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const TimeoutToExit = time.Second

TimeoutToExit timeout for exit operation for SServer component

Variables

View Source
var ErrShutdownAttemptWithoutExit = errors.New("unexpected way to shutdown service")

ErrShutdownAttemptWithoutExit is an error occurred when context cancelled but Exit function is not called

View Source
var ErrTwoDBSetup = errors.New("only one db supported at one time")

ErrTwoDBSetup shows that AcraServer can connects only to one database at the same time

View Source
var ErrWaitTimeout = errors.New("timeout")

ErrWaitTimeout error indicates that server was shutdown and waited N seconds while shutting down all connections.

Functions

func BuildHTTPAPIConnectionWrapper

func BuildHTTPAPIConnectionWrapper(tlsWrapper *network.TLSConnectionWrapper, clientIDFromCert bool, clientID []byte) (network.HTTPServerConnectionWrapper, error)

BuildHTTPAPIConnectionWrapper builds the connection wrapper that will be used by the HTTP API server. If `tlsWrapper` is nil, no TLS protection is used and connections will use the specified clientID. If clientIDFromCert is true, the clientID will be derived from the TLS user certificate. If false, the static clientID will be used.

func NewMetricConnectionCallback

func NewMetricConnectionCallback(connectionType string) *network.MetricConnectionCallback

NewMetricConnectionCallback return initialized MetricConnectionCallback with proper connectionType

func RegisterMetrics

func RegisterMetrics(serviceName string, version *utils.Version, edition utils.ProductEdition)

RegisterMetrics registers AcraServer metrics.

Types

type APICore

type APICore struct {
	// contains filtered or unexported fields
}

APICore contains the API logic of the HTTP API server Is used to decouple the API logic from actual HTTP setting routine In the future could be used to abstract HTTP setting up from API configuring

func NewAPICore

func NewAPICore(ctx context.Context, keystore keystore.ServerKeyStore) APICore

NewAPICore creates new APICore

type ClientSession

type ClientSession struct {
	// contains filtered or unexported fields
}

ClientSession handles connection between database and AcraServer.

func NewClientSession

func NewClientSession(ctx context.Context, config *Config, connection net.Conn) (*ClientSession, error)

NewClientSession creates new ClientSession object.

func (*ClientSession) ClientConnection

func (clientSession *ClientSession) ClientConnection() net.Conn

ClientConnection returns connection to AcraConnector.

func (*ClientSession) Close

func (clientSession *ClientSession) Close()

Close session connections to AcraConnector and database.

func (*ClientSession) ConnectToDb

func (clientSession *ClientSession) ConnectToDb() error

ConnectToDb connects to the database via tcp using Host and Port from config.

func (*ClientSession) Context

func (clientSession *ClientSession) Context() context.Context

Context returns session's context.

func (*ClientSession) DatabaseConnection

func (clientSession *ClientSession) DatabaseConnection() net.Conn

DatabaseConnection returns connection to database. It must be established first by ConnectToDb().

func (*ClientSession) DeleteData

func (clientSession *ClientSession) DeleteData(key string)

DeleteData delete session related data by key

func (*ClientSession) GetData

func (clientSession *ClientSession) GetData(key string) (interface{}, bool)

GetData return session related data by key and true otherwise nil, false

func (*ClientSession) HasData

func (clientSession *ClientSession) HasData(key string) bool

HasData return true if session has data by key

func (*ClientSession) Logger

func (clientSession *ClientSession) Logger() *log.Entry

Logger returns session's logger.

func (*ClientSession) PreparedStatementRegistry

func (clientSession *ClientSession) PreparedStatementRegistry() base.PreparedStatementRegistry

PreparedStatementRegistry returns prepared statement registry of this session. The session does not have a registry by default, it must be set with SetPreparedStatementRegistry.

func (*ClientSession) ProtocolState

func (clientSession *ClientSession) ProtocolState() interface{}

ProtocolState returns private protocol state of this session. The session does not have any state by default, it must be set with SetProtocolState.

func (*ClientSession) SetData

func (clientSession *ClientSession) SetData(key string, data interface{})

SetData save session related data by key

func (*ClientSession) SetPreparedStatementRegistry

func (clientSession *ClientSession) SetPreparedStatementRegistry(registry base.PreparedStatementRegistry)

SetPreparedStatementRegistry sets prepared statement registry for this session.

func (*ClientSession) SetProtocolState

func (clientSession *ClientSession) SetProtocolState(state interface{})

SetProtocolState sets protocol state for this session.

type Config

type Config struct {
	ConnectionWrapper        network.ConnectionWrapper
	HTTPAPIConnectionWrapper network.HTTPServerConnectionWrapper

	TraceToLog bool
	// contains filtered or unexported fields
}

Config describes AcraServer configuration

func NewConfig

func NewConfig() (*Config, error)

NewConfig returns new Config object

func (*Config) DetectPoisonRecords

func (config *Config) DetectPoisonRecords() bool

DetectPoisonRecords returns if AcraServer should detect Poison records

func (*Config) GetAcraAPIConnectionString

func (config *Config) GetAcraAPIConnectionString() string

GetAcraAPIConnectionString returns AcraServer API connection string

func (*Config) GetAcraConnectionString

func (config *Config) GetAcraConnectionString() string

GetAcraConnectionString returns AcraServer data connection string

func (*Config) GetCensor

func (config *Config) GetCensor() acracensor.AcraCensorInterface

GetCensor returns AcraCensor associated with AcraServer

func (*Config) GetConfigPath

func (config *Config) GetConfigPath() string

GetConfigPath returns AcraServer config path

func (*Config) GetDBHost

func (config *Config) GetDBHost() string

GetDBHost returns AcraServer database host

func (*Config) GetDBPort

func (config *Config) GetDBPort() int

GetDBPort returns AcraServer database port

func (*Config) GetDebug

func (config *Config) GetDebug() bool

GetDebug returns if AcraServer should run in debug mode and print debug logs

func (*Config) GetEnableHTTPAPI

func (config *Config) GetEnableHTTPAPI() bool

GetEnableHTTPAPI returns if AcraServer should listen to HTTP commands

func (*Config) GetKeyStore

func (config *Config) GetKeyStore() keystore.ServerKeyStore

GetKeyStore return configure KeyStore

func (*Config) GetSQLDialect

func (config *Config) GetSQLDialect() dialect.Dialect

GetSQLDialect returns MySQL or PostgreSQL dialect depending on the configuration.

func (*Config) GetServiceName

func (config *Config) GetServiceName() string

GetServiceName returns AcraServer service name.

func (*Config) GetStaticClientID

func (config *Config) GetStaticClientID() []byte

GetStaticClientID returns configured static clientID

func (*Config) GetTLSClientIDExtractor

func (config *Config) GetTLSClientIDExtractor() network.TLSClientIDExtractor

GetTLSClientIDExtractor return configured TLSClietIDExtractor

func (*Config) GetTableSchema

func (config *Config) GetTableSchema() encryptorConfig.TableSchemaStore

GetTableSchema returns table schema in use.

func (*Config) GetTraceOptions

func (config *Config) GetTraceOptions() []trace.StartOption

GetTraceOptions return configured trace StartOptions

func (*Config) GetUseClientIDFromCertificate

func (config *Config) GetUseClientIDFromCertificate() bool

GetUseClientIDFromCertificate return is acra-server should use clientID from the certificate

func (*Config) LoadMapTableSchemaConfig

func (config *Config) LoadMapTableSchemaConfig(extractor *args.ServiceExtractor, storageType string, useMySQL bool) error

LoadMapTableSchemaConfig load table schemas from config file

func (*Config) SetAcraAPIConnectionString

func (config *Config) SetAcraAPIConnectionString(str string)

SetAcraAPIConnectionString sets AcraServer API connection string

func (*Config) SetAcraConnectionString

func (config *Config) SetAcraConnectionString(str string)

SetAcraConnectionString sets AcraServer data connection string

func (*Config) SetCensor

func (config *Config) SetCensor(censorConfigPath string) error

SetCensor creates AcraCensor and sets its configuration

func (*Config) SetConfigPath

func (config *Config) SetConfigPath(path string)

SetConfigPath sets AcraServer config path

func (*Config) SetDBConnectionSettings

func (config *Config) SetDBConnectionSettings(host string, port int)

SetDBConnectionSettings sets address of the database.

func (*Config) SetDatabaseType

func (config *Config) SetDatabaseType(mysql, postgresql bool) error

SetDatabaseType set mysql or postgresql, return ErrTwoDBSetup if both true, set postgresql true if both false

func (*Config) SetDebug

func (config *Config) SetDebug(value bool)

SetDebug sets if AcraServer should run in debug mode and print debug logs

func (*Config) SetDetectPoisonRecords

func (config *Config) SetDetectPoisonRecords(val bool)

SetDetectPoisonRecords sets if AcraServer should detect Poison records

func (*Config) SetEnableHTTPAPI

func (config *Config) SetEnableHTTPAPI(api bool)

SetEnableHTTPAPI sets if AcraServer should listen to HTTP commands

func (*Config) SetKeyStore

func (config *Config) SetKeyStore(k keystore.ServerKeyStore)

SetKeyStore sets keystore.

func (*Config) SetScriptOnPoison

func (config *Config) SetScriptOnPoison(script string)

SetScriptOnPoison sets path to script to execute when poison record is triggered.

func (*Config) SetServiceName

func (config *Config) SetServiceName(name string)

SetServiceName sets AcraServer service name.

func (*Config) SetStaticClientID

func (config *Config) SetStaticClientID(clientID []byte) error

SetStaticClientID set clientID to use for all incoming connections with turned off through TLS certificate identification

func (*Config) SetStopOnPoison

func (config *Config) SetStopOnPoison(stop bool)

SetStopOnPoison tells AcraServer to shutdown when poison record is triggered.

func (*Config) SetTLSClientIDExtractor

func (config *Config) SetTLSClientIDExtractor(tlsClientIDExtractor network.TLSClientIDExtractor)

SetTLSClientIDExtractor set clientID extractor from TLS metadata

func (*Config) SetTableSchema

func (config *Config) SetTableSchema(store encryptorConfig.TableSchemaStore)

SetTableSchema set TableSchemaStore

func (*Config) SetUseClientIDFromCertificate

func (config *Config) SetUseClientIDFromCertificate(use bool)

SetUseClientIDFromCertificate set should acra-server use clientID from the certificate or not

func (*Config) UseMySQL

func (config *Config) UseMySQL() bool

UseMySQL returns if AcraServer should connect to MySQL database

func (*Config) UsePostgreSQL

func (config *Config) UsePostgreSQL() bool

UsePostgreSQL returns if AcraServer should connect to PostgreSQL database

type ConnectionContextCallback

type ConnectionContextCallback func(ctx context.Context, c net.Conn) context.Context

ConnectionContextCallback is callback that is called to map context for each connection We use it to set the connection to the context, so it can be use latter (for extracting the clientID for example)

type HTTPAPIServer

type HTTPAPIServer struct {
	// contains filtered or unexported fields
}

HTTPAPIServer handles all HTTP api logic

func NewHTTPAPIServer

func NewHTTPAPIServer(
	ctx context.Context,
	keystore keystore.ServerKeyStore,
	traceOn bool,
	traceOptions []trace.StartOption,
	tlsIDExtractor network.TLSClientIDExtractor,
	connCtxCallback ConnectionContextCallback,
) HTTPAPIServer

NewHTTPAPIServer creates new AcraAPIServer The arguments: - keystore is a keystore operated by the Acra - traceOn controls the tracing. Often provided from the config. - traceOptions - options for the tracer. Often provided from the config. - tlsIDExtractor is used to extract IDs from the TLS connection - connCtxCallback is a callback for setting context for each connection

func (*HTTPAPIServer) InitEngine

func (apiServer *HTTPAPIServer) InitEngine(engine *gin.Engine)

InitEngine configures all path handlers for the API

func (*HTTPAPIServer) Start

func (apiServer *HTTPAPIServer) Start(listener net.Listener, group *sync.WaitGroup) error

Start the server. Blocking operation

type SServer

type SServer struct {
	// contains filtered or unexported fields
}

SServer represents AcraServer server, connects with KeyStorage, configuration file, data and command connections (listeners, managers, file descriptors), and signals.

func NewEEAcraServerMainComponent

func NewEEAcraServerMainComponent(config *Config, proxyFactory base.ProxyFactory, errorChan chan os.Signal, restartChan chan os.Signal) (*SServer, error)

NewEEAcraServerMainComponent creates new SServer wrapper

func (*SServer) Close

func (server *SServer) Close()

Close all listeners and return first error

func (*SServer) ConnectionsCounter

func (server *SServer) ConnectionsCounter() int

ConnectionsCounter counts number of active data and API connections.

func (*SServer) Exit

func (server *SServer) Exit(err error)

Exit exits SServer by sending the input error to the internal channel that is listened in Start function

func (*SServer) ListenerAPI

func (server *SServer) ListenerAPI() net.Listener

ListenerAPI returns listener for AcraServer management API connections.

func (*SServer) ListenerAcra

func (server *SServer) ListenerAcra() net.Listener

ListenerAcra returns listener for AcraServer database connections.

func (*SServer) Start

func (server *SServer) Start(parentContext context.Context)

Start listening connections from proxy

func (*SServer) StartCommands

func (server *SServer) StartCommands(parentContext context.Context)

StartCommands starts listening commands connections from proxy.

func (*SServer) StartCommandsFromFileDescriptor

func (server *SServer) StartCommandsFromFileDescriptor(parentContext context.Context, fd uintptr)

StartCommandsFromFileDescriptor starts listening commands connections from file descriptor.

func (*SServer) StartFromFileDescriptor

func (server *SServer) StartFromFileDescriptor(parentContext context.Context, fd uintptr)

StartFromFileDescriptor starts listening Acra data connections from file descriptor.

func (*SServer) StartServer

func (server *SServer) StartServer(parentContext context.Context, group *sync.WaitGroup, enableHTTPApi bool) error

StartServer starts SServer

func (*SServer) StartServerFromFileDescriptor

func (server *SServer) StartServerFromFileDescriptor(parentContext context.Context, group *sync.WaitGroup, enableHTTPApi bool, fdAcra, fdAPI uintptr) error

StartServerFromFileDescriptor starts SServer with appropriate file descriptors

func (*SServer) StopListeners

func (server *SServer) StopListeners()

StopListeners stops accepts new connections, and stops existing listeners with deadline.

func (*SServer) WaitConnections

func (server *SServer) WaitConnections(duration time.Duration)

WaitConnections waits until connection complete or stops them after duration time.

func (*SServer) WaitWithTimeout

func (server *SServer) WaitWithTimeout(duration time.Duration) error

WaitWithTimeout waits until connection complete or stops them after duration time.

Jump to

Keyboard shortcuts

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