Skip to content

Commit

Permalink
added wasm implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Duve committed Nov 19, 2024
1 parent 2a1cb9a commit 8438852
Show file tree
Hide file tree
Showing 53 changed files with 2,078 additions and 11,322 deletions.
9 changes: 2 additions & 7 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "gomod" # See documentation for possible values
directory: "/" # Location of package manifests
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "weekly"
5 changes: 1 addition & 4 deletions .github/workflows/go-cross.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
# /~https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

# /~https://github.com/marketplace/actions/checkout
- name: Checkout code
uses: actions/checkout@v2

# /~https://github.com/marketplace/actions/cache
- name: Cache Go modules
uses: actions/cache@v3
with:
Expand All @@ -44,4 +41,4 @@ jobs:
${{ runner.os }}-${{ matrix.go-version }}-go-
- name: Test
run: go test -v -cover ./...
run: go test -v -cover ./...
39 changes: 23 additions & 16 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,52 @@ on:
pull_request:

jobs:

main:
name: Main Process
name: Main process
runs-on: ubuntu-latest
env:
GO_VERSION: 1.21
GOLANGCI_LINT_VERSION: v1.50.0
YAEGI_VERSION: v0.14.2
CGO_ENABLED: 0
GOLANGCI_LINT_VERSION: v1.55.2
defaults:
run:
working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}

steps:

- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

- name: Check out code
uses: actions/checkout@v2
with:
path: go/src/github.com/${{ github.repository }}
fetch-depth: 0

- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

- name: Cache Go modules
uses: actions/cache@v3
with:
path: go/pkg/mod
key: ${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ env.GO_VERSION }}-
- name: Install dependencies
- name: Check and get dependencies
run: |
go mod tidy
go mod download
go mod tidy
git diff --exit-code go.mod
git diff --exit-code go.sum
- name: Run tests
run: |
go test -v -cover ./...
go test -v -cover ./...
- name: Install tinygo
uses: acifani/setup-tinygo@v2

- name: Install golangci-lint ${{ env.GOLANGCI_LINT_VERSION }}
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION}

- name: Build
run: make
35 changes: 35 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Release

on:
push:
tags:
- "v*.*.*"

jobs:
main:
name: Release process
runs-on: ubuntu-latest
env:
GO_VERSION: 1.21

steps:
- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

- name: Install tinygo
uses: acifani/setup-tinygo@v2

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: release --clean --timeout=10m
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN_REPO }}
131 changes: 117 additions & 14 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,99 @@
run:
timeout: 5m
timeout: 10m

linters-settings:
govet:
enable-all: true
disable:
- fieldalignment
gocyclo:
min-complexity: 12
goconst:
min-len: 5
min-occurrences: 4
misspell:
locale: US
min-len: 3
min-occurrences: 3
funlen:
lines: -1
statements: 50
misspell:
locale: US
depguard:
rules:
main:
deny:
- pkg: "github.com/instana/testify"
desc: not allowed
- pkg: "github.com/pkg/errors"
desc: Should be replaced by standard lib errors package
tagalign:
align: false
order:
- xml
- json
- yaml
- yml
- toml
- mapstructure
- url
godox:
keywords:
- FIXME
gofumpt:
extra-rules: true
gocritic:
enabled-tags:
- diagnostic
- style
- performance
disabled-checks:
- paramTypeCombine # already handle by gofumpt.extra-rules
- whyNoLint # already handle by nonolint
- unnamedResult
- hugeParam
- sloppyReassign
- rangeValCopy
- octalLiteral
- ptrToRefParam
- appendAssign
- ruleguard
- httpNoBody
- exposedSyncMutex
revive:
rules:
- name: struct-tag
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: exported
disabled: true
- name: if-return
- name: increment-decrement
- name: var-naming
- name: var-declaration
- name: package-comments
disabled: true
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
- name: unused-parameter
disabled: true
- name: unreachable-code
- name: redefines-builtin-id
testifylint:
enable:
- bool-compare
- compares
- empty
- error-is-as
- error-nil
- expected-actual
- float-compare
- len
- suite-dont-use-pkg
- suite-extra-assert-call
- suite-thelper

linters:
enable-all: true
Expand All @@ -35,17 +108,47 @@ linters:
- scopelint # deprecated
- structcheck # deprecated
- varcheck # deprecated
- cyclop # duplicate of gocyclo
- sqlclosecheck # not relevant (SQL)
- rowserrcheck # not relevant (SQL)
- execinquery # not relevant (SQL)
- lll
- dupl # not relevant
- prealloc # too many false-positive
- bodyclose # too many false-positive
- gomnd
- testpackage # not relevant
- tparallel # not relevant
- paralleltest # not relevant
- nestif # too many false-positive
- wrapcheck
- goerr113 # not relevant
- nlreturn # not relevant
- wsl # not relevant
- exhaustive # not relevant
- exhaustruct # not relevant
- makezero # not relevant
- forbidigo
- varnamelen # not relevant
- nilnil # not relevant
- ireturn # not relevant
- contextcheck # too many false-positive
- noctx
- forcetypeassert
- errchkjson
- nonamedreturns
- gosmopolitan # not relevant

issues:
exclude-use-default: false
max-same-issues: 0
exclude: []
exclude:
- 'Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*printf?|os\.(Un)?Setenv). is not checked'
- 'exported (type|method|function) (.+) should have comment or be unexported'
- 'ST1000: at least one file in a package should have a package comment'
exclude-rules:
- path: (.+)_test.go
linters:
- goconst
- funlen
- godot
- goconst
- maintidx
36 changes: 36 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
project_name: grpc_forward_auth

builds:
- binary: plugin.wasm
gobinary: tinygo
no_unique_dist_dir: true
main: .
flags:
- -scheduler=none
- --no-debug
- -target=wasi
ldflags:
- ''
goos:
- linux
goarch:
- amd64

changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^doc:'
- '^chore:'
- '^chore(deps):'
- '^test:'
- '^tests:'

archives:
- id: plugindemowasm
name_template: '{{ .ProjectName }}_v{{ .Version }}'
format: zip
files:
- LICENSE
- .traefik.yml
1 change: 1 addition & 0 deletions .traefik.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
displayName: GRPC Forward Auth
type: middleware
runtime: wasm
iconPath: .assets/logo.png

import: github.com/morzan1001/forward_auth_grpc_plugin
Expand Down
10 changes: 4 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ PROTO_FILES=$(PROTO_DIR)/*.proto
# Install depricated protoc-gen-go
install-proto-deps-deprecated:
go install github.com/gogo/protobuf/protoc-gen-gofast@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest

# Install protoc dependencies
install-proto-deps:
Expand All @@ -21,8 +20,7 @@ install-proto-deps:

# Generate proto files using the deprecated protoc-gen-go
proto-deprecated: install-proto-deps-deprecated
$(PROTOC) --gofast_out=. --gofast_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
$(PROTOC) --gofast_out=plugins=grpc:. --gofast_opt=paths=source_relative \
$(PROTO_FILES)

# Generate proto files
Expand All @@ -37,12 +35,12 @@ lint:
test:
go test -v -cover -timeout 30s ./...

yaegi_test:
yaegi test -v .

vendor:
go mod vendor

build:
@tinygo build -o plugin.wasm -scheduler=none --no-debug -target=wasi ./forward_auth_grpc.go

clean:
rm -rf ./vendor
rm -f $(PROTO_DIR)/*.pb.go
Expand Down
Loading

0 comments on commit 8438852

Please sign in to comment.