Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ PRIVATE_KEY_BASE64=<PRIVATE_KEY_BASE64>
PUBLIC_KEY_BASE64=<PUBLIC_KEY_BASE64>

# Database
MYSQL_HOST=mysql
MYSQL_PORT=3306
MYSQL_CASBIN_DATABASE=casbin
MYSQL_USER=admin
MYSQL_PASSWORD=secret
POSTGRES_HOST=postgres
POSTGRES_DB_DEMO=iam
POSTGRES_DB_TEST=iam_test
POSTGRES_USER=admin
POSTGRES_PASSWORD=secret
POSTGRES_SSL_MODE=disable

# ABAC
POLICY_DIR=/usr/code/examples/abac/cmd/api/policies
JWT_ISSUER=https://abac.com
JWT_AUDIENCE=https://abac.com
6 changes: 5 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run tests

- name: Test core library
run: make ci-test

- name: Test examples
run: make ci-test-examples
140 changes: 79 additions & 61 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,58 +1,7 @@
linters-settings:
dupl:
threshold: 100
funlen:
lines: -1
statements: 50
goconst:
min-len: 2
min-occurrences: 3
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport
- ifElseChain
- octalLiteral
- whyNoLint
gocyclo:
min-complexity: 15
gofmt:
rewrite-rules:
- pattern: 'interface{}'
replacement: 'any'
mnd:
# don't include the "operation" and "assign"
checks:
- argument
- case
- condition
- return
ignored-numbers:
- '0'
- '1'
- '2'
- '3'
ignored-functions:
- strings.SplitN
lll:
line-length: 140
nolintlint:
allow-unused: false
require-explanation: true
require-specific: true
revive:
rules:
- name: unexported-return
disabled: true
- name: unused-parameter
version: "2"

linters:
disable-all: true
default: none
enable:
- bodyclose
- copyloopvar
Expand All @@ -66,26 +15,95 @@ linters:
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- mnd
- goprintffuncname
- gosec
- gosimple
- govet
- intrange
- ineffassign
- intrange
- lll
- mnd
- nakedret
- noctx
- nolintlint
- revive
- staticcheck
- stylecheck
- unconvert
- unparam
- unused
- whitespace
settings:
dupl:
threshold: 100
funlen:
lines: -1
statements: 50
goconst:
min-len: 2
min-occurrences: 3
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport
- ifElseChain
- octalLiteral
- whyNoLint
gocyclo:
min-complexity: 15
lll:
line-length: 140
mnd:
checks:
- argument
- case
- condition
- return
ignored-numbers:
- "0"
- "1"
- "2"
- "3"
ignored-functions:
- strings.SplitN
nolintlint:
require-explanation: true
require-specific: true
allow-unused: false
revive:
rules:
- name: indent-error-flow
- name: unexported-return
disabled: true
- name: unused-parameter
- name: unused-receiver

exclusions:
generated: strict
warn-unused: true
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- path: "_test.go"
text: "unlambda"
linters:
- gocritic

run:
timeout: 5m
formatters:
enable:
- gofmt
- goimports
settings:
gofmt:
rewrite-rules:
- pattern: interface{}
replacement: any
exclusions:
generated: strict
warn-unused: true
28 changes: 7 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
DIST_DIR := _dist
GO_CODE_DIR := cmd internal
GO_CODE_DIR := abac
TEST_OUTPUT_DIR := ${DIST_DIR}/tests
BUILD_DIR := ${DIST_DIR}/build

DEFAULT_VERSION := v0.0.0
EXAMPLES_DIR ?= examples
EXAMPLE_DIRS := $(shell find $(EXAMPLES_DIR) -mindepth 1 -maxdepth 1 -type d -print)

# Docker
.PHONY: up
Expand Down Expand Up @@ -37,15 +37,15 @@ ci-%: create-dev-env
.PHONY: test
test: lint-actions lint-go test-go

.PHONY: build
build: cleanup-build test
@echo "Running api-casbin and api-opa in parallel..."
@$(MAKE) -j 2 api-casbin api-opa
.PHONY: test-examples
test-examples:
@for d in $(EXAMPLE_DIRS); do $(MAKE) -C "$$d" test; done

## App
.PHONY: lint-go
lint-go:
@echo "Running Go linter on code in $(GO_CODE_DIR)..."
@golangci-lint fmt $(addsuffix /..., $(GO_CODE_DIR)) -v
@golangci-lint run $(addsuffix /..., $(GO_CODE_DIR)) -v

.PHONY: test-go
Expand All @@ -64,20 +64,6 @@ test-go:
$(addprefix `pwd`/, $(addsuffix /..., $(GO_CODE_DIR)))
@go tool cover -html=${TEST_OUTPUT_DIR}/cp.out -o ${TEST_OUTPUT_DIR}/cp.html

.PHONY: api-%
api-%:
@CURRENT_VERSION=$(shell git describe --tags --abbrev=0 2>/dev/null || echo $(DEFAULT_VERSION)); \
echo "Building api (version $$CURRENT_VERSION) using $*..."; \
go build -o ${BUILD_DIR}/api-$* \
-a -ldflags "-X 'github.com/CameronXie/access-control-explorer/internal/version.Version=$$CURRENT_VERSION' -extldflags '-s -w -static'" \
-tags $* \
./cmd

.PHONY: cleanup-build
cleanup-build:
@rm -rf ${BUILD_DIR}
@mkdir -p ${BUILD_DIR}

## Action
.PHONY: lint-actions
lint-actions:
Expand Down
Loading