Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ export GOBIN := `echo $PWD/.bin`
default:
@just --list

# start nerfs-builds artifact builder in demo mode
# start nerfs artifact builder in demo mode
run mode: compile
$GOBIN/nerfs-builds {{mode}}
$GOBIN/nerfs {{mode}}

# compile the nerfs-builds executable
# compile the nerfs executable
compile: tidy
cd cmds/nerfs-builds && go install
cd cmds/nerfs && go install

# tidy up Go modules
tidy:
go mod tidy

# vet the nerfs-compile source tree
# vet the nerfs source tree
vet:
go vet ./...

# run go test on the source tree
tests:
go test -race ./...

# lint the nerfs-compile source tree
# lint the nerfs source tree
lint: vet
$GOBIN/golangci-lint run --config $scripts/golangci.yaml

Expand Down
83 changes: 0 additions & 83 deletions cmds/nerfs-builds/commands/commands.go

This file was deleted.

28 changes: 0 additions & 28 deletions cmds/nerfs-builds/wordlist/words.txt

This file was deleted.

63 changes: 63 additions & 0 deletions cmds/nerfs/commands/commands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package commands

import (
"fmt"
"os"

"cattlecloud.net/go/babycli"
"cattlecloud.net/nerfs/cmds/nerfs/domains"
"cattlecloud.net/nerfs/cmds/nerfs/wordlist"
)

func Invoke(args []string) babycli.Code {
return invoke(args)
}

func invoke(args []string) babycli.Code {
return babycli.New(&babycli.Configuration{
Arguments: args,
Version: "v0.0.0",
Top: &babycli.Component{
Name: "nerfs",
Help: "run the artifact builder(s)",
Description: "Builds an artifact",
Flags: babycli.Flags{},
Components: babycli.Components{
{
Name: "build",
Help: "generate the artifact files",
Flags: babycli.Flags{
{
Type: babycli.StringFlag,
Long: "output",
Require: true,
Short: "o",
Help: "specify output DIR",
Default: &babycli.Default{
Value: os.TempDir(),
Show: true,
},
},
},
Function: func(c *babycli.Component) babycli.Code {
output := c.GetString("output")

buildDomains := domains.NewBuilder()
if err := buildDomains.Build(output); err != nil {
fmt.Println("build failure:", err)
return babycli.Failure
}

buildWords := wordlist.NewBuilder()
if err := buildWords.Build(output); err != nil {
fmt.Println("build failure:", err)
return babycli.Failure
}

return babycli.Success
},
},
},
},
}).Run()
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"cattlecloud.net/go/atomicfs"
"cattlecloud.net/go/ulog"
"cattlecloud.net/nerfs"
)

var sources = []string{
Expand All @@ -30,7 +31,7 @@ func NewBuilder() *Builder {
}
}

