Documentation
¶
Index ¶
- Constants
- Variables
- func FindColumnInfo(fromClause []*pg_query.Node, colRef *pg_query.ColumnRef, ...) (base.ColumnInfo, error)
- func GetColumnSetting(column *pg_query.ColumnRef, tableName string, ...) config.ColumnEncryptionSetting
- func GetWhereStatements(parseResult *pg_query.ParseResult) ([]*pg_query.Node, error)
- func MapColumnsToAliases(selectQuery *pg_query.SelectStmt, tableSchemaStore config.TableSchemaStore) ([]*base.ColumnInfo, error)
- func ParseQuerySettings(ctx context.Context, statement *pg_query.SelectStmt, ...) ([]*base.QueryDataItem, error)
- func ParseSearchQueryPlaceholdersSettings(statement *pg_query.ParseResult, schemaStore config.TableSchemaStore) map[int]config.ColumnEncryptionSetting
- func PgEncodeToHexString(data []byte) []byte
- func UpdateExpressionValue(ctx context.Context, expr *pg_query.A_Const, coder *PgQueryDBDataCoder, ...) error
- type AliasToTableMap
- type AliasedTableName
- type ArrayClientIDObservableManager
- type ArrayQueryObservableManager
- func (manager *ArrayQueryObservableManager) AddQueryObserver(obs QueryObserver)
- func (manager *ArrayQueryObservableManager) ID() string
- func (manager *ArrayQueryObservableManager) OnBind(ctx context.Context, statement *pg_query.ParseResult, values []base.BoundValue) ([]base.BoundValue, bool, error)
- func (manager *ArrayQueryObservableManager) OnQuery(ctx context.Context, query OnQueryObject) (OnQueryObject, bool, error)
- func (manager *ArrayQueryObservableManager) RegisteredObserversCount() int
- type ClientIDObservable
- type ClientIDObservableManager
- type ClientIDObserver
- type OnQueryObject
- type PgQueryDBDataCoder
- type QueryDataEncryptor
- func (encryptor *QueryDataEncryptor) GetQueryEncryptionSettings() []*base.QueryDataItem
- func (encryptor *QueryDataEncryptor) ID() string
- func (encryptor *QueryDataEncryptor) OnBind(ctx context.Context, parseResult *pg_query.ParseResult, ...) ([]decryptor.BoundValue, bool, error)
- func (encryptor *QueryDataEncryptor) OnColumn(ctx context.Context, data []byte) (context.Context, []byte, error)
- func (encryptor *QueryDataEncryptor) OnQuery(ctx context.Context, query OnQueryObject) (OnQueryObject, bool, error)
- type QueryObservable
- type QueryObserver
- type QueryObserverManager
- type SearchableExprItem
- type SearchableQueryFilter
Constants ¶
const InvalidPlaceholderIndex = -1
InvalidPlaceholderIndex value that represent invalid index for sql placeholders
const SubstrFuncName = "substr"
SubstrFuncName substr function name
Variables ¶
var ErrInvalidPlaceholder = errors.New("invalid placeholder value")
ErrInvalidPlaceholder is returned when Acra cannot parse SQL placeholder expression.
var ErrUnsupportedQueryType = errors.New("unsupported Query type")
ErrUnsupportedQueryType represent error related unsupported Query type
var ErrUpdateLeaveDataUnchanged = errors.New("updateFunc didn't change data")
ErrUpdateLeaveDataUnchanged show that data wasn't changed in UpdateExpressionValue with updateFunc
Functions ¶
func FindColumnInfo ¶
func FindColumnInfo(fromClause []*pg_query.Node, colRef *pg_query.ColumnRef, schemaStore config.TableSchemaStore) (base.ColumnInfo, error)
FindColumnInfo get ColumnInfo from TableExprs, ColName and TableSchemaStore
func GetColumnSetting ¶
func GetColumnSetting(column *pg_query.ColumnRef, tableName string, schemaStore config.TableSchemaStore) config.ColumnEncryptionSetting
GetColumnSetting get ColumnEncryptionSetting from schemaStore based on tableName and column
func GetWhereStatements ¶
func GetWhereStatements(parseResult *pg_query.ParseResult) ([]*pg_query.Node, error)
GetWhereStatements parse all Where expressions
func MapColumnsToAliases ¶
func MapColumnsToAliases(selectQuery *pg_query.SelectStmt, tableSchemaStore config.TableSchemaStore) ([]*base.ColumnInfo, error)
MapColumnsToAliases parse slice of ColumnInfo from sqlparser.Select and config.TableSchemaStore
func ParseQuerySettings ¶
func ParseQuerySettings(ctx context.Context, statement *pg_query.SelectStmt, schemaStore config.TableSchemaStore) ([]*base.QueryDataItem, error)
ParseQuerySettings parse list of select query settings based on schemaStore
func ParseSearchQueryPlaceholdersSettings ¶
func ParseSearchQueryPlaceholdersSettings(statement *pg_query.ParseResult, schemaStore config.TableSchemaStore) map[int]config.ColumnEncryptionSetting
ParseSearchQueryPlaceholdersSettings parse encryption settings of statement with placeholders
func PgEncodeToHexString ¶
PgEncodeToHexString encodes to hex with \x prefix
func UpdateExpressionValue ¶
func UpdateExpressionValue(ctx context.Context, expr *pg_query.A_Const, coder *PgQueryDBDataCoder, setting config.ColumnEncryptionSetting, updateFunc func(context.Context, []byte) ([]byte, error)) error
UpdateExpressionValue decode value from DB related string to binary format, call updateFunc, encode to DB string format and replace value in expression with new
Types ¶
type AliasToTableMap ¶
AliasToTableMap store table alias as key and table name as value
func NewAliasToTableMapFromTables ¶
func NewAliasToTableMapFromTables(tables []*AliasedTableName) AliasToTableMap
NewAliasToTableMapFromTables create AliasToTableMap from slice of aliased tables
type AliasedTableName ¶
AliasedTableName store TableName and related As value together
func GetTablesWithAliases ¶
func GetTablesWithAliases(tables []*pg_query.Node) []*AliasedTableName
GetTablesWithAliases collect all tables from all update TableExprs which may be as subquery/table/join/etc collect only table names and ignore aliases for subqueries
type ArrayClientIDObservableManager ¶
type ArrayClientIDObservableManager struct {
// contains filtered or unexported fields
}
ArrayClientIDObservableManager store all subscribed observes and call sequentially OnQuery on each observer
func NewArrayClientIDObservableManager ¶
func NewArrayClientIDObservableManager(ctx context.Context) (*ArrayClientIDObservableManager, error)
NewArrayClientIDObservableManager create new ArrayClientIDObservableManager
func (*ArrayClientIDObservableManager) AddClientIDObserver ¶
func (manager *ArrayClientIDObservableManager) AddClientIDObserver(observer ClientIDObserver)
AddClientIDObserver add new subscriber for clientID changes
func (*ArrayClientIDObservableManager) OnNewClientID ¶
func (manager *ArrayClientIDObservableManager) OnNewClientID(clientID []byte)
OnNewClientID pass clientID to subscribers
type ArrayQueryObservableManager ¶
type ArrayQueryObservableManager struct {
// contains filtered or unexported fields
}
ArrayQueryObservableManager store all subscribed observes and call sequentially OnQuery on each observer
func NewArrayQueryObservableManager ¶
func NewArrayQueryObservableManager(ctx context.Context) (*ArrayQueryObservableManager, error)
NewArrayQueryObservableManager create new ArrayQueryObservableManager
func (*ArrayQueryObservableManager) AddQueryObserver ¶
func (manager *ArrayQueryObservableManager) AddQueryObserver(obs QueryObserver)
AddQueryObserver observer to array
func (*ArrayQueryObservableManager) ID ¶
func (manager *ArrayQueryObservableManager) ID() string
ID returns name of this QueryObserver.
func (*ArrayQueryObservableManager) OnBind ¶
func (manager *ArrayQueryObservableManager) OnBind(ctx context.Context, statement *pg_query.ParseResult, values []base.BoundValue) ([]base.BoundValue, bool, error)
OnBind would be called for each added observer to manager.
func (*ArrayQueryObservableManager) OnQuery ¶
func (manager *ArrayQueryObservableManager) OnQuery(ctx context.Context, query OnQueryObject) (OnQueryObject, bool, error)
OnQuery would be called for each added observer to manager
func (*ArrayQueryObservableManager) RegisteredObserversCount ¶
func (manager *ArrayQueryObservableManager) RegisteredObserversCount() int
RegisteredObserversCount return count of registered observers
type ClientIDObservable ¶
type ClientIDObservable interface {
AddClientIDObserver(ClientIDObserver)
}
ClientIDObservable used to subscribe for clientID changes
type ClientIDObservableManager ¶
type ClientIDObservableManager interface { ClientIDObservable ClientIDObserver }
ClientIDObservableManager used to subscribe for clientID changes and notify about changes
type ClientIDObserver ¶
type ClientIDObserver interface {
OnNewClientID(clientID []byte)
}
ClientIDObserver used to notify subscribers about changed ClientID in encryption/decryption context
type OnQueryObject ¶
type OnQueryObject interface { Statement() (*pg_query.ParseResult, error) Query() (string, error) }
OnQueryObject interface for result of OnQuery call
func NewOnQueryObjectFromQuery ¶
func NewOnQueryObjectFromQuery(query string) OnQueryObject
NewOnQueryObjectFromQuery return OnQueryObject with query string as value
func NewOnQueryObjectFromStatement ¶
func NewOnQueryObjectFromStatement(stmt *pg_query.ParseResult) OnQueryObject
NewOnQueryObjectFromStatement return OnQueryObject with Statement as value
type PgQueryDBDataCoder ¶
type PgQueryDBDataCoder struct{}
PgQueryDBDataCoder responsible to handle decoding/encoding SQL literals before/after QueryEncryptor handlers
Acra captures SQL queries like `INSERT INTO users (age, username, email, photo) VALUES (123, 'john_wick', 'johnwick@mail.com', '\xaabbcc');` and manipulates with SQL values `123`, `'john_wick'`, `'johnwick@mail.com'`, `'\xaabbcc'`. On first stage Acra decodes with Decode method values from SQL literals into binary or leave as is. For example hex encoded values decoded into binary" `'\xaabbcc'` decoded into []byte{170,187,204} and passed to QueryEncryptor's callbacks `EncryptWithClientID` After that it should be encoded with Encode method from binary form into SQL to replace values in the query.
func (*PgQueryDBDataCoder) Decode ¶
func (*PgQueryDBDataCoder) Decode(aConst *pg_query.A_Const, setting config.ColumnEncryptionSetting) ([]byte, error)
Decode hex/escaped literals to raw binary values for encryption/decryption. String values left as is because it doesn't need any decoding. Historically Int values had support only for tokenization and operated over string SQL literals.
func (*PgQueryDBDataCoder) Encode ¶
func (*PgQueryDBDataCoder) Encode(aConst *pg_query.A_Const, data []byte, setting config.ColumnEncryptionSetting) error
Encode data to correct literal from binary data for this expression
type QueryDataEncryptor ¶
type QueryDataEncryptor struct {
// contains filtered or unexported fields
}
QueryDataEncryptor parse query and encrypt raw data according to TableSchemaStore
func NewQueryEncryptor ¶
func NewQueryEncryptor(schema config.TableSchemaStore, dataEncryptor base.DataEncryptor) (*QueryDataEncryptor, error)
NewQueryEncryptor create QueryDataEncryptor with DBDataCoder
func (*QueryDataEncryptor) GetQueryEncryptionSettings ¶
func (encryptor *QueryDataEncryptor) GetQueryEncryptionSettings() []*base.QueryDataItem
GetQueryEncryptionSettings returns collected in OnQuery callback encryptor settings
func (*QueryDataEncryptor) ID ¶
func (encryptor *QueryDataEncryptor) ID() string
ID returns name of this QueryObserver.
func (*QueryDataEncryptor) OnBind ¶
func (encryptor *QueryDataEncryptor) OnBind(ctx context.Context, parseResult *pg_query.ParseResult, values []decryptor.BoundValue) ([]decryptor.BoundValue, bool, error)
OnBind process bound values for prepared statement based on TableSchemaStore.
func (*QueryDataEncryptor) OnColumn ¶
func (encryptor *QueryDataEncryptor) OnColumn(ctx context.Context, data []byte) (context.Context, []byte, error)
OnColumn return new encryption setting context if info exist, otherwise column data and passed context will be returned
func (*QueryDataEncryptor) OnQuery ¶
func (encryptor *QueryDataEncryptor) OnQuery(ctx context.Context, query OnQueryObject) (OnQueryObject, bool, error)
OnQuery raw data in query according to TableSchemaStore
type QueryObservable ¶
type QueryObservable interface { AddQueryObserver(QueryObserver) RegisteredObserversCount() int }
QueryObservable used to handle subscribers for new incoming queries
type QueryObserver ¶
type QueryObserver interface { ID() string // Simple queries and prepared statements during preparation stage. SQL is modifiable. OnQuery(ctx context.Context, data OnQueryObject) (OnQueryObject, bool, error) // Prepared statement parameters during execution stage. Parameter values are modifiable. OnBind(ctx context.Context, statement *pg_query.ParseResult, values []base.BoundValue) ([]base.BoundValue, bool, error) }
QueryObserver observes database queries and is able to modify them. Methods should return "true" as their second bool result if the data has been modified.
type QueryObserverManager ¶
type QueryObserverManager interface { QueryObserver QueryObservable }
QueryObserverManager interface for observer aggregations
type SearchableExprItem ¶
type SearchableExprItem struct { Expr *pg_query.A_Expr Setting config.ColumnEncryptionSetting }
SearchableExprItem represent the filtered value found by SearchableQueryFilter
type SearchableQueryFilter ¶
type SearchableQueryFilter struct {
// contains filtered or unexported fields
}
SearchableQueryFilter filter searchable expression based on SearchableQueryFilterMode
func NewSearchableQueryFilter ¶
func NewSearchableQueryFilter(schemaStore config.TableSchemaStore, mode base.SearchableQueryFilterMode) *SearchableQueryFilter
NewSearchableQueryFilter create new SearchableQueryFilter from schemaStore and SearchableQueryFilterMode
func (*SearchableQueryFilter) ChangeSearchableOperator ¶
func (filter *SearchableQueryFilter) ChangeSearchableOperator(expr *pg_query.A_Expr)
ChangeSearchableOperator change the operator of ComparisonExpr to EqualStr|NotEqualStr depending on expr.Operator
func (*SearchableQueryFilter) FilterSearchableComparisons ¶
func (filter *SearchableQueryFilter) FilterSearchableComparisons(result *pg_query.ParseResult) []SearchableExprItem
FilterSearchableComparisons filter search comparisons from statement