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
41 changes: 24 additions & 17 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@ on:
env:
VAULT_ADDR: https://vault.eng.aserto.com/
PRE_RELEASE: ${{ github.ref == 'refs/heads/main' && 'main' || '' }}
GO_VERSION: "1.23"
GO_RELEASER_VERSION: "v2.3.2"
GO_LANGCI_LINT_VERSION: "v1.61.0"
GO_TESTSUM_VERSION: "1.11.0"
GO_VERSION: "1.24"
GO_RELEASER_VERSION: "v2.8.2"
GO_LANGCI_LINT_VERSION: "v2.0.2"
GO_TESTSUM_VERSION: "1.12.1"

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
package:
- "./"
- "./common"

steps:
-
uses: actions/checkout@v4
Expand All @@ -33,21 +40,21 @@ jobs:
with:
go-version: ${{ env.GO_VERSION }}
-
name: Build
uses: goreleaser/goreleaser-action@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
name: Lint package ${{ matrix.package }}
uses: golangci/golangci-lint-action@v7
with:
distribution: goreleaser
version: ${{ env.GO_RELEASER_VERSION }}
args: build --clean --snapshot --single-target
version: ${{ env.GO_LANGCI_LINT_VERSION }}
install-mode: binary
working-directory: ${{ matrix.package}}
args: --config="${{ github.workspace }}/.golangci.yaml"
-
name: Lint
uses: golangci/golangci-lint-action@v6
name: Test Setup
uses: gertd/action-gotestsum@v3.0.0
with:
version: ${{ env.GO_LANGCI_LINT_VERSION }}
verify: false
args: --timeout=30m
gotestsum_version: ${{ env.GO_TESTSUM_VERSION }}
- name: Test package ${{ matrix.package }}
run: |
gotestsum --format short-verbose -- -count=1 -v ${{ matrix.package }}/...

push:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -114,7 +121,7 @@ jobs:
run: exit 1
-
name: Push image to GitHub Container Registry
uses: goreleaser/goreleaser-action@v5
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: ${{ env.GO_RELEASER_VERSION }}
Expand Down
233 changes: 90 additions & 143 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,150 +1,97 @@
---
# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration

linters-settings:
depguard:
list-type: blacklist
packages:
# logging is allowed only by zerolog
- github.com/sirupsen/logrus
packages-with-error-message:
- github.com/sirupsen/logrus: "logging is allowed only by zerolog"
dupl:
threshold: 100
funlen:
lines: 100
statements: 80
goconst:
min-len: 2
min-occurrences: 2
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
gocyclo:
min-complexity: 18
goimports:
local-prefixes: github.com/golangci/golangci-lint
golint:
min-confidence: 0
gomnd:
checks:
- argument
- case
- condition
- return
govet:
shadow: true
settings:
printf:
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
maligned:
suggest-new: true
misspell:
locale: US
nolintlint:
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
# Configuration
# https://golangci-lint.run/usage/configuration/

version: "2"

linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- asciicheck
- bodyclose
- dogsled
# https://golangci-lint.run/usage/configuration/#linters-configuration
default: all

# explicitly disabled linters
disable:
- containedctx
- contextcheck
- cyclop
- depguard
- errcheck
- copyloopvar
- exhaustruct
- exhaustive
- funlen
- gochecknoinits
- goconst
- gocritic
- gocyclo
- godot
- godox
- err113
- forbidigo
- gochecknoglobals # no configuration options
- nilnil
- nlreturn # redundant with wsl
- paralleltest
- revive
- tagalign
- thelper
- varnamelen
- wrapcheck

settings:
cyclop:
max-complexity: 12

errcheck:
exclude-functions:
- fmt.Fprint
- fmt.Fprintf
- fmt.Fprintln
- os.Close

funlen:
lines: 80
statements: 60
ignore-comments: true

gomoddirectives:
replace-local: true

