Documentation ¶
Overview ¶
Package redact parses a file removing any detected secrets.
Index ¶
Examples ¶
Constants ¶
View Source
const ReplacementText = "**REDACTED**"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Opt ¶
type Opt struct {
// contains filtered or unexported fields
}
func (*Opt) Redact ¶
Redact removes secrets detected in the provided string.
Example ¶
package main import ( "fmt" "log" "codeberg.org/msantos/redact/pkg/redact" ) func main() { red := redact.New(redact.WithRules(`[[rules]] id = "crypt-password-hash" description = "Detected a password hash" regex = '''\$(?:[a-zA-Z0-9]+)\$([^\s:]+)''' `)) redacted, err := red.Redact("root:$6$d468dc01f1cd655d$1c0a188389f4db6399265080815ac488ea65c3295a18d2d7da3ce5e8ef082362adeedec9b69.9704d4d188:18515:0:99999:7:::") if err != nil { log.Fatalln(err) } fmt.Println(redacted) }
Output: root:$6$**REDACTED**:18515:0:99999:7:::
Example (Mask) ¶
package main import ( "fmt" "log" "codeberg.org/msantos/redact/pkg/redact" "codeberg.org/msantos/redact/pkg/redact/overwrite" ) func main() { red := redact.New(redact.WithRules(`[[rules]] id = "crypt-password-hash" description = "Detected a password hash" regex = '''\$(?:[a-zA-Z0-9]+)\$([^\s:]+)''' `), redact.WithOverwrite(&overwrite.Mask{Char: byte('*')}), ) redacted, err := red.Redact("root:$6$d468dc01f1cd655d$1c0a188389f4db6399265080815ac488ea65c3295a18d2d7da3ce5e8ef082362adeedec9b69.9704d4d188:18515:0:99999:7:::") if err != nil { log.Fatalln(err) } fmt.Println(redacted) }
Output: root:$6$*******************************************************************************************************:18515:0:99999:7:::
type Option ¶
type Option func(*Opt)
func WithOverwrite ¶
WithOverwrite sets the method for overwriting secrets:
- redact: substitute the secret with the redaction string
- mask: set each character of the secret with the first letter of the redaction string
Click to show internal directories.
Click to hide internal directories.