client

package
Version: v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2022 License: Apache-2.0 Imports: 42 Imported by: 12

Documentation

Overview

Copyright 2022 CodeNotary, Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2022 CodeNotary, Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const AdminTokenFileSuffix = "_admin"

AdminTokenFileSuffix is the suffix used for the token file name

View Source
const DefaultDB = "defaultdb"
View Source
const SQLPrefix byte = 2

Variables

View Source
var (
	ErrIllegalArguments = errors.New("illegal arguments")

	ErrAlreadyConnected   = errors.New("already connected")
	ErrNotConnected       = errors.New("not connected")
	ErrHealthCheckFailed  = errors.New("health check failed")
	ErrServerStateIsOlder = errors.New("server state is older than the client one")
	ErrSessionAlreadyOpen = errors.New("session already opened")
)

Errors related to Client connection and health check

View Source
var (
	ErrSrvIllegalArguments   = status.Error(codes.InvalidArgument, "illegal arguments")
	ErrSrvIllegalState       = status.Error(codes.InvalidArgument, "illegal state")
	ErrSrvEmptyAdminPassword = status.Error(codes.InvalidArgument, "Admin password cannot be empty")
	ErrWriteOnlyTXNotAllowed = status.Error(codes.InvalidArgument, "write only transaction not allowed")
)

Server errors mapping

Functions

func NewClient added in v1.2.0

func NewClient() *immuClient

NewClient ...

func NewImmuClient

func NewImmuClient(options *Options) (*immuClient, error)

NewImmuClient ... Deprecated: use NewClient instead.

Types

type ImmuClient