gosec:
excludes:
- G104 # Errors unhandled
- G304 # Potential file inclusion via variable (see https://github.com/golang/go/issues/67002)

ireturn:
allow:
- error
- empty
- scim.ResourceHandler

lll:
line-length: 150

recvcheck:
exclusions:
- "*.Map"

tagliatelle:
case:
rules:
json: snake
yaml: snake

overrides:
- pkg: pkg/app/handlers
rules:
json: camel

exclusions:
generated: lax

# Paths to exclude
paths:
- internal/pkg/xdg/
- pkg/cc/signals/
- pkg/cli/editor/

rules:
- path: pkg/cli/cmd/
linters:
- dupl

formatters:
enable:
- gofmt
- gofumpt
- goimports
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- noctx
- rowserrcheck
- staticcheck
- stylecheck
- testpackage
- typecheck
- unconvert
- unparam
- unused

# don't enable:
# - depguard
# - dupl
# - gochecknoglobals
# - gocognit
# - gomnd
# - lll
# - nestif
# - nolintlint # conflict with 1.19 gofmt changes
# - prealloc
# - revive
# - wsl
# - whitespace

issues:
# List of regexps of issue texts to exclude, empty list by default.
# But independently from this option we use default exclude patterns,
# it can be disabled by `exclude-use-default: false`. To list all
# excluded by default patterns execute `golangci-lint run --help`
exclude:
- declaration of "(err|ctx)" shadows declaration at
- shadow of imported from 'github.com/stretchr/testify/assert' package 'assert'
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
linters:
- gomnd
# https://github.com/go-critic/go-critic/issues/926
- text: "unnecessaryDefer:"
linters:
- gocritic
- text: "unnamedResult:"
linters:
- gocritic
- path: \.resolvers\.go
text: "typeDefFirst:"
linters:
- gocritic
- path: \.resolvers\.go
text: "paramTypeCombine:"
linters:
- gocritic
- path: \.resolvers\.go
text: "hugeParam:"
linters:
- gocritic
- text: "G404"
linters:
- gosec
30 changes: 24 additions & 6 deletions cmd/aserto-scim/main.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package main

import (
"context"
"fmt"
"log"
"os"

"github.com/aserto-dev/scim/pkg/app"
"github.com/aserto-dev/scim/pkg/version"
"github.com/spf13/cobra"
"golang.org/x/sync/errgroup"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
)

var (
flagConfigPath string
)
var flagConfigPath string

var rootCmd = &cobra.Command{
Use: "aserto-scim [flags]",
Expand All @@ -32,12 +33,29 @@ var cmdRun = &cobra.Command{
Use: "run [args]",
Short: "Start SCIM service",
RunE: func(cmd *cobra.Command, args []string) error {
return app.Run(flagConfigPath, os.Stdout, os.Stderr)
srv, err := app.NewSCIMServer(flagConfigPath, os.Stdout, os.Stderr)
if err != nil {
return err
}

errGroup, ctx := errgroup.WithContext(signals.SetupSignalHandler())
errGroup.Go(srv.Run)

<-ctx.Done()
if err := srv.Shutdown(context.Background()); err != nil {
return err
}

if err := errGroup.Wait(); err != nil {
log.Printf("Error: %v", err)
}

log.Println("SCIM server stopped")
return nil
},
}

// nolint: gochecknoinits
func init() {
func init() { //nolint: gochecknoinits
cmdRun.Flags().StringVarP(&flagConfigPath, "config", "c", "", "config path")
rootCmd.AddCommand(cmdRun)
}
Expand Down
14 changes: 14 additions & 0 deletions common/assets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package common

import (
"embed"
"fmt"
)

//go:embed assets/*
var staticAssets embed.FS

func LoadTemplate(templateName string) ([]byte, error) {
templateFile := fmt.Sprintf("assets/%s.tmpl", templateName)
return staticAssets.ReadFile(templateFile)
}
Loading