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)
- type Kind
- type Obfuscator
- func (o Obfuscator) IsAccepting(kind Kind, name string) bool
- func (o *Obfuscator) Process(data []byte, name string) (uint, []byte, error)
- func (o *Obfuscator) ProcessReader(r io.Reader, name string) (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.
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 ShouldAffect []*regexp.Regexp ReplacePattern *regexp.Regexp ObfuscatedFiles []string Replaced uint }
Obfuscator provides the basic functionality of an obfuscation engine.
Kind filters the variant of resource we want to work on, while ShouldAffect defines a list of regexp.Regexp, to match against for the file names, or command.
Replacement 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.
Checks if the Obfuscator.Kind is matching the given kind. If not returns false. Checks if the Obfuscator.ShouldAffect is matching the given name.
func (*Obfuscator) Process ¶
Process takes data and returns it obfuscated. Also takes name of file that is obfuscated
Returns count of replaced values as uint, obfuscated data as []byte, and error
func (*Obfuscator) ProcessReader ¶
func (o *Obfuscator) ProcessReader(r io.Reader, name string) (count uint, out bytes.Buffer, err error)
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 pattern to the list where the Obfuscator will be applied
func (*Obfuscator) WithReplacement ¶
func (o *Obfuscator) WithReplacement(r *regexp.Regexp) *Obfuscator
WithReplacement adds a new pattern to the list.