type ImmuClient interface {
	Disconnect() error
	IsConnected() bool
	// Deprecated: grpc retry mechanism can be implemented with WithConnectParams dialOption
	WaitForHealthCheck(ctx context.Context) (err error)
	HealthCheck(ctx context.Context) error
	// Deprecated: connection is handled in OpenSession
	Connect(ctx context.Context) (clientConn *grpc.ClientConn, err error)

	// Deprecated: use OpenSession
	Login(ctx context.Context, user []byte, pass []byte) (*schema.LoginResponse, error)
	// Deprecated: use CloseSession
	Logout(ctx context.Context) error

	OpenSession(ctx context.Context, user []byte, pass []byte, database string) (err error)
	CloseSession(ctx context.Context) error

	CreateUser(ctx context.Context, user []byte, pass []byte, permission uint32, databasename string) error
	ListUsers(ctx context.Context) (*schema.UserList, error)
	ChangePassword(ctx context.Context, user []byte, oldPass []byte, newPass []byte) error
	ChangePermission(ctx context.Context, action schema.PermissionAction, username string, database string, permissions uint32) error
	// Deprecated: will be removed in future versions
	UpdateAuthConfig(ctx context.Context, kind auth.Kind) error
	// Deprecated: will be removed in future versions
	UpdateMTLSConfig(ctx context.Context, enabled bool) error

	WithOptions(options *Options) *immuClient
	WithLogger(logger logger.Logger) *immuClient
	WithStateService(rs state.StateService) *immuClient
	// Deprecated: will be removed in future versions
	WithClientConn(clientConn *grpc.ClientConn) *immuClient
	// Deprecated: will be removed in future versions
	WithServiceClient(serviceClient schema.ImmuServiceClient) *immuClient
	WithTokenService(tokenService tokenservice.TokenService) *immuClient
	WithServerSigningPubKey(serverSigningPubKey *ecdsa.PublicKey) *immuClient
	WithStreamServiceFactory(ssf stream.ServiceFactory) *immuClient

	GetServiceClient() schema.ImmuServiceClient
	GetOptions() *Options
	SetupDialOptions(options *Options) []grpc.DialOption

	DatabaseList(ctx context.Context) (*schema.DatabaseListResponse, error)
	DatabaseListV2(ctx context.Context) (*schema.DatabaseListResponseV2, error)
	CreateDatabase(ctx context.Context, d *schema.DatabaseSettings) error
	CreateDatabaseV2(ctx context.Context, database string, settings *schema.DatabaseNullableSettings) (*schema.CreateDatabaseResponse, error)
	LoadDatabase(ctx context.Context, r *schema.LoadDatabaseRequest) (*schema.LoadDatabaseResponse, error)
	UnloadDatabase(ctx context.Context, r *schema.UnloadDatabaseRequest) (*schema.UnloadDatabaseResponse, error)
	DeleteDatabase(ctx context.Context, r *schema.DeleteDatabaseRequest) (*schema.DeleteDatabaseResponse, error)
	UseDatabase(ctx context.Context, d *schema.Database) (*schema.UseDatabaseReply, error)
	UpdateDatabase(ctx context.Context, settings *schema.DatabaseSettings) error
	UpdateDatabaseV2(ctx context.Context, database string, settings *schema.DatabaseNullableSettings) (*schema.UpdateDatabaseResponse, error)
	GetDatabaseSettings(ctx context.Context) (*schema.DatabaseSettings, error)
	GetDatabaseSettingsV2(ctx context.Context) (*schema.DatabaseSettingsResponse, error)

	SetActiveUser(ctx context.Context, u *schema.SetActiveUserRequest) error

	FlushIndex(ctx context.Context, cleanupPercentage float32, synced bool) (*schema.FlushIndexResponse, error)
	CompactIndex(ctx context.Context, req *empty.Empty) error

	Health(ctx context.Context) (*schema.DatabaseHealthResponse, error)
	CurrentState(ctx context.Context) (*schema.ImmutableState, error)

	Set(ctx context.Context, key []byte, value []byte) (*schema.TxHeader, error)
	VerifiedSet(ctx context.Context, key []byte, value []byte) (*schema.TxHeader, error)

	ExpirableSet(ctx context.Context, key []byte, value []byte, expiresAt time.Time) (*schema.TxHeader, error)

	Get(ctx context.Context, key []byte) (*schema.Entry, error)
	GetSince(ctx context.Context, key []byte, tx uint64) (*schema.Entry, error)
	GetAt(ctx context.Context, key []byte, tx uint64) (*schema.Entry, error)

	VerifiedGet(ctx context.Context, key []byte) (*schema.Entry, error)
	VerifiedGetSince(ctx context.Context, key []byte, tx uint64) (*schema.Entry, error)
	VerifiedGetAt(ctx context.Context, key []byte, tx uint64) (*schema.Entry, error)

	History(ctx context.Context, req *schema.HistoryRequest) (*schema.Entries, error)

	ZAdd(ctx context.Context, set []byte, score float64, key []byte) (*schema.TxHeader, error)
	VerifiedZAdd(ctx context.Context, set []byte, score float64, key []byte) (*schema.TxHeader, error)

	ZAddAt(ctx context.Context, set []byte, score float64, key []byte, atTx uint64) (*schema.TxHeader, error)
	VerifiedZAddAt(ctx context.Context, set []byte, score float64, key []byte, atTx uint64) (*schema.TxHeader, error)

	Scan(ctx context.Context, req *schema.ScanRequest) (*schema.Entries, error)
	ZScan(ctx context.Context, req *schema.ZScanRequest) (*schema.ZEntries, error)

	TxByID(ctx context.Context, tx uint64) (*schema.Tx, error)
	VerifiedTxByID(ctx context.Context, tx uint64) (*schema.Tx, error)

	TxByIDWithSpec(ctx context.Context, req *schema.TxRequest) (*schema.Tx, error)

	TxScan(ctx context.Context, req *schema.TxScanRequest) (*schema.TxList, error)

	Count(ctx context.Context, prefix []byte) (*schema.EntryCount, error)
	CountAll(ctx context.Context) (*schema.EntryCount, error)

	SetAll(ctx context.Context, kvList *schema.SetRequest) (*schema.TxHeader, error)
	GetAll(ctx context.Context, keys [][]byte) (*schema.Entries, error)

	Delete(ctx context.Context, req *schema.DeleteKeysRequest) (*schema.TxHeader, error)

	ExecAll(ctx context.Context, in *schema.ExecAllRequest) (*schema.TxHeader, error)

	SetReference(ctx context.Context, key []byte, referencedKey []byte) (*schema.TxHeader, error)
	VerifiedSetReference(ctx context.Context, key []byte, referencedKey []byte) (*schema.TxHeader, error)

	SetReferenceAt(ctx context.Context, key []byte, referencedKey []byte, atTx uint64) (*schema.TxHeader, error)
	VerifiedSetReferenceAt(ctx context.Context, key []byte, referencedKey []byte, atTx uint64) (*schema.TxHeader, error)

	Dump(ctx context.Context, writer io.WriteSeeker) (int64, error)

	StreamSet(ctx context.Context, kv []*stream.KeyValue) (*schema.TxHeader, error)
	StreamGet(ctx context.Context, k *schema.KeyRequest) (*schema.Entry, error)
	StreamVerifiedSet(ctx context.Context, kv []*stream.KeyValue) (*schema.TxHeader, error)
	StreamVerifiedGet(ctx context.Context, k *schema.VerifiableGetRequest) (*schema.Entry, error)
	StreamScan(ctx context.Context, req *schema.ScanRequest) (*schema.Entries, error)
	StreamZScan(ctx context.Context, req *schema.ZScanRequest) (*schema.ZEntries, error)
	StreamHistory(ctx context.Context, req *schema.HistoryRequest) (*schema.Entries, error)
	StreamExecAll(ctx context.Context, req *stream.ExecAllRequest) (*schema.TxHeader, error)

	ExportTx(ctx context.Context, req *schema.ExportTxRequest) (schema.ImmuService_ExportTxClient, error)
	ReplicateTx(ctx context.Context) (schema.ImmuService_ReplicateTxClient, error)

	SQLExec(ctx context.Context, sql string, params map[string]interface{}) (*schema.SQLExecResult, error)
	SQLQuery(ctx context.Context, sql string, params map[string]interface{}, renewSnapshot bool) (*schema.SQLQueryResult, error)
	ListTables(ctx context.Context) (*schema.SQLQueryResult, error)
	DescribeTable(ctx context.Context, tableName string) (*schema.SQLQueryResult, error)

	VerifyRow(ctx context.Context, row *schema.Row, table string, pkVals []*schema.SQLValue) error

	NewTx(ctx context.Context) (Tx, error)
}

