34 Commits

Author SHA1 Message Date
argoyle 46e1bd284c fix: prohibit concurrent read/write 2023-12-26 18:21:59 +01:00
argoyle 16e5ad4f23 build(deps): bump github.com/sparetimecoders/goamqp from 0.2.0 to 0.2.1
Bumps [github.com/sparetimecoders/goamqp](https://github.com/sparetimecoders/goamqp) from 0.2.0 to 0.2.1.
- [Release notes](https://github.com/sparetimecoders/goamqp/releases)
- [Commits](https://github.com/sparetimecoders/goamqp/compare/v0.2.0...v0.2.1)
2023-12-19 05:19:45 +00:00
argoyle f5c18e4515 ci: update version of Go 2023-12-11 17:31:32 +01:00
argoyle e3c79092c2 ci: update to go 1.21.3 and remove patch level 2023-10-27 14:12:51 +02:00
argoyle 7815c85c92 build(deps): bump github.com/sparetimecoders/goamqp from 0.1.5 to 0.2.0
Bumps [github.com/sparetimecoders/goamqp](https://github.com/sparetimecoders/goamqp) from 0.1.5 to 0.2.0.
- [Release notes](https://github.com/sparetimecoders/goamqp/releases)
- [Commits](https://github.com/sparetimecoders/goamqp/compare/v0.1.5...v0.2.0)
2023-10-05 05:19:27 +00:00
argoyle de664d7a05 chore: use 1.21.1 in go.mod for Dependabot 2023-09-27 21:09:56 +02:00
argoyle 67963fcdc1 ci: update to Go 1.21.1 for vulnerabilities 2023-09-08 07:06:55 +02:00
argoyle d3a504ca68 ci: update to Golang 1.21.0 2023-08-30 20:19:14 +02:00
argoyle 233197999f ci: update pre-commit versions 2023-08-30 18:01:12 +02:00
argoyle 1ea2469c77 ci: update to Go 1.20.7 2023-08-07 08:37:15 +02:00
argoyle 775553c2d5 build(deps): bump github.com/sparetimecoders/goamqp from 0.1.4 to 0.1.5
Bumps [github.com/sparetimecoders/goamqp](https://github.com/sparetimecoders/goamqp) from 0.1.4 to 0.1.5.
- [Release notes](https://github.com/sparetimecoders/goamqp/releases)
- [Commits](https://github.com/sparetimecoders/goamqp/compare/v0.1.4...v0.1.5)
2023-07-04 05:19:53 +00:00
argoyle 4203f4474f ci: make releases handle multi-line release notes 2023-06-08 16:16:15 +02:00
argoyle cc7de2e5a1 ci: update Go version 2023-06-08 16:12:38 +02:00
argoyle f14aec80d9 ci: update golangci-lint 2023-06-04 16:45:07 +02:00
argoyle cbd358ba85 build(deps): bump github.com/stretchr/testify from 1.8.3 to 1.8.4
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.3 to 1.8.4.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.8.3...v1.8.4)
2023-05-31 05:19:33 +00:00
argoyle df845a7b4b chore: update pre-commit and fix golangci-lint 2023-05-19 10:48:32 +02:00
argoyle d8f6785032 build(deps): bump github.com/stretchr/testify from 1.8.2 to 1.8.3
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.2 to 1.8.3.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.8.2...v1.8.3)
2023-05-19 05:19:34 +00:00
argoyle ff779d9456 build(deps): bump github.com/sparetimecoders/goamqp from 0.1.3 to 0.1.4
Bumps [github.com/sparetimecoders/goamqp](https://github.com/sparetimecoders/goamqp) from 0.1.3 to 0.1.4.
- [Release notes](https://github.com/sparetimecoders/goamqp/releases)
- [Commits](https://github.com/sparetimecoders/goamqp/compare/v0.1.3...v0.1.4)
2023-05-11 05:19:41 +00:00
argoyle eba7784e59 ci: update Go version and fix gitlabci lint 2023-05-04 08:34:40 +02:00
argoyle d022eb8ebd ci: update to Go 1.20.3 2023-04-06 10:26:35 +02:00
argoyle 9c802b1239 ci: update Go verion for vulnerabilities scan 2023-03-09 22:00:21 +01:00
argoyle 2e3bd451df build(deps): bump github.com/stretchr/testify from 1.8.1 to 1.8.2
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.1 to 1.8.2.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.8.1...v1.8.2)
2023-02-26 10:22:34 +00:00
argoyle 0608960a02 ci: update to golang 1.20.1 2023-02-26 11:03:49 +01:00
argoyle bbbfb99dd9 ci: change dependabot rebase strategy 2023-01-29 10:52:30 +01:00
argoyle eef42d4b32 ci: update to Go 1.19.5 2023-01-29 10:52:23 +01:00
argoyle d1a9414390 ci: add release handling 2023-01-29 10:52:12 +01:00
argoyle dee3bb5d60 ci: add local module to pre-commit config 2023-01-13 13:39:34 +01:00
argoyle dcbdef35cf ci: add pre-commit and remove those checks from test step 2022-12-28 20:06:28 +01:00
argoyle 1794fcd2ad build(deps): bump github.com/sparetimecoders/goamqp from 0.1.2 to 0.1.3
Bumps [github.com/sparetimecoders/goamqp](https://github.com/sparetimecoders/goamqp) from 0.1.2 to 0.1.3.
- [Release notes](https://github.com/sparetimecoders/goamqp/releases)
- [Commits](https://github.com/sparetimecoders/goamqp/compare/v0.1.2...v0.1.3)
2022-11-15 05:19:17 +00:00
argoyle abfeb751b2 chore: replace deprecated ioutil.ReadAll 2022-11-10 10:54:45 +01:00
argoyle 51f0aaf0ca build(deps): bump github.com/sparetimecoders/goamqp from 0.1.1 to 0.1.2
Bumps [github.com/sparetimecoders/goamqp](https://github.com/sparetimecoders/goamqp) from 0.1.1 to 0.1.2.
- [Release notes](https://github.com/sparetimecoders/goamqp/releases)
- [Commits](https://github.com/sparetimecoders/goamqp/compare/v0.1.1...v0.1.2)
2022-10-26 05:19:33 +00:00
argoyle 8604a3568a build(deps): bump github.com/stretchr/testify from 1.8.0 to 1.8.1
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.0 to 1.8.1.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.8.0...v1.8.1)
2022-10-24 05:19:21 +00:00
argoyle fee49889cf fix: run builds with Go 1.19.2 to fix vulnerabilities 2022-10-11 17:59:59 +02:00
argoyle 7e70411553 ci: add vulnerability-check 2022-09-13 14:18:20 +02:00
7 changed files with 137 additions and 22 deletions
+51 -6
View File
@@ -1,14 +1,27 @@
include:
- template: 'Workflows/MergeRequest-Pipelines.gitlab-ci.yml'
image: golang:1.18
variables:
GOFLAGS: -mod=readonly
image: golang:1.21.5
stages:
- deps
- test
- prepare
- release
run-pre-commit:
stage: .pre
image: unbound/pre-commit
variables:
PRE_COMMIT_HOME: ${CI_PROJECT_DIR}/.cache/pre-commit
cache:
- key:
files:
- .pre-commit-config.yaml
paths:
- ${PRE_COMMIT_HOME}
script:
- pre-commit run --all-files
deps:
stage: deps
@@ -20,11 +33,43 @@ test:
dependencies:
- deps
script:
- go fmt $(go list ./...)
- go vet $(go list ./...)
- CGO_ENABLED=1 go test -mod=readonly -race -coverprofile=coverage.txt -covermode=atomic -coverpkg=$(go list ./... | tr '\n' , | sed 's/,$//') ./...
- go tool cover -html=coverage.txt -o coverage.html
- go tool cover -func=coverage.txt
- curl -Os https://uploader.codecov.io/latest/linux/codecov
- chmod +x codecov
- ./codecov -t ${CODECOV_TOKEN} -R $CI_PROJECT_DIR -C $CI_COMMIT_SHA -r $CI_PROJECT_PATH
vulnerabilities:
stage: test
image: golang:1.21.5
script:
- go install golang.org/x/vuln/cmd/govulncheck@latest
- govulncheck ./...
prepare_release:
image: node:18
stage: prepare
before_script:
- npm install -g conventional-changelog-cli
script:
- conventional-changelog -p conventionalcommits > ./release.description
artifacts:
paths:
- release.description
rules:
- if: $CI_COMMIT_TAG
release:
image: registry.gitlab.com/gitlab-org/release-cli:latest
stage: release
needs:
- job: prepare_release
artifacts: true
script:
- echo "Running release_job for $TAG"
release:
tag_name: '$CI_COMMIT_TAG'
description: ./release.description
rules:
- if: $CI_COMMIT_TAG
+1
View File
@@ -10,3 +10,4 @@ updates:
schedule:
interval: "daily"
open-pull-requests-limit: 20
rebase-strategy: none
+2
View File
@@ -0,0 +1,2 @@
run:
allow-parallel-runners: true
+42
View File
@@ -0,0 +1,42 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
args:
- --allow-multiple-documents
- id: check-added-large-files
- repo: https://gitlab.com/devopshq/gitlab-ci-linter
rev: v1.0.5
hooks:
- id: gitlab-ci-linter
args:
- --project
- unboundsoftware/shiny/authz_client
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
rev: v9.5.0
hooks:
- id: commitlint
stages: [ commit-msg ]
additional_dependencies: [ '@commitlint/config-conventional' ]
- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.5.1
hooks:
- id: go-mod-tidy
- id: go-imports
args:
- -local
- gitlab.com/unboundsoftware/shiny/authz_client
- repo: https://github.com/lietu/go-pre-commit
rev: v0.0.1
hooks:
- id: go-test
- id: gofumpt
- repo: https://github.com/golangci/golangci-lint
rev: v1.54.2
hooks:
- id: golangci-lint
+19 -2
View File
@@ -3,9 +3,10 @@ package client
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"reflect"
"sync"
"github.com/sparetimecoders/goamqp"
)
@@ -23,6 +24,7 @@ type CompanyPrivileges struct {
// PrivilegeHandler processes PrivilegeAdded-events and fetches the initial set of privileges from an authz-service
type PrivilegeHandler struct {
*sync.RWMutex
client *http.Client
baseURL string
privileges map[string]map[string]*CompanyPrivileges
@@ -41,6 +43,7 @@ func WithBaseURL(url string) OptsFunc {
// New creates a new PrivilegeHandler. Pass OptsFuncs to configure.
func New(opts ...OptsFunc) *PrivilegeHandler {
handler := &PrivilegeHandler{
RWMutex: &sync.RWMutex{},
client: &http.Client{},
baseURL: "http://authz-service",
privileges: map[string]map[string]*CompanyPrivileges{},
@@ -58,11 +61,13 @@ func (h *PrivilegeHandler) Fetch() error {
return err
}
buff, err := ioutil.ReadAll(resp.Body)
buff, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
h.RLock()
defer h.RUnlock()
err = json.Unmarshal(buff, &h.privileges)
if err != nil {
return err
@@ -77,6 +82,8 @@ func (h *PrivilegeHandler) Process(msg interface{}, _ goamqp.Headers) (interface
if priv, exists := h.privileges[ev.Email]; exists {
priv[ev.CompanyID] = &CompanyPrivileges{}
} else {
h.Lock()
defer h.Unlock()
h.privileges[ev.Email] = map[string]*CompanyPrivileges{
ev.CompanyID: {},
}
@@ -84,13 +91,19 @@ func (h *PrivilegeHandler) Process(msg interface{}, _ goamqp.Headers) (interface
return nil, nil
case *UserRemoved:
if priv, exists := h.privileges[ev.Email]; exists {
h.Lock()
defer h.Unlock()
delete(priv, ev.CompanyID)
}
return nil, nil
case *PrivilegeAdded:
h.Lock()
defer h.Unlock()
h.setPrivileges(ev.Email, ev.CompanyID, ev.Privilege, true)
return nil, nil
case *PrivilegeRemoved:
h.Lock()
defer h.Unlock()
h.setPrivileges(ev.Email, ev.CompanyID, ev.Privilege, false)
return nil, nil
default:
@@ -130,6 +143,8 @@ func (h *PrivilegeHandler) setPrivileges(email, companyId string, privilege Priv
// CompaniesByUser return a slice of company ids matching the provided email and predicate func
func (h *PrivilegeHandler) CompaniesByUser(email string, predicate func(privileges CompanyPrivileges) bool) []string {
h.RLock()
defer h.RUnlock()
var result []string
if p, exists := h.privileges[email]; exists {
for k, v := range p {
@@ -143,6 +158,8 @@ func (h *PrivilegeHandler) CompaniesByUser(email string, predicate func(privileg
// IsAllowed return true if the provided predicate return true for the privileges matching the provided email and companyID, return false otherwise
func (h *PrivilegeHandler) IsAllowed(email, companyID string, predicate func(privileges CompanyPrivileges) bool) bool {
h.RLock()
defer h.RUnlock()
if p, exists := h.privileges[email]; exists {
if v, exists := p[companyID]; exists {
return predicate(*v)
+5 -5
View File
@@ -1,17 +1,17 @@
module gitlab.com/unboundsoftware/shiny/authz_client
go 1.18
go 1.21
require (
github.com/sparetimecoders/goamqp v0.1.1
github.com/stretchr/testify v1.8.0
github.com/sparetimecoders/goamqp v0.2.1
github.com/stretchr/testify v1.8.4
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rabbitmq/amqp091-go v1.3.4 // indirect
github.com/rabbitmq/amqp091-go v1.9.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
+17 -9
View File
@@ -1,24 +1,32 @@
github.com/caarlos0/env v3.5.0+incompatible h1:Yy0UN8o9Wtr/jGHZDpCBLpNrzcFLLM2yixi/rBrKyJs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rabbitmq/amqp091-go v1.3.4 h1:tXuIslN1nhDqs2t6Jrz3BAoqvt4qIZzxvdbdcxWtHYU=
github.com/rabbitmq/amqp091-go v1.3.4/go.mod h1:ogQDLSOACsLPsIq0NpbtiifNZi2YOz0VTJ0kHRghqbM=
github.com/sparetimecoders/goamqp v0.1.1 h1:+TSwlrrnfJIyM+MKpnzk+4mnIvt6M8gdEFNRN4Q0wQA=
github.com/sparetimecoders/goamqp v0.1.1/go.mod h1:JIydmIgCqETEHIiGYmN03gNSs2bghWBHEqnR/Lfmzb0=
github.com/rabbitmq/amqp091-go v1.9.0 h1:qrQtyzB4H8BQgEuJwhmVQqVHB9O4+MNDJCCAcpc3Aoo=
github.com/rabbitmq/amqp091-go v1.9.0/go.mod h1:+jPrT9iY2eLjRaMSRHUhc3z14E/l85kv/f+6luSD3pc=
github.com/sparetimecoders/goamqp v0.2.1 h1:zW1zL3xzjzVx3+ftJtvBwDKAdI9mCM8a3mcGbwAAezc=
github.com/sparetimecoders/goamqp v0.2.1/go.mod h1:/kywWTiRX6EjLKG4eKmoO3l6byh4ycyeYjOx7csf3z4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=