func (b *Builder) Build(destination string) error {
func (b *Builder) Build(directory string) error {
start := time.Now()
b.log.I.Fmt("starting the build ...")

Expand All @@ -48,13 +49,13 @@ func (b *Builder) Build(destination string) error {
return err
}

directory := filepath.Dir(destination)
fw := atomicfs.New(atomicfs.Options{
TmpDirectory: directory,
TmpExtension: ".temp",
Mode: 0o644,
})

destination := filepath.Join(directory, nerfs.DomainsFile)
b.log.I.Fmt("writing artifact to %s", destination)
if err := fw.WriteFile(destination, buf); err != nil {
return err
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion cmds/nerfs-builds/main.go → cmds/nerfs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"os"

"cattlecloud.net/go/babycli"
"cattlecloud.net/nerfs/cmds/nerfs-builds/commands"
"cattlecloud.net/nerfs/cmds/nerfs/commands"
)

func main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func NewArtifact() *Artifact {

func (a *Artifact) Add(line string) {
// given line is directly from words.txt which is in the form
// <word(s)> -> <regexp>
// <word> -> <regexp>

tokens := strings.Split(line, "->")
if len(tokens) != 2 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"cattlecloud.net/go/atomicfs"
"cattlecloud.net/go/ulog"
"cattlecloud.net/nerfs"
)

type Builder struct {
Expand All @@ -21,7 +22,7 @@ func NewBuilder() *Builder {
}
}

func (b *Builder) Build(destination string) error {
func (b *Builder) Build(directory string) error {
start := time.Now()
b.log.I.Fmt("starting the build ...")

Expand All @@ -41,13 +42,13 @@ func (b *Builder) Build(destination string) error {
return err
}

directory := filepath.Dir(destination)
fw := atomicfs.New(atomicfs.Options{
TmpDirectory: directory,
TmpExtension: ".temp",
Mode: 0o644,
})

destination := filepath.Join(directory, nerfs.WordsFile)
b.log.I.Fmt("writing artifact to %s", destination)
if err := fw.WriteFile(destination, buf); err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,29 @@ package wordlist
import (
"encoding/json"
"os"
"path/filepath"
"regexp"
"testing"

"cattlecloud.net/nerfs"
"github.com/shoenig/test/must"
"github.com/shoenig/test/util"
)

const (
// numWords must match the number of expressions in words.txt
numWords = 28
numWords = 14
)

func TestBuilder_Build(t *testing.T) {
t.Parallel()

dest := util.TempFile(t)
dir := t.TempDir()

b := NewBuilder()
err := b.Build(dest)
err := b.Build(dir)
must.NoError(t, err)

f, ferr := os.Open(dest)
f, ferr := os.Open(filepath.Join(dir, nerfs.WordsFile))
must.NoError(t, ferr)

m := make(map[string]*regexp.Regexp)
Expand All @@ -34,8 +35,6 @@ func TestBuilder_Build(t *testing.T) {

t.Run("spot checks", func(t *testing.T) {
must.RegexMatch(t, m["wop"], "wop")
must.RegexMatch(t, m["coom"], "c00m$")
must.RegexMatch(t, m["camel jockey"], "c@m3l-jock3ys")
must.RegexMatch(t, m["dago"], "d@g0$")

// non-matching due to word boundary
Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions cmds/nerfs/wordlist/words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
chink -> (?i)\bch[i1]nk[s$]?\b
clit -> (?i)\bcl[i1]t[s$]?\b
dago -> (?i)\bd[a@]g[o0][s$]?\b
dyke -> (?i)\bd[i1y]k[e3][s$]?\b
fag -> (?i)\bf[a@]g[s$]?\b
faggot -> (?i)\bf[a@]gg[o0]t[s$]?\b
gook -> (?i)\bg[o0]+k[s$]?\b
heeb -> (?i)\bh[e3]b[s$]?\b
kyke -> (?i)\bk[i1y]k[e3][s$]?\b
nigger -> (?i)\bn[i1]g+[e3]r[zs$]?\b
spic -> (?i)\bsp[i1][ck][s$]?\b
wetback -> (?i)\bw[e3]tb[a@]c?k?[s$]?\b
wigger -> (?i)\bw[i1]gg[e3]r[s$]?\b
wop -> (?i)\bw[o0]p[s$]?\b
9 changes: 7 additions & 2 deletions nerfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import (

const (
DomainsFile = "domains.txt"
WordsFile = "wordlist.json"
WordsFile = "wordlist.txt"
)

// An Artifact contains the in-memory optimized form of the domain and word
// block-list files created by the nerfs-builds tool.
// block-list files created by the nerfs tool.
//
// Create an Artifact by calling Load() with the directory of the compiled
// artifacts.
Expand Down Expand Up @@ -64,6 +64,11 @@ func (a *Artifact) Synopsis(r io.Reader) *Synopsis {
}

func (a *Artifact) matchDomain(s string) bool {
s, _ = strings.CutPrefix(s, "https://")
s, _ = strings.CutPrefix(s, "http://")
if i := strings.IndexAny(s, "/?#"); i >= 0 {
s = s[:i]
}
return a.domains.Contains(s)
}

Expand Down
Loading