ImmuClient ...

type MTLsOptions

type MTLsOptions struct {
	Servername  string
	Pkey        string
	Certificate string
	ClientCAs   string
}

MTLsOptions mTLS options

func DefaultMTLsOptions

func DefaultMTLsOptions() MTLsOptions

DefaultMTLsOptions returns the default mTLS options

func (MTLsOptions) WithCertificate

func (o MTLsOptions) WithCertificate(certificate string) MTLsOptions

WithCertificate ...

func (MTLsOptions) WithClientCAs

func (o MTLsOptions) WithClientCAs(clientCAs string) MTLsOptions

WithClientCAs ...

func (MTLsOptions) WithPkey

func (o MTLsOptions) WithPkey(pkey string) MTLsOptions

WithPkey ...

func (MTLsOptions) WithServername

func (o MTLsOptions) WithServername(servername string) MTLsOptions

WithServername ...

type Options

type Options struct {
	Dir                string
	Address            string
	Port               int
	HealthCheckRetries int
	MTLs               bool
	MTLsOptions        MTLsOptions
	Auth               bool
	MaxRecvMsgSize     int
	DialOptions        []grpc.DialOption
	Config             string
	TokenFileName      string
	CurrentDatabase    string
	//--> used by immuclient CLI and sql stdlib package
	PasswordReader c.PasswordReader
	Username       string
	Password       string
	Database       string
	//<--
	Metrics             bool
	PidPath             string
	LogFileName         string
	ServerSigningPubKey string
	StreamChunkSize     int
	HeartBeatFrequency  time.Duration
}

Options client options

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions ...

func (*Options) Bind

