Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PathMap prep #15

Merged
merged 1 commit into from
Nov 4, 2023
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.20
require (
github.com/alecthomas/kong v0.8.1
github.com/aserto-dev/errors v0.0.6
github.com/aserto-dev/go-aserto v0.20.4
github.com/aserto-dev/go-directory v0.30.0
github.com/aserto-dev/go-aserto v0.30.0
github.com/aserto-dev/go-directory v0.30.1
github.com/golang/mock v1.1.1
github.com/hashicorp/go-multierror v1.1.1
github.com/magefile/mage v1.15.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ github.com/alecthomas/repr v0.1.0 h1:ENn2e1+J3k09gyj2shc0dHr/yjaWSHRlrJ4DPMevDqE
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/aserto-dev/errors v0.0.6 h1:iH5fkJwBGFPbcdS4B8mwvNdwODlhDEXXPduZtjLh6vo=
github.com/aserto-dev/errors v0.0.6/go.mod h1:kenI1gamsemaR2wS+M2un0kXIJ9exTrmeRT/fCFwlWc=
github.com/aserto-dev/go-aserto v0.20.4 h1:8vpAr5ojLd0mzL8SXdzXMHRk/8G8kOAho5vrpQ2pWr4=
github.com/aserto-dev/go-aserto v0.20.4/go.mod h1:hZAYXwqs+w4JdrggWzV7SdDK47MqHYi5LtjoWcB78vg=
github.com/aserto-dev/go-directory v0.30.0 h1:mKQhoP7rl9XjxP8X0H6RvjvgjqeRh7WqbWugg/nsCCM=
github.com/aserto-dev/go-directory v0.30.0/go.mod h1:xkZFWZ0u0RcYRBkJLTqantIG/jnVxYhzd2+kIQf8PnU=
github.com/aserto-dev/go-aserto v0.30.0 h1:RZMM8ojXp4O15+qPKsFjQ+6/+KV3pXAwqCJrQjJRD5I=
github.com/aserto-dev/go-aserto v0.30.0/go.mod h1:y+Mrqm9yl3XgBA0lkZ4Pj2cZN1ytL1pjAwpG9rKQCJA=
github.com/aserto-dev/go-directory v0.30.1 h1:2sPtNBntul3tpWxVy5N8jOEqpyf1NGi1Oo9lgrlSees=
github.com/aserto-dev/go-directory v0.30.1/go.mod h1:Gt0RiHgws/m9KJMiCaDXXDYZYoAHFQsd6Vf3KOPWO34=
github.com/aserto-dev/header v0.0.4 h1:Bb58n1m2X/qRV3N2PS0avuFOyRcG8Iri7/qq0Wsunq8=
github.com/aserto-dev/header v0.0.4/go.mod h1:LNgRo3gStS71lO1d9Oue9e9kfVvirvUHvdZClzDmNwo=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down
26 changes: 26 additions & 0 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package model
import (
"bytes"
"encoding/json"
"fmt"
"io"
"time"

Expand All @@ -22,6 +23,22 @@ type ObjectName Identifier
type RelationName Identifier
type PermissionName Identifier

func (on ObjectName) String() string {
return string(on)
}

func (rn RelationName) String() string {
return string(rn)
}

func (pn PermissionName) String() string {
return string(pn)
}

func (pn PermissionName) RN() RelationName {
return RelationName(pn)
}

type Object struct {
Relations map[RelationName][]*Relation `json:"relations,omitempty"`
Permissions map[PermissionName]*Permission `json:"permissions,omitempty"`
Expand All @@ -33,6 +50,15 @@ type Relation struct {
Wildcard ObjectName `json:"wildcard,omitempty"`
}

type ObjectRelation struct {
Object ObjectName `json:"object"`
Relation RelationName `json:"relation,omitempty"`
}

func (or ObjectRelation) String() string {
return fmt.Sprintf("%s:%s", or.Object, or.Relation)
}

type SubjectRelation struct {
Object ObjectName `json:"object,omitempty"`
Relation RelationName `json:"relation,omitempty"`
Expand Down
38 changes: 19 additions & 19 deletions v3/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
const SupportedSchemaVersion int = 3

const (
unionIdentifier string = "|"
intersectionIdentifier string = "&"
exclusionIdentifier string = " - "
relationIdentifier string = "#"
wildcardIdentifier string = ":*"
arrowIdentifier string = "->"
UnionIdentifier string = "|"
IntersectionIdentifier string = "&"
ExclusionIdentifier string = " - "
RelationIdentifier string = "#"
WildcardIdentifier string = ":*"
ArrowIdentifier string = "->"
)

type Manifest struct {
Expand Down Expand Up @@ -114,19 +114,19 @@ func (v *SchemaVersion) UnmarshalYAML(value *yaml.Node) error {
}

func (r *RelationDefinition) UnmarshalYAML(value *yaml.Node) error {
s := strings.Split(value.Value, unionIdentifier)
s := strings.Split(value.Value, UnionIdentifier)
for _, v := range s {
switch {
// subject relation
case strings.Contains(v, relationIdentifier):
sr := strings.Split(v, relationIdentifier)
case strings.Contains(v, RelationIdentifier):
sr := strings.Split(v, RelationIdentifier)
r.Definition = append(r.Definition, &SubjectRelation{
ObjectType: strings.TrimSpace(sr[0]),
Relation: strings.TrimSpace(sr[1]),
})
// wildcard relation
case strings.Contains(v, wildcardIdentifier):
wc := strings.Split(v, wildcardIdentifier)
case strings.Contains(v, WildcardIdentifier):
wc := strings.Split(v, WildcardIdentifier)
r.Definition = append(r.Definition, &WildcardRelation{
ObjectType: strings.TrimSpace(wc[0]),
})
Expand All @@ -144,8 +144,8 @@ func (r *RelationDefinition) UnmarshalYAML(value *yaml.Node) error {
func (p *PermissionOperator) UnmarshalYAML(value *yaml.Node) error {
switch {
// union (OR)
case strings.Contains(value.Value, unionIdentifier):
s := strings.Split(value.Value, unionIdentifier)
case strings.Contains(value.Value, UnionIdentifier):
s := strings.Split(value.Value, UnionIdentifier)
union := []string{}
for _, v := range s {
union = append(union, strings.TrimSpace(v))
Expand All @@ -156,8 +156,8 @@ func (p *PermissionOperator) UnmarshalYAML(value *yaml.Node) error {
},
}
// intersection (AND)
case strings.Contains(value.Value, intersectionIdentifier):
s := strings.Split(value.Value, intersectionIdentifier)
case strings.Contains(value.Value, IntersectionIdentifier):
s := strings.Split(value.Value, IntersectionIdentifier)
intersect := []string{}
for _, v := range s {
intersect = append(intersect, strings.TrimSpace(v))
Expand All @@ -168,17 +168,17 @@ func (p *PermissionOperator) UnmarshalYAML(value *yaml.Node) error {
},
}
// arrow
case strings.Contains(value.Value, arrowIdentifier):
s := strings.Split(value.Value, arrowIdentifier)
case strings.Contains(value.Value, ArrowIdentifier):
s := strings.Split(value.Value, ArrowIdentifier)
*p = PermissionOperator{
Operator: &ArrowOperator{
Relation: strings.TrimSpace(s[0]),
Permission: strings.TrimSpace(s[1]),
},
}
// exclusion (NOT)
case strings.Contains(value.Value, exclusionIdentifier):
s := strings.Split(value.Value, exclusionIdentifier)
case strings.Contains(value.Value, ExclusionIdentifier):
s := strings.Split(value.Value, ExclusionIdentifier)
*p = PermissionOperator{
Operator: &ExclusionOperator{
Base: strings.TrimSpace(s[0]),
Expand Down
Loading