Skip to content

Commit

Permalink
drop minimize until its determined its actually helpful
Browse files Browse the repository at this point in the history
  • Loading branch information
miniscruff committed Oct 26, 2024
1 parent 6745dd7 commit e97de78
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 87 deletions.
35 changes: 0 additions & 35 deletions docs/specification/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,38 +39,3 @@ validate_scope(
scopeOrRule string,
) error
```

## Minimize
Minimize will attempt to reduce the number of scopes or rules by following a few checks.
During this process each scope or rule is also validated using the validate_scope
specification exiting early if any invalid scopes are found. This allows you to
call minimize in place of validation if you're end goal is the scopes or rules
and not just checking input is valid.

### Checks

1. Merge identical scopes
1. `["blog/read", "blog/read"]` to `["blog/read"]`
1. Merge into arrays
1. `["blog/read", "blog/create"]` to `["blog/read|create"]`
1. Reduce by wildcards and super wildcards
1. `["blog/read", "blog/*"]` to `["blog/*"]`
1. `["blog/tech/read", "blog/tech/write", "blog/**"]` to `["blog/**"]`
1. Remove allow rules that match a deny rule
1. `["allow/blog/read", "deny/blog/*"]` to `["deny/blog/*"]`

There are some conditions we do not merge.

1. Guessing wildcards:
1. Given you have read and write as the only two valid options: `["a/read", "a/write"]`
1. We will not merge this to `["a/*"]` as we would not know these are the only two options.
1. Additionally, using `*` implies everything no and in the future.
1. Where as `read|write` implies just these two and if we add more, do not add them.

```py title="Minimize"
minimize(
# Given scopes or rules to minimize.
# It is expected that it is all scopes or all rules, otherwise it will fail.
scopeOrRules: []string,
) []string and error
```
52 changes: 0 additions & 52 deletions scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -244,58 +244,6 @@
"error": "scopie-106: scope was empty"
}
],
"minimizeTests": [
{
"id": "duplicate scope",
"scopesOrRules": ["blog/read", "blog/read"],
"result": ["blog/read"]
},
{
"id": "merge array",
"scopesOrRules": ["blog/create", "blog/read"],
"result": ["blog/create|read"]
},
{
"id": "append to array",
"scopesOrRules": ["blog/create", "blog/read|update"],
"result": ["blog/create|read|update"]
},
{
"id": "wildcard reduction",
"scopesOrRules": ["blog/create", "blog/read", "blog/*"],
"result": ["blog/*"]
},
{
"id": "super wildcard reduction",
"scopesOrRules": ["blog/create", "blog/read", "blog/**"],
"result": ["blog/**"]
},
{
"id": "super wildcard reduction at two levels",
"scopesOrRules": ["blog/tech/read", "blog/tech/write", "blog/**"],
"result": ["blog/**"]
},
{
"id": "remove allow if it exactly matches a deny",
"scopesOrRules": ["allow/blog/read", "deny/blog/read"],
"result": ["deny/blog/read"]
},
{
"id": "remove allow if it is under a deny",
"scopesOrRules": ["allow/blog/tech/read", "deny/blog/**"],
"result": ["deny/blog/**"]
},
{
"id": "deep nested scope is still array swapped",
"scopesOrRules": ["a/b/c/d/e", "a/f/c/d/e"],
"result": ["a/b/c/d/e", "a/f/c/d/e"]
},
{
"id": "deep nested scopes with top and bottom level difference is not minimized",
"scopesOrRules": ["a/b/c/d/e", "a/f/c/d/g"],
"result": ["a/b/c/d/e", "a/f/c/d/g"]
}
],
"benchmarks": [
{
"id": "allow,1actor,1rule,1block1length",
Expand Down

0 comments on commit e97de78

Please sign in to comment.