From 0f74e14d222655d0100fa5f6455339c450d7208e Mon Sep 17 00:00:00 2001 From: Koen Rouwhorst Date: Sat, 17 Aug 2019 17:59:46 +0200 Subject: [PATCH 01/10] Fix misspelling --- bucket_checker.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bucket_checker.go b/bucket_checker.go index 1032a99..efdc381 100644 --- a/bucket_checker.go +++ b/bucket_checker.go @@ -33,7 +33,7 @@ type S3Resolver struct { const s3host = "s3.amazonaws.com" -// IsBucket determines wheter this prefix is a valid S3 bucket name. +// IsBucket determines whether this prefix is a valid S3 bucket name. func (s *S3Resolver) IsBucket(name string) bool { result, err := s.resolveCNAME(fmt.Sprintf("%s.%s.", name, s3host)) From d8835e5532aa234e9215289a2752c5983d51ffba Mon Sep 17 00:00:00 2001 From: Koen Rouwhorst Date: Sat, 17 Aug 2019 18:01:25 +0200 Subject: [PATCH 02/10] Remove unnecessary 'else' block --- bucket_checker.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bucket_checker.go b/bucket_checker.go index efdc381..a1c978c 100644 --- a/bucket_checker.go +++ b/bucket_checker.go @@ -52,9 +52,10 @@ func getConfig(nameserver string) (*dns.ClientConfig, error) { Servers: []string{addr.String()}, Port: "53", }, nil - } else { - return nil, errors.New("invalid ip addr") } + + return nil, errors.New("invalid ip addr") + } else { config, err := dns.ClientConfigFromFile("/etc/resolv.conf") From ae82f5045ea2c3d52d062a8bd52a0649e60b27d9 Mon Sep 17 00:00:00 2001 From: Koen Rouwhorst Date: Sat, 17 Aug 2019 18:05:13 +0200 Subject: [PATCH 03/10] Remove unneeded 'else' block --- bucket_checker.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/bucket_checker.go b/bucket_checker.go index a1c978c..09aa3e4 100644 --- a/bucket_checker.go +++ b/bucket_checker.go @@ -55,16 +55,15 @@ func getConfig(nameserver string) (*dns.ClientConfig, error) { } return nil, errors.New("invalid ip addr") + } - } else { - config, err := dns.ClientConfigFromFile("/etc/resolv.conf") - - if err != nil { - return nil, errors.New("could not read local resolver config") - } + config, err := dns.ClientConfigFromFile("/etc/resolv.conf") - return config, nil + if err != nil { + return nil, errors.New("could not read local resolver config") } + + return config, nil } func (s *S3Resolver) resolveCNAME(name string) (string, error) { From 731afecb5961c54494e18a32e657df08186f5ac5 Mon Sep 17 00:00:00 2001 From: Koen Rouwhorst Date: Sat, 17 Aug 2019 18:09:17 +0200 Subject: [PATCH 04/10] Get rid of global variables in main.go --- main.go | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index 5bc8dde..8012d16 100644 --- a/main.go +++ b/main.go @@ -6,14 +6,6 @@ import ( "os" ) -var ( - threads int - names []string - wordListFile string - preAndSuffixesFile string - nameserver string -) - const version = "0.0.1" const usage = `s3enum @@ -40,11 +32,12 @@ func main() { os.Exit(0) } - names = opts[""].([]string) - preAndSuffixesFile = opts["--suffixlist"].(string) - wordListFile = opts["--wordlist"].(string) - threads, _ = opts.Int("--threads") + names := opts[""].([]string) + preAndSuffixesFile := opts["--suffixlist"].(string) + wordListFile := opts["--wordlist"].(string) + threads, _ := opts.Int("--threads") + var nameserver string if opts["--nameserver"] == nil { nameserver = "" } else { From c386ba1108e86d36eb081abb161bfa40a6e54934 Mon Sep 17 00:00:00 2001 From: Koen Rouwhorst Date: Sat, 17 Aug 2019 18:11:32 +0200 Subject: [PATCH 05/10] Add newline between package and GitHub imports --- bucket_checker.go | 3 ++- main.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bucket_checker.go b/bucket_checker.go index 09aa3e4..1bedd10 100644 --- a/bucket_checker.go +++ b/bucket_checker.go @@ -3,9 +3,10 @@ package main import ( "errors" "fmt" - "github.com/miekg/dns" "net" "strings" + + "github.com/miekg/dns" ) type Resolver interface { diff --git a/main.go b/main.go index 8012d16..3a1939e 100644 --- a/main.go +++ b/main.go @@ -2,8 +2,9 @@ package main import ( "fmt" - "github.com/docopt/docopt-go" "os" + + "github.com/docopt/docopt-go" ) const version = "0.0.1" From 99bf13c3e75f3df2061455e0da9407c666c4d144 Mon Sep 17 00:00:00 2001 From: Koen Rouwhorst Date: Sat, 17 Aug 2019 18:15:16 +0200 Subject: [PATCH 06/10] Remove unused parameters --- consumer.go | 4 ++-- consumer_test.go | 5 +---- main.go | 13 ++----------- printer.go | 4 ++-- printer_test.go | 5 +---- 5 files changed, 8 insertions(+), 23 deletions(-) diff --git a/consumer.go b/consumer.go index c33b7b9..f953522 100644 --- a/consumer.go +++ b/consumer.go @@ -9,7 +9,7 @@ type Consumer struct { } // NewConsumer initializer -func NewConsumer(resolver Resolver, input chan string, result chan string, quit chan bool) (*Consumer, error) { +func NewConsumer(resolver Resolver, input chan string, result chan string, quit chan bool) *Consumer { consumer := &Consumer{ resolver: resolver, inputChannel: input, @@ -17,7 +17,7 @@ func NewConsumer(resolver Resolver, input chan string, result chan string, quit quit: quit, } - return consumer, nil + return consumer } // Consume reads messages from 'input', and outputs results to 'result'. diff --git a/consumer_test.go b/consumer_test.go index 778c34b..20abee1 100644 --- a/consumer_test.go +++ b/consumer_test.go @@ -24,10 +24,7 @@ func TestConsume(t *testing.T) { done3 := make(chan bool) resolver := NewTestResolver() - consumer, err := NewConsumer(resolver, inputChannel, resultChannel, done2) - if err != nil { - t.Errorf("fail!") - } + consumer := NewConsumer(resolver, inputChannel, resultChannel, done2) go consumer.Consume() diff --git a/main.go b/main.go index 3a1939e..ec72b3a 100644 --- a/main.go +++ b/main.go @@ -57,21 +57,12 @@ func main() { os.Exit(1) } - consumer, err := NewConsumer(resolver, wordChannel, resultChannel, wordDone) - if err != nil { - fmt.Fprintf(os.Stderr, "Could not initialize Consumer: %v\n", err) - os.Exit(1) - } - + consumer := NewConsumer(resolver, wordChannel, resultChannel, wordDone) for i := 0; i < threads; i++ { go consumer.Consume() } - printer, err := NewPrinter(resultChannel, resultDone) - if err != nil { - fmt.Fprintf(os.Stderr, "Could not initialize Printer: %v\n", err) - os.Exit(1) - } + printer := NewPrinter(resultChannel, resultDone) go printer.PrintBuckets() producer, err := NewProducer(preAndSuffixesFile, wordChannel, resultDone) diff --git a/printer.go b/printer.go index a35056d..75d8aba 100644 --- a/printer.go +++ b/printer.go @@ -17,13 +17,13 @@ type Printer struct { } // NewPrinter initializer -func NewPrinter(channel chan string, done chan bool) (*Printer, error) { +func NewPrinter(channel chan string, done chan bool) *Printer { printer := &Printer{ channel: channel, done: done, } - return printer, nil + return printer } // PrintBuckets prints the results as they come in. diff --git a/printer_test.go b/printer_test.go index 606ef75..8deb087 100644 --- a/printer_test.go +++ b/printer_test.go @@ -10,10 +10,7 @@ func TestPrintResults(t *testing.T) { channel := make(chan string) done := make(chan bool) - printer, err := NewPrinter(channel, done) - if err != nil { - t.Errorf("failed to initialize the Printer") - } + printer := NewPrinter(channel, done) go printer.PrintBuckets() From 8b0199edd5da5837a31fd055c311e76f2baf94fe Mon Sep 17 00:00:00 2001 From: Koen Rouwhorst Date: Sat, 17 Aug 2019 19:51:29 +0200 Subject: [PATCH 07/10] Remove global variable 'out' --- main.go | 2 +- printer.go | 11 ++++------- printer_test.go | 7 +++---- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index ec72b3a..2f5b59b 100644 --- a/main.go +++ b/main.go @@ -62,7 +62,7 @@ func main() { go consumer.Consume() } - printer := NewPrinter(resultChannel, resultDone) + printer := NewPrinter(resultChannel, resultDone, os.Stdout) go printer.PrintBuckets() producer, err := NewProducer(preAndSuffixesFile, wordChannel, resultDone) diff --git a/printer.go b/printer.go index 75d8aba..a55baf7 100644 --- a/printer.go +++ b/printer.go @@ -3,24 +3,21 @@ package main import ( "fmt" "io" - "os" -) - -var ( - out io.Writer = os.Stdout // substituted during testing ) // Printer struct type Printer struct { channel chan string done chan bool + out io.Writer } // NewPrinter initializer -func NewPrinter(channel chan string, done chan bool) *Printer { +func NewPrinter(channel chan string, done chan bool, out io.Writer) *Printer { printer := &Printer{ channel: channel, done: done, + out: out, } return printer @@ -31,7 +28,7 @@ func (c *Printer) PrintBuckets() { for { bucket, more := <-c.channel if more { - fmt.Fprintf(out, "%s\n", bucket) + fmt.Fprintf(c.out, "%s\n", bucket) } else { c.done <- true return diff --git a/printer_test.go b/printer_test.go index 8deb087..e043494 100644 --- a/printer_test.go +++ b/printer_test.go @@ -10,12 +10,11 @@ func TestPrintResults(t *testing.T) { channel := make(chan string) done := make(chan bool) - printer := NewPrinter(channel, done) + out := new(bytes.Buffer) // replace 'out' in order to capture the output + printer := NewPrinter(channel, done, out) go printer.PrintBuckets() - out = new(bytes.Buffer) // replace 'out' in order to capture the output - // produce some test results to the results channel for i := 1; i <= 5; i++ { channel <- fmt.Sprintf("test%v", i) @@ -30,7 +29,7 @@ func TestPrintResults(t *testing.T) { "test4\n" + "test5\n" - got := out.(*bytes.Buffer).String() + got := printer.out.(*bytes.Buffer).String() if got != expected { t.Errorf("expected %q, got %q", expected, got) } From c3fab1829b29d1a0ddd407128a6560394095f23b Mon Sep 17 00:00:00 2001 From: Koen Rouwhorst Date: Sat, 17 Aug 2019 19:53:51 +0200 Subject: [PATCH 08/10] Add GolangCI-Lint --- .github/workflows/test.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dc77706..8313a86 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,5 +24,13 @@ jobs: env: GOPROXY: https://proxy.golang.org + - name: Run linter + uses: docker://golangci/golangci-lint + env: + GOROOT: /usr/local/go + with: + entrypoint: golangci-lint + args: run --enable-all -D lll -D errcheck + - name: Run tests run: go test -mod readonly -race From 04108b022ae24ba5d959b81a58ea7ebb9ffd03c5 Mon Sep 17 00:00:00 2001 From: Koen Rouwhorst Date: Sat, 17 Aug 2019 20:01:08 +0200 Subject: [PATCH 09/10] Update CHANGELOG --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e67c946..8afa935 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ ## Unreleased -- Migrated CI from Travis CI to GitHub Actions +- Migrated CI from Travis CI to GitHub Actions [\#27](https://github.com/koenrh/s3enum/pull/27) +- Added GolangCI-Lint [\#28](https://github.com/koenrh/s3enum/pull/28) ## v0.1.0 From f0b286e753ce0d6bace5e3144b1782a589fdd0c0 Mon Sep 17 00:00:00 2001 From: Koen Rouwhorst Date: Mon, 19 Aug 2019 18:12:12 +0200 Subject: [PATCH 10/10] Rename 'out' to 'log' --- printer.go | 8 ++++---- printer_test.go | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/printer.go b/printer.go index a55baf7..496370b 100644 --- a/printer.go +++ b/printer.go @@ -9,15 +9,15 @@ import ( type Printer struct { channel chan string done chan bool - out io.Writer + log io.Writer } // NewPrinter initializer -func NewPrinter(channel chan string, done chan bool, out io.Writer) *Printer { +func NewPrinter(channel chan string, done chan bool, log io.Writer) *Printer { printer := &Printer{ channel: channel, done: done, - out: out, + log: log, } return printer @@ -28,7 +28,7 @@ func (c *Printer) PrintBuckets() { for { bucket, more := <-c.channel if more { - fmt.Fprintf(c.out, "%s\n", bucket) + fmt.Fprintf(c.log, "%s\n", bucket) } else { c.done <- true return diff --git a/printer_test.go b/printer_test.go index e043494..5bec368 100644 --- a/printer_test.go +++ b/printer_test.go @@ -10,8 +10,8 @@ func TestPrintResults(t *testing.T) { channel := make(chan string) done := make(chan bool) - out := new(bytes.Buffer) // replace 'out' in order to capture the output - printer := NewPrinter(channel, done, out) + log := new(bytes.Buffer) + printer := NewPrinter(channel, done, log) go printer.PrintBuckets() @@ -29,7 +29,7 @@ func TestPrintResults(t *testing.T) { "test4\n" + "test5\n" - got := printer.out.(*bytes.Buffer).String() + got := printer.log.(*bytes.Buffer).String() if got != expected { t.Errorf("expected %q, got %q", expected, got) }