sds

package module
v0.0.0-...-daa7c24 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MatchActionNone          = MatchActionType("None")
	MatchActionRedact        = MatchActionType("Redact")
	MatchActionHash          = MatchActionType("Hash")
	MatchActionPartialRedact = MatchActionType("PartialRedact")
)
View Source
const (
	LuhnChecksum      = SecondaryValidator("LuhnChecksum")
	ChineseIdChecksum = SecondaryValidator("ChineseIdChecksum")
)
View Source
const (
	FirstCharacters = PartialRedactionDirection("FirstCharacters")
	LastCharacters  = PartialRedactionDirection("LastCharacters")
)

Variables

View Source
var (
	ErrUnknown            error = fmt.Errorf("unknown error")
	ErrInvalidRegex       error = fmt.Errorf("invalid regex")
	ErrInvalidKeywords    error = fmt.Errorf("invalid keywords")
	ErrInvalidMatchAction error = fmt.Errorf("invalid match action")
)

Functions

This section is empty.

Types

type ExtraConfig

type ExtraConfig struct {
	ProximityKeywords  *ProximityKeywordsConfig
	SecondaryValidator SecondaryValidator
}

ExtraConfig is used to provide more configuration while creating the rules.

type MatchAction

type MatchAction struct {
	Type MatchActionType
	// used when Type == MatchActionRedact, empty otherwise
	RedactionValue string
	// used when Type == MatchActionPartialRedact, empty otherwise
	CharacterCount uint32
	// used when Type == MatchActionPartialRedact, empty otherwise
	Direction PartialRedactionDirection
}

MatchAction is used to configure the rules.

func (MatchAction) MarshalJSON

func (m MatchAction) MarshalJSON() ([]byte, error)

MarshalJSON marshals the MatchAction in a format understood by the serde rust JSON library.

type MatchActionType

type MatchActionType string

type PartialRedactionDirection

type PartialRedactionDirection string

type ProximityKeywordsConfig

type ProximityKeywordsConfig struct {
	LookAheadCharacterCount uint32   `json:"look_ahead_character_count"`
	IncludedKeywords        []string `json:"included_keywords"`
	ExcludedKeywords        []string `json:"excluded_keywords"`
}

ProximityKeywordsConfig represents the proximity keyword matching for the core library.

func CreateProximityKeywordsConfig

func CreateProximityKeywordsConfig(lookAheadCharaceterCount uint32, includedKeywords []string, excludedKeywords []string) *ProximityKeywordsConfig

CreateProximityKeywordsConfig creates a ProximityKeywordsConfig.

type Rule

type Rule struct {
	Id                 string                   `json:"id"`
	Pattern            string                   `json:"pattern"`
	MatchAction        MatchAction              `json:"match_action"`
	ProximityKeywords  *ProximityKeywordsConfig `json:"proximity_keywords,omitempty"`
	SecondaryValidator SecondaryValidator       `json:"validator,omitempty"`
}

Rule is sent to the core library to create scanners.

func NewHashRule

func NewHashRule(id string, pattern string, extraConfig ExtraConfig) Rule

NewHashRule returns a matching rule redacting with hashes.

func NewMatchingRule

func NewMatchingRule(id string, pattern string, extraConfig ExtraConfig) Rule

NewMatchingRule returns a matching rule with no match _action_.

func NewPartialRedactRule

func NewPartialRedactRule(id string, pattern string, characterCount uint32, direction PartialRedactionDirection, extraConfig ExtraConfig) Rule

NewPartialRedactRule returns a matching rule partially redacting matches.

func NewRedactingRule

func NewRedactingRule(id string, pattern string, redactionValue string, extraConfig ExtraConfig) Rule

NewRedactingRule returns a matching rule redacting events.

type RuleMatch

type RuleMatch struct {
	RuleIdx uint32
	// TODO(remy): not implemented yet.
	Path              string
	ReplacementType   MatchAction
	StartIndex        uint32
	EndIndexExclusive uint32
	ShiftOffset       int32
}

RuleMatch stores the matches reported by the core library.

type ScanResult

type ScanResult struct {
	// Event contains the event after the scan.
	// If `Mutated` is true:
	//   * it contains the processed event after redaction.
	// If `Mutated` is false:
	//   * it contains the original event, unchanged.
	Event []byte
	// contains filtered or unexported fields
}

ScanResult contains a Scan result.

type Scanner

type Scanner struct {
	// Id of this scanner generated by the SDS library when the scanner is created.
	Id int64
	// They are stored on creation for read-only usage.
	Rules []Rule
}

Scanner wraps an SDS scanner. See `CreateScanner` to create one providing SDS rules. See `Scan`, `ScanEventsList` or a `ScanEventsMap` for usage.

func CreateScanner

func CreateScanner(rules []Rule) (*Scanner, error)

CreateScanner creates a scanner in the underlying SDS shared library. The library only returns an ID to then address what scanner to use on Scan calls. This ID is stored in the Scanner Go object for convenience. See `Scan` to process events. The rules used to create the Scanner are stored as a read-only information in the returned Scanner.

func (*Scanner) Delete

func (s *Scanner) Delete()

Delete deletes the instance of the current Scanner. The current Scanner should not be reused.

func (*Scanner) Scan

func (s *Scanner) Scan(event []byte) (ScanResult, error)

Scan sends the string event to the SDS shared library for processing.

func (*Scanner) ScanEventsList

func (s *Scanner) ScanEventsList(event []interface{}) (ScanResult, error)

ScanEventsList sends a list of event to the SDS shared library for processing.

func (*Scanner) ScanEventsMap

func (s *Scanner) ScanEventsMap(event map[string]interface{}) (ScanResult, error)

ScanEventsMap sends a map event to the SDS shared library for processing.

type SecondaryValidator

type SecondaryValidator string

func (SecondaryValidator) MarshalJSON

func (s SecondaryValidator) MarshalJSON() ([]byte, error)

MarshalJSON marshales the SecondaryValidator.

Jump to

Keyboard shortcuts

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