Skip to content

Commit 043a1d5

Browse files
committed
Rename Scope -> ScopeName
1 parent 94ad568 commit 043a1d5

File tree

7 files changed

+19
-19
lines changed

7 files changed

+19
-19
lines changed

coderd/coderdtest/authorize.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ type authCall struct {
527527
SubjectID string
528528
Roles []string
529529
Groups []string
530-
Scope rbac.Scope
530+
Scope rbac.ScopeName
531531
Action rbac.Action
532532
Object rbac.Object
533533
}
@@ -541,11 +541,11 @@ var _ rbac.Authorizer = (*RecordingAuthorizer)(nil)
541541

542542
// ByRoleNameSQL does not record the call. This matches the postgres behavior
543543
// of not calling Authorize()
544-
func (r *RecordingAuthorizer) ByRoleNameSQL(_ context.Context, _ string, _ []string, _ rbac.Scope, _ []string, _ rbac.Action, _ rbac.Object) error {
544+
func (r *RecordingAuthorizer) ByRoleNameSQL(_ context.Context, _ string, _ []string, _ rbac.ScopeName, _ []string, _ rbac.Action, _ rbac.Object) error {
545545
return r.AlwaysReturn
546546
}
547547

548-
func (r *RecordingAuthorizer) ByRoleName(_ context.Context, subjectID string, roleNames []string, scope rbac.Scope, groups []string, action rbac.Action, object rbac.Object) error {
548+
func (r *RecordingAuthorizer) ByRoleName(_ context.Context, subjectID string, roleNames []string, scope rbac.ScopeName, groups []string, action rbac.Action, object rbac.Object) error {
549549
r.Called = &authCall{
550550
SubjectID: subjectID,
551551
Roles: roleNames,
@@ -557,7 +557,7 @@ func (r *RecordingAuthorizer) ByRoleName(_ context.Context, subjectID string, ro
557557
return r.AlwaysReturn
558558
}
559559

560-
func (r *RecordingAuthorizer) PrepareByRoleName(_ context.Context, subjectID string, roles []string, scope rbac.Scope, groups []string, action rbac.Action, _ string) (rbac.PreparedAuthorized, error) {
560+
func (r *RecordingAuthorizer) PrepareByRoleName(_ context.Context, subjectID string, roles []string, scope rbac.ScopeName, groups []string, action rbac.Action, _ string) (rbac.PreparedAuthorized, error) {
561561
return &fakePreparedAuthorizer{
562562
Original: r,
563563
SubjectID: subjectID,
@@ -577,7 +577,7 @@ type fakePreparedAuthorizer struct {
577577
Original *RecordingAuthorizer
578578
SubjectID string
579579
Roles []string
580-
Scope rbac.Scope
580+
Scope rbac.ScopeName
581581
Action rbac.Action
582582
Groups []string
583583
HardCodedSQLString string

coderd/database/modelmethods.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
const AllUsersGroup = "Everyone"
88

9-
func (s APIKeyScope) ToRBAC() rbac.Scope {
9+
func (s APIKeyScope) ToRBAC() rbac.ScopeName {
1010
switch s {
1111
case APIKeyScopeAll:
1212
return rbac.ScopeAll

coderd/rbac/authz.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import (
1818
)
1919

2020
type Authorizer interface {
21-
ByRoleName(ctx context.Context, subjectID string, roleNames []string, scope Scope, groups []string, action Action, object Object) error
22-
PrepareByRoleName(ctx context.Context, subjectID string, roleNames []string, scope Scope, groups []string, action Action, objectType string) (PreparedAuthorized, error)
21+
ByRoleName(ctx context.Context, subjectID string, roleNames []string, scope ScopeName, groups []string, action Action, object Object) error
22+
PrepareByRoleName(ctx context.Context, subjectID string, roleNames []string, scope ScopeName, groups []string, action Action, objectType string) (PreparedAuthorized, error)
2323
}
2424

2525
type PreparedAuthorized interface {
@@ -33,7 +33,7 @@ type PreparedAuthorized interface {
3333
//
3434
// Ideally the 'CompileToSQL' is used instead for large sets. This cost scales
3535
// linearly with the number of objects passed in.
36-
func Filter[O Objecter](ctx context.Context, auth Authorizer, subjID string, subjRoles []string, scope Scope, groups []string, action Action, objects []O) ([]O, error) {
36+
func Filter[O Objecter](ctx context.Context, auth Authorizer, subjID string, subjRoles []string, scope ScopeName, groups []string, action Action, objects []O) ([]O, error) {
3737
if len(objects) == 0 {
3838
// Nothing to filter
3939
return objects, nil
@@ -179,7 +179,7 @@ type authSubject struct {
179179
// ByRoleName will expand all roleNames into roles before calling Authorize().
180180
// This is the function intended to be used outside this package.
181181
// The role is fetched from the builtin map located in memory.
182-
func (a RegoAuthorizer) ByRoleName(ctx context.Context, subjectID string, roleNames []string, scope Scope, groups []string, action Action, object Object) error {
182+
func (a RegoAuthorizer) ByRoleName(ctx context.Context, subjectID string, roleNames []string, scope ScopeName, groups []string, action Action, object Object) error {
183183
start := time.Now()
184184
ctx, span := tracing.StartSpan(ctx,
185185
trace.WithTimestamp(start), // Reuse the time.Now for metric and trace
@@ -239,7 +239,7 @@ func (a RegoAuthorizer) Authorize(ctx context.Context, subjectID string, roles [
239239
return nil
240240
}
241241

242-
func (a RegoAuthorizer) PrepareByRoleName(ctx context.Context, subjectID string, roleNames []string, scope Scope, groups []string, action Action, objectType string) (PreparedAuthorized, error) {
242+
func (a RegoAuthorizer) PrepareByRoleName(ctx context.Context, subjectID string, roleNames []string, scope ScopeName, groups []string, action Action, objectType string) (PreparedAuthorized, error) {
243243
start := time.Now()
244244
ctx, span := tracing.StartSpan(ctx,
245245
trace.WithTimestamp(start),

coderd/rbac/authz_internal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func TestFilter(t *testing.T) {
7777
SubjectID string
7878
Roles []string
7979
Action Action
80-
Scope Scope
80+
Scope ScopeName
8181
ObjectType string
8282
}{
8383
{

coderd/rbac/authz_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type benchmarkCase struct {
1616
Roles []string
1717
Groups []string
1818
UserID uuid.UUID
19-
Scope rbac.Scope
19+
Scope rbac.ScopeName
2020
}
2121

2222
// benchmarkUserCases builds a set of users with different roles and groups.

coderd/rbac/scopes.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"golang.org/x/xerrors"
77
)
88

9-
type Scope string
9+
type ScopeName string
1010

1111
// TODO: @emyrk rename this struct
1212
type ScopeRole struct {
@@ -15,12 +15,12 @@ type ScopeRole struct {
1515
}
1616

1717
const (
18-
ScopeAll Scope = "all"
19-
ScopeApplicationConnect Scope = "application_connect"
18+
ScopeAll ScopeName = "all"
19+
ScopeApplicationConnect ScopeName = "application_connect"
2020
)
2121

2222
// TODO: Support passing in scopeID list for allowlisting resources.
23-
var builtinScopes = map[Scope]ScopeRole{
23+
var builtinScopes = map[ScopeName]ScopeRole{
2424
// ScopeAll is a special scope that allows access to all resources. During
2525
// authorize checks it is usually not used directly and skips scope checks.
2626
ScopeAll: {
@@ -50,7 +50,7 @@ var builtinScopes = map[Scope]ScopeRole{
5050
},
5151
}
5252

53-
func ExpandScope(scope Scope) (ScopeRole, error) {
53+
func ExpandScope(scope ScopeName) (ScopeRole, error) {
5454
role, ok := builtinScopes[scope]
5555
if !ok {
5656
return ScopeRole{}, xerrors.Errorf("no scope named %q", scope)

coderd/rbac/trace.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
// rbacTraceAttributes are the attributes that are added to all spans created by
99
// the rbac package. These attributes should help to debug slow spans.
10-
func rbacTraceAttributes(roles []string, groupCount int, scope Scope, action Action, objectType string, extra ...attribute.KeyValue) trace.SpanStartOption {
10+
func rbacTraceAttributes(roles []string, groupCount int, scope ScopeName, action Action, objectType string, extra ...attribute.KeyValue) trace.SpanStartOption {
1111
return trace.WithAttributes(
1212
append(extra,
1313
attribute.StringSlice("subject_roles", roles),

0 commit comments

Comments
 (0)