Skip to content

Commit

Permalink
upgrade go version to 1.20 (#279)
Browse files Browse the repository at this point in the history
* use logging datastore for sql in validate
* upgrade to go 1.20
* fix otlp schema url
* adjust go version in gh-actions
* upgrade linter
* upgrade to go 1.21
* replace exp/slices with slices from stdlib
  • Loading branch information
nelsonunbasicalgillo committed Aug 24, 2023
1 parent a25eb8a commit 272638a
Show file tree
Hide file tree
Showing 18 changed files with 629 additions and 1,280 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: '1.21'

- name: Check out code
uses: actions/checkout@v3

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.50
version: v1.54
args: --config=".golangci.yml" --timeout=5m

test:
Expand All @@ -40,7 +40,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: '1.21'

- name: Check out code
uses: actions/checkout@v3
Expand All @@ -60,7 +60,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: '1.21'

- name: Check out code
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
fetch-depth: 0 # this is important, otherwise it won't checkout the full tree (i.e. no previous tags)
- uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: '1.21'
- uses: actions/cache@v3
with:
path: ~/go/pkg/mod
Expand Down
6 changes: 0 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ linters:
disable-all: true
enable:
- bodyclose
- depguard
- dogsled
- dupl
- errcheck
Expand All @@ -77,8 +76,3 @@ linters:
- unparam
- unused
- whitespace

# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
service:
golangci-lint-version: 1.50.x # use the fixed version to not introduce new linters unexpectedly
2 changes: 1 addition & 1 deletion cmd/kelon/kelon.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"os"
"strings"

"github.com/alecthomas/kingpin/v2"
log "github.com/sirupsen/logrus"
"github.com/unbasical/kelon/common"
"github.com/unbasical/kelon/internal/pkg/core"
"github.com/unbasical/kelon/internal/pkg/util"
"github.com/unbasical/kelon/pkg/constants/logging"
"gopkg.in/alecthomas/kingpin.v2"
)

//nolint:gochecknoglobals,gocritic
Expand Down
87 changes: 43 additions & 44 deletions examples/local/policies/mixed_example.rego
Original file line number Diff line number Diff line change
Expand Up @@ -3,89 +3,88 @@ package applications.mixed
# Here we mix multiple datastores (MongoDB and Postgres)
# NOTE: Only one datastore can be used in a allow/verify policy


