Skip to content

Commit

Permalink
fix linter warnings. add refang option
Browse files Browse the repository at this point in the history
  • Loading branch information
jakewarren committed Apr 26, 2018
1 parent fddb0c9 commit 7da39ad
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dev:

#Install a release build on your local system
install: clean
@go install ${LDFLAGS} cmd/defang/main.go
@go install ${LDFLAGS} github.com/jakewarren/defang/cmd/defang

build:
@go build ${LDFLAGS_DEV} -o bin/${BINARY} cmd/defang/main.go
Expand Down
28 changes: 25 additions & 3 deletions cmd/defang/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
var version string

type config struct {
refang bool
}

type app struct {
Expand All @@ -27,6 +28,7 @@ func main() {

d := app{}

pflag.BoolVarP(&d.Config.refang, "refang", "r", false, "refang IOCs")
displayVersion := pflag.BoolP("version", "V", false, "display version")
displayHelp := pflag.BoolP("help", "h", false, "display help")

Expand All @@ -53,8 +55,19 @@ func (d app) processInput() {

var output string

scanner := bufio.NewScanner(d.input)
if d.Config.refang {
output = d.refangIOCs()
} else {
output = d.defangIOCs()
}

fmt.Print(output)
clipboard.WriteAll(output)

}

func (d app) defangIOCs() (output string) {
scanner := bufio.NewScanner(d.input)
for scanner.Scan() {
text := scanner.Text()

Expand Down Expand Up @@ -85,10 +98,19 @@ func (d app) processInput() {
}

}
return
}

fmt.Print(output)
clipboard.WriteAll(output)
func (d app) refangIOCs() (output string) {
scanner := bufio.NewScanner(d.input)
for scanner.Scan() {
text := scanner.Text()

u, _ := defang.Refang(text)
output += u + "\n"

}
return
}

// getInput determines the input source between STDIN, String param or file name
Expand Down
4 changes: 2 additions & 2 deletions defang_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"testing"
)

func ExampleDefangIPv4() {
func ExampleIPv4() {
defangedIP, _ := IPv4("8.8.8.8")
fmt.Println(defangedIP)
// Output: 8.8.8[.]8
}

func TestDefangIPv4(t *testing.T) {
func TestIPv4(t *testing.T) {
type args struct {
ip interface{}
}
Expand Down
3 changes: 3 additions & 0 deletions defang_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (
"github.com/pkg/errors"
)

// Mask allows the user to apply a different defanging scheme if they are in a fun mood
type Mask int

const (
// Nsfw marks the URL as Nsfw
Nsfw Mask = iota
Meow
Evil
Expand Down Expand Up @@ -89,6 +91,7 @@ func URL(rawURL interface{}) (string, error) {
return output, nil
}

// URLWithMask defangs a URL and applies the specified defanging scheme
func URLWithMask(rawURL interface{}, m Mask) (string, error) {

output, err := URL(rawURL)
Expand Down
1 change: 1 addition & 0 deletions integration/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func TestCliArgs(t *testing.T) {
{"no arguments", []string{}, "no-args.golden"},
{"one argument", []string{"google.com"}, "one-argument.golden"},
{"file", []string{"testdata/blob.txt"}, "file.golden"},
{"refang file", []string{"-r", "integration/file.golden"}, "refang-file.golden"},
}

for _, tt := range tests {
Expand Down
1 change: 1 addition & 0 deletions integration/no-args.golden
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ Usage: defang [<flags>] [FILE]
Optional flags:

-h, --help display help
-r, --refang refang IOCs
-V, --version display version
6 changes: 6 additions & 0 deletions integration/refang-file.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
1.2.3.4
google.com
operator@fancybear.com
noreply@github.com
8.8.8.8
1.1.1.1
1 change: 1 addition & 0 deletions refang.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/pkg/errors"
)

// Refang takes a defanged IOC and returns it to it's original form
func Refang(input interface{}) (string, error) {

var output string
Expand Down

0 comments on commit 7da39ad

Please sign in to comment.