redact

package
v0.0.0-...-a65f256 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: ISC Imports: 11 Imported by: 0

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 New

func New(opt ...Option) *Opt

New sets the configuration for the redaction process.

func (*Opt) Err

func (o *Opt) Err() error

func (*Opt) Redact

func (o *Opt) Redact(s string) (string, error)

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

func WithOverwrite(overwrite overwrite.Replacer) Option

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

func WithRules

func WithRules(s string) Option

WithRules adds gitleaks rules to the configuration.

Directories

Path Synopsis
Package overwrite selects the redaction method.
Package overwrite selects the redaction method.

Jump to

Keyboard shortcuts

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