Skip to content

Commit

Permalink
Consistently use "user" as the default subject type
Browse files Browse the repository at this point in the history
  • Loading branch information
ronenh committed Sep 12, 2024
1 parent fc30ca0 commit da5174b
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion middleware/ginz/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (o *CheckOptions) subjectType() string {
return o.subj.subjType
}

return "user"
return internal.DefaultSubjType
}

type Check struct {
Expand Down
2 changes: 1 addition & 1 deletion middleware/gorillaz/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (o *CheckOptions) subjectType() string {
return o.subj.subjType
}

return "user"
return internal.DefaultSubjType
}

type Check struct {
Expand Down
12 changes: 6 additions & 6 deletions middleware/grpcz/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ import (
"google.golang.org/grpc"
)

const (
DefaultSubjType = "user"
DefaultObjType = "tenant"
)

type ObjectMapper func(ctx context.Context, req any) (objType, id string)
type Filter func(ctx context.Context, req any) bool

Expand Down Expand Up @@ -63,7 +58,12 @@ func (o *CheckOptions) object(ctx context.Context, req any) (string, string) {
}

func (o *CheckOptions) subject(ctx context.Context, req any) (string, string) {
return o.subj.resolve(ctx, req)
subjType, subjID := o.subj.resolve(ctx, req)
if subjType == "" {
subjType = internal.DefaultSubjType
}

return subjType, subjID
}

func (o *CheckOptions) relation(ctx context.Context, req any) string {
Expand Down
8 changes: 2 additions & 6 deletions middleware/grpcz/rebac.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,9 @@ func (c *RebacMiddleware) subjectType() string {
return c.subjType
}

return DefaultSubjType
return internal.DefaultSubjType
}

func (c *RebacMiddleware) objectType() string {
if c.objType != "" {
return c.objType
}

return DefaultObjType
return c.objType
}
2 changes: 1 addition & 1 deletion middleware/httpz/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (o *CheckOptions) subjectType() string {
return o.subj.subjType
}

return "user"
return internal.DefaultSubjType
}

type Check struct {
Expand Down
5 changes: 5 additions & 0 deletions middleware/internal/default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package internal

const (
DefaultSubjType = "user"
)

0 comments on commit da5174b

Please sign in to comment.