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

topaz v2 model #121

Closed
wants to merge 6 commits into from
Closed
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
11 changes: 6 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@
.vscode/launch.json

# test config & data files
config.y?ml
test.y?ml
data?.json
bundle.tar.gz
*ds.db
!config.yaml
./pkg/testing/assets/config.y?ml
./pkg/testing/assets/test.y?ml
./pkg/testing/assets/data?.json
./pkg/testing/assets/bundle.tar.gz
./pkg/testing/assets/*ds.db

# allow test assets
!pkg/testing/assets/*.db
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
"protomsg",
"protoutil",
"rakyll",
"rapidoc",
"rbuf",
"registery",
"rego",
Expand Down
4 changes: 2 additions & 2 deletions Depfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ go:
version: "v1.18.2"
gotestsum:
importPath: "gotest.tools/gotestsum"
version: "v1.10.0"
version: "v1.10.1"
golangci-lint:
importPath: "github.com/golangci/golangci-lint/cmd/golangci-lint"
version: "v1.52.2"
version: "v1.54.1"
goimports:
importPath: "golang.org/x/tools/cmd/goimports"
version: "latest"
Expand Down
32 changes: 16 additions & 16 deletions builtins/edge/ds/check.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ds

import (
dsc "github.com/aserto-dev/go-directory/aserto/directory/common/v2"
dsr "github.com/aserto-dev/go-directory/aserto/directory/reader/v2"
dsc2 "github.com/aserto-dev/go-directory/aserto/directory/common/v2"
dsr2 "github.com/aserto-dev/go-directory/aserto/directory/reader/v2"
"github.com/aserto-dev/topaz/resolvers"
"github.com/open-policy-agent/opa/ast"
"github.com/open-policy-agent/opa/rego"
Expand Down Expand Up @@ -36,9 +36,9 @@ func RegisterCheckRelation(logger *zerolog.Logger, fnName string, dr resolvers.D
func(bctx rego.BuiltinContext, op1 *ast.Term) (*ast.Term, error) {

type args struct {
Subject *dsc.ObjectIdentifier `json:"subject"`
RelationType *dsc.RelationTypeIdentifier `json:"relation"`
Object *dsc.ObjectIdentifier `json:"object"`
Subject *dsc2.ObjectIdentifier `json:"subject"`
RelationType *dsc2.RelationTypeIdentifier `json:"relation"`
Object *dsc2.ObjectIdentifier `json:"object"`
}

var a args
Expand All @@ -49,14 +49,14 @@ func RegisterCheckRelation(logger *zerolog.Logger, fnName string, dr resolvers.D

if a.Subject == nil && a.RelationType == nil && a.Object == nil {
a = args{
Subject: &dsc.ObjectIdentifier{
Subject: &dsc2.ObjectIdentifier{
Type: proto.String(""),
Key: proto.String(""),
},
RelationType: &dsc.RelationTypeIdentifier{
RelationType: &dsc2.RelationTypeIdentifier{
Name: proto.String(""),
},
Object: &dsc.ObjectIdentifier{
Object: &dsc2.ObjectIdentifier{
Type: proto.String(""),
Key: proto.String(""),
},
Expand All @@ -73,7 +73,7 @@ func RegisterCheckRelation(logger *zerolog.Logger, fnName string, dr resolvers.D
a.RelationType.ObjectType = a.Object.Type
}

resp, err := client.CheckRelation(bctx.Context, &dsr.CheckRelationRequest{
resp, err := client.CheckRelation(bctx.Context, &dsr2.CheckRelationRequest{
Subject: a.Subject,
Relation: a.RelationType,
Object: a.Object,
Expand Down Expand Up @@ -112,9 +112,9 @@ func RegisterCheckPermission(logger *zerolog.Logger, fnName string, dr resolvers
func(bctx rego.BuiltinContext, op1 *ast.Term) (*ast.Term, error) {

type args struct {
Subject *dsc.ObjectIdentifier `json:"subject"`
Permission *dsc.PermissionIdentifier `json:"permission"`
Object *dsc.ObjectIdentifier `json:"object"`
Subject *dsc2.ObjectIdentifier `json:"subject"`
Permission *dsc2.PermissionIdentifier `json:"permission"`
Object *dsc2.ObjectIdentifier `json:"object"`
}

var a args
Expand All @@ -125,14 +125,14 @@ func RegisterCheckPermission(logger *zerolog.Logger, fnName string, dr resolvers

if a.Subject == nil && a.Permission == nil && a.Object == nil {
a = args{
Subject: &dsc.ObjectIdentifier{
Subject: &dsc2.ObjectIdentifier{
Type: proto.String(""),
Key: proto.String(""),
},
Permission: &dsc.PermissionIdentifier{
Permission: &dsc2.PermissionIdentifier{
Name: proto.String(""),
},
Object: &dsc.ObjectIdentifier{
Object: &dsc2.ObjectIdentifier{
Type: proto.String(""),
Key: proto.String(""),
},
Expand All @@ -145,7 +145,7 @@ func RegisterCheckPermission(logger *zerolog.Logger, fnName string, dr resolvers
return nil, errors.Wrapf(err, "get directory client")
}

resp, err := client.CheckPermission(bctx.Context, &dsr.CheckPermissionRequest{
resp, err := client.CheckPermission(bctx.Context, &dsr2.CheckPermissionRequest{
Subject: a.Subject,

Permission: a.Permission,
Expand Down
22 changes: 11 additions & 11 deletions builtins/edge/ds/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package ds
import (
"bytes"

dsc "github.com/aserto-dev/go-directory/aserto/directory/common/v2"
dsr "github.com/aserto-dev/go-directory/aserto/directory/reader/v2"
dsc2 "github.com/aserto-dev/go-directory/aserto/directory/common/v2"
dsr2 "github.com/aserto-dev/go-directory/aserto/directory/reader/v2"
"github.com/aserto-dev/topaz/resolvers"
"github.com/open-policy-agent/opa/ast"
"github.com/open-policy-agent/opa/rego"
Expand Down Expand Up @@ -42,10 +42,10 @@ func RegisterGraph(logger *zerolog.Logger, fnName string, dr resolvers.Directory
func(bctx rego.BuiltinContext, op1 *ast.Term) (*ast.Term, error) {

type args struct {
Anchor *dsc.ObjectIdentifier `json:"anchor"`
Subject *dsc.ObjectIdentifier `json:"subject"`
Relation *dsc.RelationTypeIdentifier `json:"relation"`
Object *dsc.ObjectIdentifier `json:"object"`
Anchor *dsc2.ObjectIdentifier `json:"anchor"`
Subject *dsc2.ObjectIdentifier `json:"subject"`
Relation *dsc2.RelationTypeIdentifier `json:"relation"`
Object *dsc2.ObjectIdentifier `json:"object"`
}

var a args
Expand All @@ -55,18 +55,18 @@ func RegisterGraph(logger *zerolog.Logger, fnName string, dr resolvers.Directory

if a.Anchor == nil && a.Subject == nil && a.Relation == nil && a.Object == nil {
a = args{
Anchor: &dsc.ObjectIdentifier{
Anchor: &dsc2.ObjectIdentifier{
Type: proto.String(""),
Key: proto.String(""),
},
Subject: &dsc.ObjectIdentifier{
Subject: &dsc2.ObjectIdentifier{
Type: proto.String(""),
Key: proto.String(""),
},
Relation: &dsc.RelationTypeIdentifier{
Relation: &dsc2.RelationTypeIdentifier{
Name: proto.String(""),
},
Object: &dsc.ObjectIdentifier{
Object: &dsc2.ObjectIdentifier{
Type: proto.String(""),
Key: proto.String(""),
},
Expand All @@ -79,7 +79,7 @@ func RegisterGraph(logger *zerolog.Logger, fnName string, dr resolvers.Directory
return nil, errors.Wrapf(err, "get directory client")
}

resp, err := client.GetGraph(bctx.Context, &dsr.GetGraphRequest{
resp, err := client.GetGraph(bctx.Context, &dsr2.GetGraphRequest{
Anchor: a.Anchor,
Subject: a.Subject,
Relation: a.Relation,
Expand Down
10 changes: 5 additions & 5 deletions builtins/edge/ds/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package ds
import (
"bytes"

dsc "github.com/aserto-dev/go-directory/aserto/directory/common/v2"
dsr "github.com/aserto-dev/go-directory/aserto/directory/reader/v2"
dsc2 "github.com/aserto-dev/go-directory/aserto/directory/common/v2"
dsr2 "github.com/aserto-dev/go-directory/aserto/directory/reader/v2"
"github.com/aserto-dev/topaz/resolvers"
"google.golang.org/protobuf/proto"

Expand All @@ -29,14 +29,14 @@ func RegisterObject(logger *zerolog.Logger, fnName string, dr resolvers.Director
Memoize: true,
},
func(bctx rego.BuiltinContext, op1 *ast.Term) (*ast.Term, error) {
var a *dsc.ObjectIdentifier
var a *dsc2.ObjectIdentifier

if err := ast.As(op1.Value, &a); err != nil {
return nil, err
}

if a.Type == nil && a.Key == nil {
a = &dsc.ObjectIdentifier{
a = &dsc2.ObjectIdentifier{
Type: proto.String(""),
Key: proto.String(""),
}
Expand All @@ -48,7 +48,7 @@ func RegisterObject(logger *zerolog.Logger, fnName string, dr resolvers.Director
return nil, errors.Wrapf(err, "get directory client")
}

resp, err := client.GetObject(bctx.Context, &dsr.GetObjectRequest{
resp, err := client.GetObject(bctx.Context, &dsr2.GetObjectRequest{
Param: a,
})
if err != nil {
Expand Down
16 changes: 8 additions & 8 deletions builtins/edge/ds/relation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package ds
import (
"bytes"

dsc "github.com/aserto-dev/go-directory/aserto/directory/common/v2"
"github.com/aserto-dev/go-directory/aserto/directory/reader/v2"
dsc2 "github.com/aserto-dev/go-directory/aserto/directory/common/v2"
dsr2 "github.com/aserto-dev/go-directory/aserto/directory/reader/v2"
"github.com/aserto-dev/topaz/resolvers"
"github.com/pkg/errors"
"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -33,7 +33,7 @@ import (
// "with_objects": false
// })
type extendedRelation struct {
*dsc.RelationIdentifier
*dsc2.RelationIdentifier
WithObjects bool `json:"with_objects"`
}

Expand All @@ -52,15 +52,15 @@ func RegisterRelation(logger *zerolog.Logger, fnName string, dr resolvers.Direct
if a == nil || a.RelationIdentifier == nil {

a = &extendedRelation{
RelationIdentifier: &dsc.RelationIdentifier{
Subject: &dsc.ObjectIdentifier{
RelationIdentifier: &dsc2.RelationIdentifier{
Subject: &dsc2.ObjectIdentifier{
Type: proto.String(""),
Key: proto.String(""),
},
Relation: &dsc.RelationTypeIdentifier{
Relation: &dsc2.RelationTypeIdentifier{
Name: proto.String(""),
},
Object: &dsc.ObjectIdentifier{
Object: &dsc2.ObjectIdentifier{
Type: proto.String(""),
Key: proto.String(""),
},
Expand All @@ -75,7 +75,7 @@ func RegisterRelation(logger *zerolog.Logger, fnName string, dr resolvers.Direct
return nil, errors.Wrapf(err, "get directory client")
}

resp, err := client.GetRelation(bctx.Context, &reader.GetRelationRequest{Param: a.RelationIdentifier, WithObjects: &a.WithObjects})
resp, err := client.GetRelation(bctx.Context, &dsr2.GetRelationRequest{Param: a.RelationIdentifier, WithObjects: &a.WithObjects})
if err != nil {
traceError(&bctx, fnName, err)
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions builtins/edge/ds/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package ds
import (
"bytes"

dsc "github.com/aserto-dev/go-directory/aserto/directory/common/v2"
dsr "github.com/aserto-dev/go-directory/aserto/directory/reader/v2"
dsc2 "github.com/aserto-dev/go-directory/aserto/directory/common/v2"
dsr2 "github.com/aserto-dev/go-directory/aserto/directory/reader/v2"
"github.com/aserto-dev/topaz/resolvers"
"github.com/pkg/errors"
"github.com/rs/zerolog"
Expand Down Expand Up @@ -46,8 +46,8 @@ func RegisterUser(logger *zerolog.Logger, fnName string, dr resolvers.DirectoryR
return nil, errors.Wrapf(err, "get directory client")
}

resp, err := client.GetObject(bctx.Context, &dsr.GetObjectRequest{
Param: &dsc.ObjectIdentifier{
resp, err := client.GetObject(bctx.Context, &dsr2.GetObjectRequest{
Param: &dsc2.ObjectIdentifier{
Type: proto.String("user"),
Key: &a.Key,
},
Expand Down
16 changes: 8 additions & 8 deletions directory/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ import (

cerr "github.com/aserto-dev/errors"
"github.com/aserto-dev/go-authorizer/pkg/aerr"
v2 "github.com/aserto-dev/go-directory/aserto/directory/common/v2"
ds2 "github.com/aserto-dev/go-directory/aserto/directory/reader/v2"
dsc2 "github.com/aserto-dev/go-directory/aserto/directory/common/v2"
dsr2 "github.com/aserto-dev/go-directory/aserto/directory/reader/v2"
"github.com/aserto-dev/go-directory/pkg/derr"
)

func GetIdentityV2(client ds2.ReaderClient, ctx context.Context, identity string) (*v2.Object, error) {
func GetIdentityV2(client dsr2.ReaderClient, ctx context.Context, identity string) (*dsc2.Object, error) {
identityString := "identity"
obj := v2.ObjectIdentifier{Type: &identityString, Key: &identity}
obj := dsc2.ObjectIdentifier{Type: &identityString, Key: &identity}

relationString := "identifier"
subjectType := "user"
withObjects := true

relResp, err := client.GetRelation(ctx, &ds2.GetRelationRequest{
Param: &v2.RelationIdentifier{
relResp, err := client.GetRelation(ctx, &dsr2.GetRelationRequest{
Param: &dsc2.RelationIdentifier{
Object: &obj,
Relation: &v2.RelationTypeIdentifier{Name: &relationString, ObjectType: &identityString},
Subject: &v2.ObjectIdentifier{Type: &subjectType},
Relation: &dsc2.RelationTypeIdentifier{Name: &relationString, ObjectType: &identityString},
Subject: &dsc2.ObjectIdentifier{Type: &subjectType},
},
WithObjects: &withObjects,
})
Expand Down
Loading
Loading