From 9c8aba5125eb9492ad6aed8d91c7e8476c3f4b06 Mon Sep 17 00:00:00 2001 From: Jess Frazelle Date: Fri, 13 Jul 2018 18:15:51 -0400 Subject: [PATCH] add ports flag to k8scan Signed-off-by: Jess Frazelle --- k8scan/Dockerfile | 27 ++++++++++++++------------- k8scan/main.go | 8 ++++---- k8scan/main_test.go | 5 +++-- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/k8scan/Dockerfile b/k8scan/Dockerfile index fe3a09a..045b694 100644 --- a/k8scan/Dockerfile +++ b/k8scan/Dockerfile @@ -5,20 +5,23 @@ ENV PATH /go/bin:/usr/local/go/bin:$PATH ENV GOPATH /go RUN apk add --no-cache \ - ca-certificates + ca-certificates \ + git \ + gcc \ + libc-dev \ + libgcc \ + make -COPY main.go /go/src/k8scan/ +# Get go deps for tests etc. +RUN go get honnef.co/go/tools/cmd/staticcheck \ + github.com/golang/lint/golint \ + github.com/google/go-cmp/cmp + +WORKDIR /go/src/k8scan + +COPY *.go /go/src/k8scan/ RUN set -x \ - && apk add --no-cache --virtual .build-deps \ - git \ - gcc \ - libc-dev \ - libgcc \ - make \ - && go get honnef.co/go/tools/cmd/staticcheck \ - && go get github.com/golang/lint/golint \ - && cd /go/src/k8scan/ \ && go get -d . \ && gofmt -s -l . \ && go vet ./... \ @@ -26,8 +29,6 @@ RUN set -x \ && staticcheck ./... \ && go test ./... \ && CGO_ENABLED=0 go build -a -tags netgo -ldflags '-w -extldflags "-static"' -o /usr/bin/k8scan *.go \ - && apk del .build-deps \ - && rm -rf /go \ && echo "Build complete." FROM scratch diff --git a/k8scan/main.go b/k8scan/main.go index 905fac5..ac8b3fa 100644 --- a/k8scan/main.go +++ b/k8scan/main.go @@ -36,7 +36,7 @@ var ( cidr string - defaultPorts = intSlice{80, 443, 9001, 8001} + defaultPorts = intSlice{80, 443, 8001, 9001} ports intSlice mailgunDomain string @@ -53,7 +53,7 @@ type intSlice []int func (i *intSlice) String() (out string) { for k, v := range *i { if k < len(*i)-1 { - out += fmt.Sprintf("%d, ", v) + out += fmt.Sprintf("%d,", v) } else { out += fmt.Sprintf("%d", v) } @@ -89,7 +89,7 @@ func (i *intSlice) Set(value string) error { *i = append(*i, port) } - return nil + continue } // It is not a range just parse the port @@ -272,7 +272,7 @@ type ARINResponse struct { Net NetJSON `json:"net,omitempty"` } -// NETJSON holds the net data from the ARIN response. +// NetJSON holds the net data from the ARIN response. type NetJSON struct { Organization OrganizationJSON `json:"orgRef,omitempty"` } diff --git a/k8scan/main_test.go b/k8scan/main_test.go index a98ab14..c32671c 100644 --- a/k8scan/main_test.go +++ b/k8scan/main_test.go @@ -1,8 +1,9 @@ package main import ( - "reflect" "testing" + + "github.com/google/go-cmp/cmp" ) func TestARINResponse(t *testing.T) { @@ -54,7 +55,7 @@ func TestParsePortRange(t *testing.T) { if err := i.Set(testFunc.given); err != nil { t.Fatal(err) } - if reflect.DeepEqual(testFunc.expected, i) { + if !cmp.Equal(testFunc.expected, i) { t.Fatalf("expected: %#v\ngot: %#v", testFunc.expected, i) } }