Documentation ¶
Index ¶
- Constants
- func JoinCommand(command string, arguments ...string) (s string)
- func NewCommandMatch(command string, arguments ...string) *regexp.Regexp
- func NewExtensionMatch(ext string) *regexp.Regexp
- func NewRegexpKeyValue(key string) *regexp.Regexp
- func ReplacePattern(line string, pattern *regexp.Regexp) (s string, count uint)
- func ReplacePatterns(line string, patterns []*regexp.Regexp) (s string, count uint)
- type Kind
- type Obfuscator
- func (o Obfuscator) IsAccepting(kind Kind, name string) bool
- func (o *Obfuscator) Process(data []byte) (uint, []byte, error)
- func (o *Obfuscator) ProcessReader(r io.Reader) (count uint, out bytes.Buffer, err error)
- func (o *Obfuscator) WithAffecting(a *regexp.Regexp) *Obfuscator
- func (o *Obfuscator) WithReplacement(r *regexp.Regexp) *Obfuscator
Examples ¶
Constants ¶
const Replacement = "<HIDDEN>"
Replacement is the standard replacement used during obfuscation.
Variables ¶
This section is empty.
Functions ¶
func JoinCommand ¶
func NewExtensionMatch ¶
func NewRegexpKeyValue ¶
NewRegexpKeyValue builds an regexp.Regexp to match multiple key-value kinds.
Should work with INI files and Icinga 2 config.
func ReplacePattern ¶
ReplacePattern replaces all matches in a line.
Types ¶
type Kind ¶
type Kind uint8
Kind is used by Obfuscator to identify the kind of content to obfuscate.
type Obfuscator ¶
type Obfuscator struct { Kind Affecting []*regexp.Regexp Replacements []*regexp.Regexp Files uint Replaced uint }
Obfuscator provides the basic functionality of an obfuscation engine.
Kind filters the variant of resource we want to work on, while Affecting defines a list of regexp.Regexp, to match against for the file names, or command.
Replacements will be iterated, so all matches or matched groups will be replaced.
Example ¶
o := New(KindFile, regexp.MustCompile(`\.ini$`), regexp.MustCompile(`password\s*=\s*(.*)`)) content := []byte(`password = "secret"`) if o.IsAccepting(KindFile, "test.ini") { count, data, err := o.Process(content) fmt.Println(err) fmt.Println(count) fmt.Println(string(data)) }
Output: <nil> 1 password = <HIDDEN>
func New ¶
func New(kind Kind, affects, replace *regexp.Regexp) *Obfuscator
New returns a basic Obfuscator with provided regexp.Regexp.
func NewAny ¶
func NewAny(replace string) *Obfuscator
NewAny returns an Obfuscator that can be used to replace any input.
func NewFile ¶
func NewFile(replace, ext string) *Obfuscator
NewFile returns an Obfuscator and will initialize regexp.Regexp based on extension and a string for replacement.
func NewOutput ¶
func NewOutput(replace, command string, arguments ...string) *Obfuscator
NewOutput returns an Obfuscator and will initialize regexp.Regexp based on command and replacement.
func (Obfuscator) IsAccepting ¶
func (o Obfuscator) IsAccepting(kind Kind, name string) bool
IsAccepting checks if we want to work on the resource.
func (*Obfuscator) Process ¶
func (o *Obfuscator) Process(data []byte) (uint, []byte, error)
Process takes data and returns it obfuscated.
func (*Obfuscator) ProcessReader ¶
ProcessReader takes an io.Reader and returns a new one obfuscated.
func (*Obfuscator) WithAffecting ¶
func (o *Obfuscator) WithAffecting(a *regexp.Regexp) *Obfuscator
WithAffecting adds a new element to the list.
func (*Obfuscator) WithReplacement ¶
func (o *Obfuscator) WithReplacement(r *regexp.Regexp) *Obfuscator
WithReplacement adds a new element to the list.