add ports flag to k8scan

Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
This commit is contained in:
Jess Frazelle 2018-07-13 18:15:51 -04:00
parent 2d54ed719f
commit 9c8aba5125
No known key found for this signature in database
GPG Key ID: 18F3685C0022BFF3
3 changed files with 21 additions and 19 deletions

View File

@ -5,20 +5,23 @@ ENV PATH /go/bin:/usr/local/go/bin:$PATH
ENV GOPATH /go ENV GOPATH /go
RUN apk add --no-cache \ 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 \ 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 . \ && go get -d . \
&& gofmt -s -l . \ && gofmt -s -l . \
&& go vet ./... \ && go vet ./... \
@ -26,8 +29,6 @@ RUN set -x \
&& staticcheck ./... \ && staticcheck ./... \
&& go test ./... \ && go test ./... \
&& CGO_ENABLED=0 go build -a -tags netgo -ldflags '-w -extldflags "-static"' -o /usr/bin/k8scan *.go \ && 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." && echo "Build complete."
FROM scratch FROM scratch

View File

@ -36,7 +36,7 @@ var (
cidr string cidr string
defaultPorts = intSlice{80, 443, 9001, 8001} defaultPorts = intSlice{80, 443, 8001, 9001}
ports intSlice ports intSlice
mailgunDomain string mailgunDomain string
@ -53,7 +53,7 @@ type intSlice []int
func (i *intSlice) String() (out string) { func (i *intSlice) String() (out string) {
for k, v := range *i { for k, v := range *i {
if k < len(*i)-1 { if k < len(*i)-1 {
out += fmt.Sprintf("%d, ", v) out += fmt.Sprintf("%d,", v)
} else { } else {
out += fmt.Sprintf("%d", v) out += fmt.Sprintf("%d", v)
} }
@ -89,7 +89,7 @@ func (i *intSlice) Set(value string) error {
*i = append(*i, port) *i = append(*i, port)
} }
return nil continue
} }
// It is not a range just parse the port // It is not a range just parse the port
@ -272,7 +272,7 @@ type ARINResponse struct {
Net NetJSON `json:"net,omitempty"` 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 { type NetJSON struct {
Organization OrganizationJSON `json:"orgRef,omitempty"` Organization OrganizationJSON `json:"orgRef,omitempty"`
} }

View File

@ -1,8 +1,9 @@
package main package main
import ( import (
"reflect"
"testing" "testing"
"github.com/google/go-cmp/cmp"
) )
func TestARINResponse(t *testing.T) { func TestARINResponse(t *testing.T) {
@ -54,7 +55,7 @@ func TestParsePortRange(t *testing.T) {
if err := i.Set(testFunc.given); err != nil { if err := i.Set(testFunc.given); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if reflect.DeepEqual(testFunc.expected, i) { if !cmp.Equal(testFunc.expected, i) {
t.Fatalf("expected: %#v\ngot: %#v", testFunc.expected, i) t.Fatalf("expected: %#v\ngot: %#v", testFunc.expected, i)
} }
} }