From 4f73092fa3296d31ffec0012d83e02e1beff74a1 Mon Sep 17 00:00:00 2001 From: Martin Buchleitner Date: Fri, 22 Mar 2024 12:21:31 +0100 Subject: [PATCH 1/7] feat: simpler build Signed-off-by: Martin Buchleitner --- .dockerignore | 3 ++- .gitignore | 1 + Dockerfile | 31 ++++++++++++++++++++++++------- Dockerfile.arm | 18 ------------------ Dockerfile.arm64 | 18 ------------------ Makefile | 43 +++++++++++++++++++++++++++++++++++++++++-- go.sum | 15 --------------- 7 files changed, 68 insertions(+), 61 deletions(-) create mode 100644 .gitignore delete mode 100644 Dockerfile.arm delete mode 100644 Dockerfile.arm64 diff --git a/.dockerignore b/.dockerignore index e0632788..fcc070bc 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,4 @@ example -.travis.yml .git +.github +traefik-forward-auth \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..d774cde1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +traefik-forward-auth diff --git a/Dockerfile b/Dockerfile index b3c6e327..86ba063c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,35 @@ FROM golang:1.13-alpine as builder -# Setup -RUN mkdir -p /go/src/github.com/thomseddon/traefik-forward-auth -WORKDIR /go/src/github.com/thomseddon/traefik-forward-auth +# build +ARG TARGETOS +ARG TARGETARCH +ARG TARGETVARIANT + +RUN case "${TARGETVARIANT}" in \ + "armhf") export GOARM='6' ;; \ + "armv7") export GOARM='6' ;; \ + "v6") export GOARM='6' ;; \ + "v7") export GOARM='7' ;; \ + esac; # Add libraries -RUN apk add --no-cache git +RUN apk add --no-cache git make ca-certificates + +# Setup +WORKDIR /build + +# download modules +COPY go.mod . +COPY go.sum . +RUN go mod download + # Copy & build -ADD . /go/src/github.com/thomseddon/traefik-forward-auth/ -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -installsuffix nocgo -o /traefik-forward-auth github.com/thomseddon/traefik-forward-auth/cmd +COPY . . +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GO111MODULE=on make build # Copy into scratch container FROM scratch COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ -COPY --from=builder /traefik-forward-auth ./ +COPY --from=builder /build/traefik-forward-auth ./ ENTRYPOINT ["./traefik-forward-auth"] diff --git a/Dockerfile.arm b/Dockerfile.arm deleted file mode 100644 index e10021e6..00000000 --- a/Dockerfile.arm +++ /dev/null @@ -1,18 +0,0 @@ -FROM golang:1.13-alpine as builder - -# Setup -RUN mkdir -p /go/src/github.com/thomseddon/traefik-forward-auth -WORKDIR /go/src/github.com/thomseddon/traefik-forward-auth - -# Add libraries -RUN apk add --no-cache git - -# Copy & build -ADD . /go/src/github.com/thomseddon/traefik-forward-auth/ -RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm GO111MODULE=on go build -a -installsuffix nocgo -o /traefik-forward-auth github.com/thomseddon/traefik-forward-auth/cmd - -# Copy into scratch container -FROM scratch -COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ -COPY --from=builder /traefik-forward-auth ./ -ENTRYPOINT ["./traefik-forward-auth"] diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 deleted file mode 100644 index a9806863..00000000 --- a/Dockerfile.arm64 +++ /dev/null @@ -1,18 +0,0 @@ -FROM golang:1.13-alpine as builder - -# Setup -RUN mkdir -p /go/src/github.com/thomseddon/traefik-forward-auth -WORKDIR /go/src/github.com/thomseddon/traefik-forward-auth - -# Add libraries -RUN apk add --no-cache git - -# Copy & build -ADD . /go/src/github.com/thomseddon/traefik-forward-auth/ -RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 GO111MODULE=on go build -a -installsuffix nocgo -o /traefik-forward-auth github.com/thomseddon/traefik-forward-auth/cmd - -# Copy into scratch container -FROM scratch -COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ -COPY --from=builder /traefik-forward-auth ./ -ENTRYPOINT ["./traefik-forward-auth"] diff --git a/Makefile b/Makefile index b2fdc66a..f57b2a23 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,47 @@ +TAG_NAME := $(shell test -d .git && git describe --abbrev=0 --tags || echo "") +SHA := $(shell test -d .git && git rev-parse --short HEAD) +COMMIT := $(SHA) +# hide commit for releases +ifeq ($(RELEASE),1) + COMMIT := +endif +ARTEFACT := traefik-forward-auth +VERSION := $(if $(TAG_NAME),$(TAG_NAME),$(SHA)) +BUILD_DATE := $(shell date -u '+%Y-%m-%d_%H:%M:%S') +BUILD_TAGS:= -a -installsuffix nocgo +#BUILD_ARGS := -trimpath + +IMAGE := mabunixda/$(ARTEFACT) +PLATFORM := linux/arm64,linux/amd64,linux/arm/v7 + +default: clean format build + +clean: + rm -f $(ARTEFACT) format: - gofmt -w -s internal/*.go internal/provider/*.go cmd/*.go + gofmt -w -l $$(find . -name '*.go') test: go test -v ./... -.PHONY: format test +porcelain:: + gofmt -w -l $$(find . -name '*.go') + go mod tidy + test -z "$$(git status --porcelain)" || (git status; git diff; false) + +build:: + @echo Version: $(VERSION) $(SHA) $(BUILD_DATE) + CGO_ENABLED=0 go build -o $(ARTEFACT) $(BUILD_TAGS) $(BUILD_ARGS) ./cmd/ + +docker:: + @echo Version: $(VERSION) $(SHA) $(BUILD_DATE) + docker buildx build --platform $(PLATFORM) --tag $(IMAGE):testing . + +publish-testing:: + @echo Version: $(VERSION) $(SHA) $(BUILD_DATE) + docker build --platform $(PLATFORM) --tag $(IMAGE):testing --push . + +publish-latest:: + @echo Version: $(VERSION) $(SHA) $(BUILD_DATE) + docker build --platform $(PLATFORM) --tag $(IMAGE):latest --tag $(IMAGE):$(VERSION) --push . diff --git a/go.sum b/go.sum index fd583712..02053fac 100644 --- a/go.sum +++ b/go.sum @@ -127,7 +127,6 @@ github.com/go-acme/lego/v3 v3.2.0/go.mod h1:074uqt+JS6plx+c9Xaiz6+L+GBb+7itGtzfc github.com/go-cmd/cmd v1.0.5/go.mod h1:y8q8qlK5wQibcw63djSl/ntiHUHXHGdCkPk0j4QeW4s= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= github.com/go-ini/ini v1.44.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= -github.com/go-kit/kit v0.8.0 h1:Wz+5lgoB0kkuqLEc6NVmwRknTKP6dTGbSqvhZtBI/j0= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.9.0 h1:wDJmvq38kDhkVxi50ni9ykkdUr1PKgqKOoi01fa0Mdk= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= @@ -145,7 +144,6 @@ github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4er github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= @@ -229,7 +227,6 @@ github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfV github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kolo/xmlrpc v0.0.0-20190717152603-07c4ee3fd181/go.mod h1:o03bZfuBwAXHetKXuInt4S7omeXUu62/A845kiycsSQ= -github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -349,7 +346,6 @@ github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdh github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= -github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= @@ -357,13 +353,11 @@ github.com/skratchdot/open-golang v0.0.0-20160302144031-75fb7ed4208c/go.mod h1:s github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= -github.com/spf13/pflag v1.0.1 h1:aCvUg6QPl3ibpQUxyLkrEkCHtPqYJL4x9AuhqVqFis4= github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= @@ -436,7 +430,6 @@ golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190206173232-65e2d4e15006/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -457,7 +450,6 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sys v0.0.0-20180622082034-63fc586f45fe/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -469,7 +461,6 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -493,10 +484,8 @@ golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3 golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135 h1:5Beo0mZN8dRzgrMMkDp0jc8YXQKx9DiJ2k1dkvGsn5A= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -gonum.org/v1/gonum v0.0.0-20190331200053-3d26580ed485 h1:OB/uP/Puiu5vS5QMRPrXCDWUPb+kt8f1KW8oQzFejQw= gonum.org/v1/gonum v0.0.0-20190331200053-3d26580ed485/go.mod h1:2ltnJ7xHfj0zHS40VVPYEAAMTa3ZGguvHGBSJeRWqE0= gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw= gonum.org/v1/netlib v0.0.0-20190331212654-76723241ea4e/go.mod h1:kS+toOQn6AQKjmKJ7gzohV1XkqsFehRA2FbsbkopSuQ= @@ -504,7 +493,6 @@ google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMt google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0 h1:KxkO13IPW4Lslp2bz+KHP2E3gtFlrIGNThxkZQ3g+4c= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -553,11 +541,8 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh k8s.io/api v0.0.0-20190718183219-b59d8169aab5/go.mod h1:TBhBqb1AWbBQbW3XRusr7n7E4v2+5ZY8r8sAMnyFC5A= k8s.io/apimachinery v0.0.0-20190612205821-1799e75a0719/go.mod h1:I4A+glKBHiTgiEjQiCCQfCAIcIMFGt291SmsvcrFzJA= k8s.io/client-go v0.0.0-20190718183610-8e956561bbf5/go.mod h1:ozblAqkW495yoAX60QZyxQBq5W0YixE9Ffn4F91RO0g= -k8s.io/code-generator v0.0.0-20190612205613-18da4a14b22b h1:p+PRuwXWwk5e+UYvicGiavEupapqM5NOxUl3y1GkD6c= k8s.io/code-generator v0.0.0-20190612205613-18da4a14b22b/go.mod h1:G8bQwmHm2eafm5bgtX67XDZQ8CWKSGu9DekI+yN4Y5I= -k8s.io/gengo v0.0.0-20190116091435-f8a0810f38af h1:SwjZbO0u5ZuaV6TRMWOGB40iaycX8sbdMQHtjNZ19dk= k8s.io/gengo v0.0.0-20190116091435-f8a0810f38af/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= -k8s.io/klog v0.3.1 h1:RVgyDHY/kFKtLqh67NvEWIgkMneNoIrdkN0CxDSQc68= k8s.io/klog v0.3.1/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= k8s.io/kube-openapi v0.0.0-20190228160746-b3a7cee44a30/go.mod h1:BXM9ceUBTj2QnfH2MK1odQs778ajze1RxcmP6S8RVVc= k8s.io/utils v0.0.0-20190221042446-c2654d5206da/go.mod h1:8k8uAuAQ0rXslZKaEWd0c3oVhZz7sSzSiPnVZayjIX0= From 904cc99521051e6f76f7a7c9647fa032d0b430e2 Mon Sep 17 00:00:00 2001 From: Martin Buchleitner Date: Fri, 22 Mar 2024 14:23:23 +0100 Subject: [PATCH 2/7] feat: own default workflow Signed-off-by: Martin Buchleitner --- .github/workflows/ci.yml | 36 -------------------- .github/workflows/default.yml | 63 +++++++++++++++++++++++++++++++++++ Dockerfile | 4 +-- go.mod | 24 +++++++++++-- go.sum | 2 -- 5 files changed, 87 insertions(+), 42 deletions(-) delete mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/default.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index b41214e6..00000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: CI - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - - test: - name: Test - runs-on: ubuntu-latest - steps: - - - name: Set up Go 1.x - uses: actions/setup-go@v2 - with: - go-version: ^1.13 - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - - name: Get dependencies - run: | - go get -v -t -d ./... - if [ -f Gopkg.toml ]; then - curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh - dep ensure - fi - - - name: Build - run: go build -v ./... - - - name: Test - run: go test -v ./... diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml new file mode 100644 index 00000000..cdb69cca --- /dev/null +++ b/.github/workflows/default.yml @@ -0,0 +1,63 @@ +name: Default +on: + push: + branches: + - '*' + pull_request: + branches: + - main + +jobs: + build: + name: Build + runs-on: ubuntu-latest + + steps: + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ^1.18 + id: go + + - name: Cache Go modules + uses: actions/cache@v2 + with: + path: | + ~/go/pkg + ~/.cache/go-build + key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-${{ matrix.go-version }}-go- + + - name: Checkout + uses: actions/checkout@v3 + + - name: remove golangci from precommit-configuration + run: | + sed -i 's/.*id: golangci-lint//' .pre-commit-config.yaml + sed -i '/^\s*$/d' .pre-commit-config.yaml + + - uses: pre-commit/action@v3.0.0 + continue-on-error: true + + - name: Build + run: make all + + - name: Lint + uses: golangci/golangci-lint-action@v3 + with: + version: latest + skip-pkg-cache: true + skip-build-cache: true + + - uses: go-semantic-release/action@v1 + id: semrel + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + changelog-file: CHANGELOG.md + + - uses: rhysd/changelog-from-release/action@v2 + if: steps.semrel.outputs.version != '' + with: + file: CHANGELOG.md + github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/Dockerfile b/Dockerfile index 86ba063c..dc9320e0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.13-alpine as builder +FROM golang:1.22-alpine as builder # build ARG TARGETOS @@ -26,7 +26,7 @@ RUN go mod download # Copy & build COPY . . -RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GO111MODULE=on make build +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} make build # Copy into scratch container FROM scratch diff --git a/go.mod b/go.mod index 2c6eb8a8..72f48dfb 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,10 @@ module github.com/thomseddon/traefik-forward-auth -go 1.13 +go 1.22 require ( github.com/containous/traefik/v2 v2.1.2 github.com/coreos/go-oidc v2.1.0+incompatible - github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect github.com/sirupsen/logrus v1.4.2 github.com/stretchr/testify v1.4.0 github.com/thomseddon/go-flags v1.4.1-0.20190507184247-a3629c504486 @@ -13,6 +12,27 @@ require ( gopkg.in/square/go-jose.v2 v2.3.1 ) +require ( + github.com/containous/alice v0.0.0-20181107144136-d83ebdd94cbd // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/golang/protobuf v1.3.2 // indirect + github.com/gorilla/context v1.1.1 // indirect + github.com/gorilla/mux v1.7.3 // indirect + github.com/gravitational/trace v0.0.0-20190726142706-a535a178675f // indirect + github.com/jonboulle/clockwork v0.1.0 // indirect + github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect + github.com/miekg/dns v1.1.15 // indirect + github.com/patrickmn/go-cache v2.1.0+incompatible // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect + github.com/vulcand/predicate v1.1.0 // indirect + golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 // indirect + golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3 // indirect + golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a // indirect + google.golang.org/appengine v1.5.0 // indirect + gopkg.in/yaml.v2 v2.2.2 // indirect +) + // From traefik replace ( github.com/Azure/go-autorest => github.com/Azure/go-autorest v12.4.1+incompatible diff --git a/go.sum b/go.sum index 02053fac..a411d05b 100644 --- a/go.sum +++ b/go.sum @@ -17,7 +17,6 @@ github.com/Azure/go-autorest/autorest/to v0.2.0/go.mod h1:GunWKJp1AEqgMaGLV+iocm github.com/Azure/go-autorest/autorest/validation v0.1.0/go.mod h1:Ha3z/SqBeaalWQvokg3NZAlQTalVMtOIAs1aGK7G6u8= github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc= github.com/Azure/go-autorest/tracing v0.1.0/go.mod h1:ROEEAFwXycQw7Sn3DXNtEedEvdeRAgDr0izn4z5Ij88= -github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DataDog/datadog-go v2.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= @@ -33,7 +32,6 @@ github.com/OpenDNS/vegadns2client v0.0.0-20180418235048-a3fa4a771d87/go.mod h1:i github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/sarama v1.23.1/go.mod h1:XLH1GYJnLVE0XCr6KdJGVJRTwY30moWNJ4sERjXX6fs= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= -github.com/VividCortex/gohistogram v1.0.0 h1:6+hBz+qvs0JOrrNhhmR7lFxo5sINxBCGXrdtl/UvroE= github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g= github.com/abronan/valkeyrie v0.0.0-20190822142731-f2e1850dc905/go.mod h1:hTreU6x9m2IP2h8e0TGrSzAXSCI3lxic8/JT5CMknjY= github.com/akamai/AkamaiOPEN-edgegrid-golang v0.9.0/go.mod h1:zpDJeKyp9ScW4NNrbdr+Eyxvry3ilGPewKoXw3XGN1k= From ffb77865132383f980378f57edd75dbd960d32ca Mon Sep 17 00:00:00 2001 From: Martin Buchleitner Date: Fri, 22 Mar 2024 14:48:00 +0100 Subject: [PATCH 3/7] adding precommit cfg Signed-off-by: Martin Buchleitner --- .pre-commit-config.yaml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..c687ec2d --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,20 @@ +--- +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - repo: https://github.com/dnephin/pre-commit-golang + rev: v0.5.1 + hooks: + - id: go-fmt + - id: go-vet + args: [-over=15] + - id: validate-toml + - id: no-go-testing + - id: go-unit-tests + - id: go-build + - id: go-mod-tidy + - id: golangci-lint From 73a69175363dd5c3bfc86e336d56a080747d6ebd Mon Sep 17 00:00:00 2001 From: Martin Buchleitner Date: Fri, 22 Mar 2024 14:49:14 +0100 Subject: [PATCH 4/7] codeql update Signed-off-by: Martin Buchleitner --- .github/workflows/codeql-analysis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index f8786ef5..2bbe77ad 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -43,18 +43,18 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v1 + uses: github/codeql-action/init@v2 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. + # By default, queries listed here will override any specified in a config file. # Prefix the list here with "+" to use these queries and those in the config file. # queries: ./path/to/local/query, your-org/your-repo/queries@main # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v1 + uses: github/codeql-action/autobuild@v2 # â„šī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl From b32bf403dc489b082b3fd92c2b049bc61381b8c7 Mon Sep 17 00:00:00 2001 From: Martin Buchleitner Date: Fri, 22 Mar 2024 14:50:03 +0100 Subject: [PATCH 5/7] all vs build Signed-off-by: Martin Buchleitner --- .github/workflows/default.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml index cdb69cca..e01908fc 100644 --- a/.github/workflows/default.yml +++ b/.github/workflows/default.yml @@ -41,7 +41,7 @@ jobs: continue-on-error: true - name: Build - run: make all + run: make build - name: Lint uses: golangci/golangci-lint-action@v3 From add6398cc3b7ff1f9d43f2c454a9fc8a8d0be042 Mon Sep 17 00:00:00 2001 From: Martin Buchleitner Date: Fri, 22 Mar 2024 14:50:56 +0100 Subject: [PATCH 6/7] codeql removal Signed-off-by: Martin Buchleitner --- .github/workflows/codeql-analysis.yml | 71 --------------------------- 1 file changed, 71 deletions(-) delete mode 100644 .github/workflows/codeql-analysis.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index 2bbe77ad..00000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,71 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -name: "CodeQL" - -on: - push: - branches: [master] - pull_request: - # The branches below must be a subset of the branches above - branches: [master] - schedule: - - cron: '0 10 * * 2' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - # Override automatic language detection by changing the below list - # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python'] - language: ['go'] - # Learn more... - # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - with: - # We must fetch at least the immediate parents so that if this is - # a pull request then we can checkout the head. - fetch-depth: 2 - - # If this run was triggered by a pull request event, then checkout - # the head of the pull request instead of the merge commit. - - run: git checkout HEAD^2 - if: ${{ github.event_name == 'pull_request' }} - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v2 - - # â„šī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # âœī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 From da680012be3c1b54a0c39d7e0795a3959714d658 Mon Sep 17 00:00:00 2001 From: Martin Buchleitner Date: Fri, 22 Mar 2024 15:36:15 +0100 Subject: [PATCH 7/7] fix some linting failures Signed-off-by: Martin Buchleitner --- .dockerignore | 2 +- .github/FUNDING.yml | 1 - .pre-commit-config.yaml | 4 +--- .../advanced-separate-pod/whoami/service.yaml | 1 - .../advanced-single-pod/traefik/rbac.yaml | 1 + .../advanced-single-pod/whoami/service.yaml | 1 - .../advanced-separate-pod/whoami/service.yaml | 1 - .../advanced-single-pod/whoami/service.yaml | 1 - .../traefik-v2/swarm/docker-compose-oidc.yml | 1 - go.mod | 4 ++++ internal/config.go | 7 +++---- internal/config_test.go | 4 ++-- internal/provider/generic_oauth.go | 2 +- internal/provider/google.go | 3 +-- internal/provider/oidc_test.go | 17 +++++++---------- internal/provider/providers_test.go | 4 ++-- internal/server.go | 4 ++-- internal/server_test.go | 8 ++++---- 18 files changed, 29 insertions(+), 37 deletions(-) diff --git a/.dockerignore b/.dockerignore index fcc070bc..11b3e967 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,4 @@ example .git .github -traefik-forward-auth \ No newline at end of file +traefik-forward-auth diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 973a5aa7..0775b752 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,2 +1 @@ github: thomseddon - diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c687ec2d..626086c2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,15 +4,13 @@ repos: rev: v4.4.0 hooks: - id: check-yaml + args: [--allow-multiple-documents] - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/dnephin/pre-commit-golang rev: v0.5.1 hooks: - id: go-fmt - - id: go-vet - args: [-over=15] - - id: validate-toml - id: no-go-testing - id: go-unit-tests - id: go-build diff --git a/examples/traefik-v1.7/kubernetes/advanced-separate-pod/whoami/service.yaml b/examples/traefik-v1.7/kubernetes/advanced-separate-pod/whoami/service.yaml index 77c8eb0f..db030049 100644 --- a/examples/traefik-v1.7/kubernetes/advanced-separate-pod/whoami/service.yaml +++ b/examples/traefik-v1.7/kubernetes/advanced-separate-pod/whoami/service.yaml @@ -11,4 +11,3 @@ spec: port: 80 selector: app: whoami - diff --git a/examples/traefik-v1.7/kubernetes/advanced-single-pod/traefik/rbac.yaml b/examples/traefik-v1.7/kubernetes/advanced-single-pod/traefik/rbac.yaml index ad1443c5..22722bfc 100644 --- a/examples/traefik-v1.7/kubernetes/advanced-single-pod/traefik/rbac.yaml +++ b/examples/traefik-v1.7/kubernetes/advanced-single-pod/traefik/rbac.yaml @@ -1,3 +1,4 @@ +--- # # RBAC # Source: traefik/templates/rbac.yaml diff --git a/examples/traefik-v1.7/kubernetes/advanced-single-pod/whoami/service.yaml b/examples/traefik-v1.7/kubernetes/advanced-single-pod/whoami/service.yaml index 77c8eb0f..db030049 100644 --- a/examples/traefik-v1.7/kubernetes/advanced-single-pod/whoami/service.yaml +++ b/examples/traefik-v1.7/kubernetes/advanced-single-pod/whoami/service.yaml @@ -11,4 +11,3 @@ spec: port: 80 selector: app: whoami - diff --git a/examples/traefik-v2/kubernetes/advanced-separate-pod/whoami/service.yaml b/examples/traefik-v2/kubernetes/advanced-separate-pod/whoami/service.yaml index 77c8eb0f..db030049 100644 --- a/examples/traefik-v2/kubernetes/advanced-separate-pod/whoami/service.yaml +++ b/examples/traefik-v2/kubernetes/advanced-separate-pod/whoami/service.yaml @@ -11,4 +11,3 @@ spec: port: 80 selector: app: whoami - diff --git a/examples/traefik-v2/kubernetes/advanced-single-pod/whoami/service.yaml b/examples/traefik-v2/kubernetes/advanced-single-pod/whoami/service.yaml index 77c8eb0f..db030049 100644 --- a/examples/traefik-v2/kubernetes/advanced-single-pod/whoami/service.yaml +++ b/examples/traefik-v2/kubernetes/advanced-single-pod/whoami/service.yaml @@ -11,4 +11,3 @@ spec: port: 80 selector: app: whoami - diff --git a/examples/traefik-v2/swarm/docker-compose-oidc.yml b/examples/traefik-v2/swarm/docker-compose-oidc.yml index db75aba8..93f63206 100644 --- a/examples/traefik-v2/swarm/docker-compose-oidc.yml +++ b/examples/traefik-v2/swarm/docker-compose-oidc.yml @@ -31,4 +31,3 @@ services: - "traefik.http.middlewares.traefik-forward-auth.forwardauth.address=http://traefik-forward-auth:4181" - "traefik.http.middlewares.traefik-forward-auth.forwardauth.authResponseHeaders=X-Forwarded-User" - "traefik.http.services.traefik-forward-auth.loadbalancer.server.port=4181" - diff --git a/go.mod b/go.mod index 72f48dfb..f46d9755 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,10 @@ module github.com/thomseddon/traefik-forward-auth go 1.22 +replace github.com/thomseddon/traefik-forward-auth/internal/provider => ./internal/provider + +replace github.com/thomseddon/traefik-forward-auth/internal => ./internal + require ( github.com/containous/traefik/v2 v2.1.2 github.com/coreos/go-oidc v2.1.0+incompatible diff --git a/internal/config.go b/internal/config.go index 840fb6dc..cfcec76d 100644 --- a/internal/config.go +++ b/internal/config.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "os" "regexp" "strconv" @@ -213,11 +212,11 @@ func (c *Config) parseUnknownFlag(option string, arg flags.SplitArgument, args [ rule.Provider = val case "whitelist": list := CommaSeparatedList{} - list.UnmarshalFlag(val) + _ = list.UnmarshalFlag(val) rule.Whitelist = list case "domains": list := CommaSeparatedList{} - list.UnmarshalFlag(val) + _ = list.UnmarshalFlag(val) rule.Domains = list default: return args, fmt.Errorf("invalid route param: %v", option) @@ -242,7 +241,7 @@ func handleFlagError(err error) error { var legacyFileFormat = regexp.MustCompile(`(?m)^([a-z-]+) (.*)$`) func convertLegacyToIni(name string) (io.Reader, error) { - b, err := ioutil.ReadFile(name) + b, err := os.ReadFile(name) if err != nil { return nil, err } diff --git a/internal/config_test.go b/internal/config_test.go index 27b8fdc8..fb3abbae 100644 --- a/internal/config_test.go +++ b/internal/config_test.go @@ -375,7 +375,7 @@ func TestConfigGetProvider(t *testing.T) { assert.Equal(&c.Providers.GenericOAuth, p) // Should catch unknown provider - p, err = c.GetProvider("bad") + _, err = c.GetProvider("bad") if assert.Error(err) { assert.Equal("Unknown provider: bad", err.Error()) } @@ -391,7 +391,7 @@ func TestConfigGetConfiguredProvider(t *testing.T) { assert.Equal(&c.Providers.Google, p) // Should fail to get valid "oidc" provider as it's not configured - p, err = c.GetConfiguredProvider("oidc") + _, err = c.GetConfiguredProvider("oidc") if assert.Error(err) { assert.Equal("Unconfigured provider: oidc", err.Error()) } diff --git a/internal/provider/generic_oauth.go b/internal/provider/generic_oauth.go index a6bba510..1bc2c035 100644 --- a/internal/provider/generic_oauth.go +++ b/internal/provider/generic_oauth.go @@ -17,7 +17,7 @@ type GenericOAuth struct { UserURL string `long:"user-url" env:"USER_URL" description:"URL used to retrieve user info"` ClientID string `long:"client-id" env:"CLIENT_ID" description:"Client ID"` ClientSecret string `long:"client-secret" env:"CLIENT_SECRET" description:"Client Secret" json:"-"` - Scopes []string `long:"scope" env:"SCOPE" env-delim:"," default:"profile" default:"email" description:"Scopes"` + Scopes []string `long:"scope" env:"SCOPE" env-delim:"," default:"email" description:"Scopes"` TokenStyle string `long:"token-style" env:"TOKEN_STYLE" default:"header" choice:"header" choice:"query" description:"How token is presented when querying the User URL"` OAuthProvider diff --git a/internal/provider/google.go b/internal/provider/google.go index 1c0d6d10..7f602be9 100644 --- a/internal/provider/google.go +++ b/internal/provider/google.go @@ -64,8 +64,7 @@ func (g *Google) GetLoginURL(redirectURI, state string) string { q.Set("redirect_uri", redirectURI) q.Set("state", state) - var u url.URL - u = *g.LoginURL + u := *g.LoginURL u.RawQuery = q.Encode() return u.String() diff --git a/internal/provider/oidc_test.go b/internal/provider/oidc_test.go index d514d37c..491ecaeb 100644 --- a/internal/provider/oidc_test.go +++ b/internal/provider/oidc_test.go @@ -4,7 +4,7 @@ import ( "crypto/rand" "crypto/rsa" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/url" @@ -138,15 +138,12 @@ func setupOIDCTest(t *testing.T, bodyValues map[string]map[string]string) (*OIDC } body := make(map[string]string) - if bodyValues != nil { - // URL encode bodyValues into body - for method, values := range bodyValues { - q := url.Values{} - for k, v := range values { - q.Set(k, v) - } - body[method] = q.Encode() + for method, values := range bodyValues { + q := url.Values{} + for k, v := range values { + q.Set(k, v) } + body[method] = q.Encode() } // Set up oidc server @@ -184,7 +181,7 @@ func NewOIDCServer(t *testing.T, key *rsaKey, body map[string]string) (*httptest } func (s *OIDCServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { - body, _ := ioutil.ReadAll(r.Body) + body, _ := io.ReadAll(r.Body) if r.URL.Path == "/.well-known/openid-configuration" { // Open id config diff --git a/internal/provider/providers_test.go b/internal/provider/providers_test.go index 47ab9e28..d77f8b2f 100644 --- a/internal/provider/providers_test.go +++ b/internal/provider/providers_test.go @@ -2,7 +2,7 @@ package provider import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/url" @@ -25,7 +25,7 @@ func NewOAuthServer(t *testing.T, body map[string]string) (*httptest.Server, *ur } func (s *OAuthServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { - body, _ := ioutil.ReadAll(r.Body) + body, _ := io.ReadAll(r.Body) // fmt.Println("Got request:", r.URL, r.Method, string(body)) if r.Method == "POST" && r.URL.Path == "/token" { diff --git a/internal/server.go b/internal/server.go index 2e20df53..78506427 100644 --- a/internal/server.go +++ b/internal/server.go @@ -32,9 +32,9 @@ func (s *Server) buildRoutes() { for name, rule := range config.Rules { matchRule := rule.formattedRule() if rule.Action == "allow" { - s.router.AddRoute(matchRule, 1, s.AllowHandler(name)) + _ = s.router.AddRoute(matchRule, 1, s.AllowHandler(name)) } else { - s.router.AddRoute(matchRule, 1, s.AuthHandler(rule.Provider, name)) + _ = s.router.AddRoute(matchRule, 1, s.AuthHandler(rule.Provider, name)) } } diff --git a/internal/server_test.go b/internal/server_test.go index d461a4cc..6ccead4e 100644 --- a/internal/server_test.go +++ b/internal/server_test.go @@ -2,7 +2,7 @@ package tfa import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/url" @@ -536,14 +536,14 @@ func doHttpRequest(r *http.Request, c *http.Cookie) (*http.Response, string) { } // Copy into request - for _, c := range w.HeaderMap["Set-Cookie"] { + for _, c := range w.Header()["Set-Cookie"] { r.Header.Add("Cookie", c) } NewServer().RootHandler(w, r) res := w.Result() - body, _ := ioutil.ReadAll(res.Body) + body, _ := io.ReadAll(res.Body) // if res.StatusCode > 300 && res.StatusCode < 400 { // fmt.Printf("%#v", res.Header) @@ -559,7 +559,7 @@ func newDefaultConfig() *Config { }) // Setup the google providers without running all the config validation - config.Providers.Google.Setup() + _ = config.Providers.Google.Setup() return config }