From 75a3d0ea51d4d632b690cd8c9558db0001dd56b0 Mon Sep 17 00:00:00 2001 From: Savely Krasovsky Date: Tue, 29 Mar 2022 21:33:28 +0300 Subject: [PATCH] GitHub workflow support --- .github/workflows/go.yml | 53 ++++++++++++++++++++++++++++++++ .gitignore | 6 ++-- .gitlab-ci.yml | 24 --------------- .goreleaser.yml | 58 ++++++++++++++++++++++++++++++++++++ CHANGELOG | 6 ++++ Makefile | 23 -------------- README.md | 2 ++ internal/daemon/daemon.go | 11 ++----- internal/proxy/auth_test.go | 1 + internal/proxy/proxy.go | 1 + internal/proxy/proxy_test.go | 1 + internal/proxy/util_test.go | 6 ---- version | 1 - 13 files changed, 128 insertions(+), 65 deletions(-) create mode 100644 .github/workflows/go.yml delete mode 100644 .gitlab-ci.yml create mode 100644 .goreleaser.yml delete mode 100644 Makefile delete mode 100644 version diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..17d12de --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,53 @@ +name: Go + +on: + pull_request: + push: + +permissions: + contents: write + +jobs: + escobar: + runs-on: ubuntu-latest + steps: + - name: Setup Golang + uses: actions/setup-go@v2 + with: + go-version: 1.18.x + + - name: Setup modules cache + uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - uses: actions/checkout@v2 + + - name: Download dependencies + run: go mod download + + - name: Lint + uses: golangci/golangci-lint-action@v2 + with: + version: v1.45.2 + + - name: Build + run: go build ./cmd/escobar + + - name: Test + run: go test -gcflags=all=-l -v ./... + + - name: Test race + run: go test -gcflags=all=-l -race -v ./... + + - name: Release + if: startsWith(github.ref, 'refs/tags/v') + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 30b6caf..a5e5a64 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,11 @@ # Goland (IDEA) -.idea +/.idea # Personal testing config configs/keytabs/personal.keytab configs/personal.env # Binaries -bin/ \ No newline at end of file +/dist/ +escobar +escobar.exe \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index cb8b01b..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,24 +0,0 @@ -image: golang:1.13 - -before_script: - - cd $CI_PROJECT_DIR - -stages: - - test - - build - -lint: - image: golangci/golangci-lint:v1.23.2 - stage: test - script: make lint - -unit tests: - stage: test - script: make test - -try to build: - stage: build - script: make cross-build - artifacts: - paths: - - bin \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..0b20141 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,58 @@ +--- +project_name: escobar + +release: + github: + owner: L11R + name: escobar + +builds: + - binary: escobar + goos: + - darwin + - windows + - linux + - freebsd + goarch: + - amd64 + - arm64 + - arm + - 386 + - ppc64le + - s390x + - mips64 + - mips64le + - riscv64 + goarm: + - 6 + - 7 + gomips: + - hardfloat + env: + - CGO_ENABLED=0 + ignore: + - goos: darwin + goarch: 386 + - goos: freebsd + goarch: arm64 + main: ./cmd/escobar/main.go + flags: + - -trimpath + ldflags: -s -w -X $(PROJECT)/internal/version.Version={{.Version}} -X $(PROJECT)/internal/version.Commit={{.ShortCommit}} + +archives: + - format: tar.gz + wrap_in_directory: true + format_overrides: + - goos: windows + format: zip + name_template: '{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}' + files: + - LICENSE + - README.md + +snapshot: + name_template: SNAPSHOT-{{ .Commit }} + +checksum: + name_template: '{{ .ProjectName }}-{{ .Version }}-checksums.txt' \ No newline at end of file diff --git a/CHANGELOG b/CHANGELOG index 25aaef8..bdbdc06 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +Changes with Escobar 3.0.0, 29 March 2022 + *) Feature: service support (Windows tested, Unix and macOS should work too) + *) Feature: auto mode support for Linux (macOS not supported yet) + *) Change: code simplification and dependencies update + *) Bugfix: many small fixes + Changes with Escobar 2.2.0, 28 January 2020 *) Change: Windows now require only few arguments *) Bugfix: Initialization logic changed, start is improved diff --git a/Makefile b/Makefile deleted file mode 100644 index 4662cb8..0000000 --- a/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -PROJECT_NAME := escobar -PROJECT := github.com/L11R/escobar -VERSION := $(shell cat version) -COMMIT := $(shell git rev-parse --short HEAD) -PKG_LIST := $(shell go list ./... | grep -v /vendor/) - -GOLANGCI_LINT_VERSION = v1.21.0 - -LDFLAGS = "-s -w -X $(PROJECT)/internal/version.Version=$(VERSION) -X $(PROJECT)/internal/version.Commit=$(COMMIT)" - -build: - go build -ldflags $(LDFLAGS) -o ./bin/$(PROJECT_NAME) ./cmd/$(PROJECT_NAME) - -cross-build: - GOOS=linux GOARCH=amd64 go build -ldflags $(LDFLAGS) -o ./bin/$(PROJECT_NAME).linux ./cmd/$(PROJECT_NAME) - GOOS=darwin GOARCH=amd64 go build -ldflags $(LDFLAGS) -o ./bin/$(PROJECT_NAME).darwin ./cmd/$(PROJECT_NAME) - GOOS=windows GOARCH=amd64 go build -ldflags $(LDFLAGS) -o ./bin/$(PROJECT_NAME).exe ./cmd/$(PROJECT_NAME) - -test: - @go test -v -cover -gcflags=-l --race $(PKG_LIST) - -lint: - @golangci-lint run -v diff --git a/README.md b/README.md index e2bc80d..97f7996 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ # Escobar +[![Go](https://github.com/L11R/escobar/actions/workflows/go.yml/badge.svg)](https://github.com/L11R/escobar/actions/workflows/go.yml) + This is an alternative to `cntlm` utility, but written in Go. It's aim to be simpler and easier to customize for own needs. Mainly tested against McAfee Web Gateway. Tested in Linux, macOS and Windows, but should work on other OS like Android. diff --git a/internal/daemon/daemon.go b/internal/daemon/daemon.go index 295ffd0..68d4574 100644 --- a/internal/daemon/daemon.go +++ b/internal/daemon/daemon.go @@ -33,15 +33,7 @@ type Daemon struct { } func New() *Daemon { - d := &Daemon{ - SystemLogger: nil, - logger: nil, - config: nil, - proxy: nil, - static: nil, - } - - return d + return &Daemon{} } func (d *Daemon) Start(svc service.Service) error { @@ -167,6 +159,7 @@ func (d *Daemon) run(svc service.Service) { go func() { if err := <-errChan; err != nil { logger.Error("Error while running proxy!", zap.Error(err)) + // nolint:errcheck d.Stop(nil) os.Exit(1) } diff --git a/internal/proxy/auth_test.go b/internal/proxy/auth_test.go index 0ce49e8..dc860ad 100644 --- a/internal/proxy/auth_test.go +++ b/internal/proxy/auth_test.go @@ -50,6 +50,7 @@ func TestProxy_setProxyAuthorizationHeader(t *testing.T) { if err != nil { t.Fatal(err) } + // nolint:errcheck defer patch.Unpatch() if err := p.setProxyAuthorizationHeader(req); err != nil { assert.NoError(t, err) diff --git a/internal/proxy/proxy.go b/internal/proxy/proxy.go index 7fba0cc..01aca6c 100644 --- a/internal/proxy/proxy.go +++ b/internal/proxy/proxy.go @@ -128,6 +128,7 @@ func (p *Proxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) { zap.String("user_agent", req.UserAgent()), zap.String("uri", req.RequestURI), ) + // nolint:staticcheck req = req.WithContext(context.WithValue(context.Background(), LogEntryCtx, logger)) defer func() { diff --git a/internal/proxy/proxy_test.go b/internal/proxy/proxy_test.go index fdbc1e8..7c63cf3 100644 --- a/internal/proxy/proxy_test.go +++ b/internal/proxy/proxy_test.go @@ -99,6 +99,7 @@ func TestNewProxy(t *testing.T) { patch := monkey.Patch(httputil.NewForwardingProxy, func() *httputil.ReverseProxy { return rp }) + // nolint:errcheck defer patch.Unpatch() expected := &Proxy{ diff --git a/internal/proxy/util_test.go b/internal/proxy/util_test.go index 8aecea2..55009f6 100644 --- a/internal/proxy/util_test.go +++ b/internal/proxy/util_test.go @@ -6,7 +6,6 @@ package proxy import ( "bytes" - "io" "net" "net/http" "testing" @@ -16,8 +15,6 @@ import ( "go.uber.org/zap" ) -// Copyright 2015 Google Inc. All rights reserved. - func Test_newResponse(t *testing.T) { req, err := http.NewRequest("GET", "http://www.example.com", nil) if err != nil { @@ -47,9 +44,6 @@ func Test_newResponse(t *testing.T) { if res.Header == nil { t.Error("res.Header: got nil, want header") } - if _, ok := res.Body.(io.ReadCloser); !ok { - t.Error("res.Body.(io.ReadCloser): got !ok, want ok") - } if got, want := res.Request, req; got != want { t.Errorf("res.Request: got %v, want %v", got, want) } diff --git a/version b/version deleted file mode 100644 index bd52db8..0000000 --- a/version +++ /dev/null @@ -1 +0,0 @@ -0.0.0 \ No newline at end of file