func (o *Options) Bind() string

Bind concatenates address and port

func (*Options) String

func (o *Options) String() string

func (*Options) WithAddress

func (o *Options) WithAddress(address string) *Options

WithAddress sets address

func (*Options) WithAuth

func (o *Options) WithAuth(authEnabled bool) *Options

WithAuth activate/deactivate auth

func (*Options) WithConfig

func (o *Options) WithConfig(config string) *Options

WithConfig sets config file name

func (*Options) WithDatabase added in v0.9.2

func (o *Options) WithDatabase(database string) *Options

WithDatabase sets the database for the client

func (*Options) WithDialOptions

func (o *Options) WithDialOptions(dialOptions []grpc.DialOption) *Options

WithDialOptions sets dialOptions

func (*Options) WithDir

func (o *Options) WithDir(dir string) *Options

WithDir sets program file folder

func (*Options) WithHealthCheckRetries

func (o *Options) WithHealthCheckRetries(retries int) *Options

WithHealthCheckRetries sets healt check retries

func (*Options) WithHeartBeatFrequency added in v1.2.0

func (o *Options) WithHeartBeatFrequency(heartBeatFrequency time.Duration) *Options

WithHeartBeatFrequency set the keep alive message frequency

func (*Options) WithLogFileName added in v0.7.0

func (o *Options) WithLogFileName(filename string) *Options

WithLogFileName set log file name

func (*Options) WithMTLs

func (o *Options) WithMTLs(MTLs bool) *Options

WithMTLs activate/deactivate MTLs

func (*Options) WithMTLsOptions

func (o *Options) WithMTLsOptions(MTLsOptions MTLsOptions) *Options

WithMTLsOptions sets MTLsOptions

func (*Options) WithMaxRecvMsgSize added in v0.8.1

func (o *Options) WithMaxRecvMsgSize(maxRecvMsgSize int) *Options

MaxRecvMsgSize max recv msg size in bytes

func (*Options) WithMetrics added in v0.7.0

func (o *Options) WithMetrics(start bool) *Options

WithMetrics set if metrics should start

func (*Options) WithPassword added in v0.9.2

func (o *Options) WithPassword(password string) *Options

WithPassword sets the password for the client

func (*Options) WithPasswordReader added in v0.7.0

func (o *Options) WithPasswordReader(pr c.PasswordReader) *Options

WithPasswordReader sets the password reader for the client

func (*Options) WithPidPath added in v0.7.0

func (o *Options) WithPidPath(path string) *Options

WithPidPath set pid file path

func (*Options) WithPort

func (o *Options) WithPort(port int) *Options

WithPort sets port

func (*Options) WithServerSigningPubKey added in v0.9.0

func (o *Options) WithServerSigningPubKey(serverSigningPubKey string) *Options

WithServerSigningPubKey sets the public key. If presents server state signature verification is enabled

func (*Options) WithStreamChunkSize added in v0.9.2

func (o *Options) WithStreamChunkSize(streamChunkSize int) *Options

WithStreamChunkSize set the chunk size

func (*Options) WithTokenFileName

func (o *Options) WithTokenFileName(tokenFileName string) *Options

WithTokenFileName sets token file name

func (*Options) WithUsername added in v0.9.2

func (o *Options) WithUsername(username string) *Options

WithUsername sets the username for the client

type TimestampService

type TimestampService interface {
	GetTime() time.Time
}

TimestampService the timestamp service interface

func NewTimestampService

func NewTimestampService(ts timestamp.TsGenerator) TimestampService

NewTimestampService ...

type Tx added in v1.2.0

type Tx interface {
	Commit(ctx context.Context) (*schema.CommittedSQLTx, error)
	Rollback(ctx context.Context) error

	SQLExec(ctx context.Context, sql string, params map[string]interface{}) error
	SQLQuery(ctx context.Context, sql string, params map[string]interface{}) (*schema.SQLQueryResult, error)
}

Directories

Path Synopsis
Package clienttest ...
Package clienttest ...

Jump to

Keyboard shortcuts

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