verify = true {
input.path == ["api", "mixed", "apps", "1"]
verify {
input.path == ["api", "mixed", "apps", "1"]
}

# Verify using Postgres as Datastore
verify = true {
some user
verify {
some user

data.pg.pg_users[user].name == input.user
user.password = input.password
data.pg.pg_users[user].name == input.user
user.password = input.password
}

# Deny all by default
allow = false
allow := false

# Path: GET /api/pg/apps/:app_id
# Datastore: Postgres
# The first app is public
allow = true {
input.method == "GET"
input.path == ["api", "mixed", "apps", "1"]
allow {
input.method == "GET"
input.path == ["api", "mixed", "apps", "1"]
}

# Path: GET /api/pg/apps/:app_id
# Datastore: Postgres
# Users with right 'OWNER' on app can access it always
allow = true {
some appId, u, r
input.method == "GET"
input.path = ["api", "mixed", "apps", appId]

# Join
data.pg.pg_users[u].id == data.pg.pg_app_rights[r].user_id

# Where
u.name == input.user
r.right == "OWNER"
r.app_id == appId
allow {
some app_id, u, r
input.method == "GET"
input.path = ["api", "mixed", "apps", app_id]

# Join
data.pg.pg_users[u].id == data.pg.pg_app_rights[r].user_id

# Where
u.name == input.user
r.right == "OWNER"
r.app_id == app_id
}

# Path: GET /api/pg/apps/:app_id
# Datastore: Postgres
# All apps with 5 stars are public
allow = true {
some app, appId
input.method == "GET"
input.path = ["api", "mixed", "apps", appId]
allow {
some app, app_id
input.method == "GET"
input.path = ["api", "mixed", "apps", app_id]

data.pg.pg_apps[app].id == appId
app.stars == 5
data.pg.pg_apps[app].id == app_id
app.stars == 5
}

# Path: GET <any>
# Datastore: Mongo
# All users that are a friends of Kevin are allowed see everything
allow = true {
input.method == "GET"
allow {
input.method == "GET"

# Query
data.mongo.users[user].name == input.user
old_or_kevin(user.age, user.friend)
# Query
data.mongo.users[user].name == input.user
old_or_kevin(user.age, user.friend)
}

# Path: GET /api/pg/apps/:app_id
# Datastore: MongoDB
# Test for count function
allow = true {
some app
input.method == "GET"
input.path = ["api", "mixed", "apps", "4"]
allow {
some app
input.method == "GET"
input.path = ["api", "mixed", "apps", "4"]

# Get all apps with 5 starts
data.mongo.apps[app].stars > 4
# Get all apps with 5 starts
data.mongo.apps[app].stars > 4

#If there is any one return true
count(app) > 0
# If there is any one return true
count(app) > 0
}

old_or_kevin(age, friend) {
age == 42
age == 42
}

old_or_kevin(age, friend) {
friend == "Kevin"
friend == "Kevin"
}
90 changes: 45 additions & 45 deletions examples/local/policies/mongo_example.rego
Original file line number Diff line number Diff line change
@@ -1,85 +1,85 @@
package applications.mongo

verify = true {
input.path == ["api", "mongo", "apps", "1"]
verify {
input.path == ["api", "mongo", "apps", "1"]
}

verify = true {
some user
verify {
some user

data.mongo.users[user].name == input.user
user.password = input.password
data.mongo.users[user].name == input.user
user.password = input.password
}

# Deny all by default
allow = false
allow := false

# Path: GET /api/mongo/apps/:app_id
# Users with right 'OWNER' on app can access it always
allow = true {
some appId, app, right, user
input.method == "GET"
input.path = ["api", "mongo", "apps", appId]
allow {
some app_id, app, right, user
input.method == "GET"
input.path = ["api", "mongo", "apps", app_id]

# This query fires against collection -> apps
data.mongo.apps[app].id == appId
# This query fires against collection -> apps
data.mongo.apps[app].id == app_id

# Nest elements
data.mongo.rights[right].right == "OWNER"
data.mongo.users[user].name == input.user
# Nest elements
data.mongo.rights[right].right == "OWNER"
data.mongo.users[user].name == input.user

# Query root
app.stars > 2
# Query root
app.stars > 2
}

# Path: GET /api/mongo/apps/:app_id
# All apps with 5 stars are public
allow = true {
some app, appId
input.method == "GET"
input.path = ["api", "mongo", "apps", appId]

# This query fires against collection -> apps
data.mongo.apps[app].stars == 5
app.id == appId
allow {
some app, app_id
input.method == "GET"
input.path = ["api", "mongo", "apps", app_id]

# This query fires against collection -> apps
data.mongo.apps[app].stars == 5
app.id == app_id
}

# Path: GET /api/mongo/apps/:app_id
# The first app is public
allow = true {
input.method == "GET"
input.path == ["api", "mongo", "apps", "1"]
allow {
input.method == "GET"
input.path == ["api", "mongo", "apps", "1"]
}

# Path: GET <any>
# All users that are a friends of Kevin are allowed see everything
allow = true {
some user
input.method == "GET"
allow {
some user
input.method == "GET"

# This query fires against collection -> users
data.mongo.users[user].name == input.user
old_or_kevin(user.age, user.friend)
# This query fires against collection -> users
data.mongo.users[user].name == input.user
old_or_kevin(user.age, user.friend)
}

# Path: GET /api/mongo/apps/:app_id
# Test for count function
allow = true {
some app
input.method == "GET"
input.path = ["api", "mongo", "apps", "4"]
allow {
some app
input.method == "GET"
input.path = ["api", "mongo", "apps", "4"]

# Get all apps with 5 starts
data.mongo.apps[app].stars > 4
# Get all apps with 5 starts
data.mongo.apps[app].stars > 4

#If there is any one return true
count(app) > 0
# If there is any one return true
count(app) > 0
}

old_or_kevin(age, friend) {
age == 42
age == 42
}

old_or_kevin(age, friend) {
friend == "Kevin"
friend == "Kevin"
}
Loading

0 comments on commit 272638a

Please sign in to comment.