Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4e6b43f

Browse files
committed
Merge branch 'cj/dbauthz' into authzquerier_layer
2 parentsd4e1124 +ad6ad36 commit4e6b43f

File tree

47 files changed

+94
-98
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+94
-98
lines changed

‎coderd/autobuild/executor/lifecycle_executor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
"golang.org/x/xerrors"
1111

1212
"cdr.dev/slog"
13-
"github.com/coder/coder/coderd/authzquery"
1413
"github.com/coder/coder/coderd/autobuild/schedule"
1514
"github.com/coder/coder/coderd/database"
15+
"github.com/coder/coder/coderd/database/dbauthz"
1616
"github.com/coder/coder/coderd/rbac"
1717
)
1818

@@ -36,7 +36,7 @@ type Stats struct {
3636
funcNew(ctx context.Context,db database.Store,log slog.Logger,tick<-chan time.Time)*Executor {
3737
le:=&Executor{
3838
// Use an authorized context with an autostart system actor.
39-
ctx:authzquery.WithAuthorizeSystemContext(ctx,rbac.RolesAutostartSystem()),
39+
ctx:dbauthz.WithAuthorizeSystemContext(ctx,rbac.RolesAutostartSystem()),
4040
db:db,
4141
tick:tick,
4242
log:log,

‎coderd/coderd.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ import (
3636

3737
"cdr.dev/slog"
3838
"github.com/coder/coder/buildinfo"
39-
"github.com/coder/coder/coderd/authzquery"
4039

4140
// Used to serve the Swagger endpoint
4241
_"github.com/coder/coder/coderd/apidoc"
4342
"github.com/coder/coder/coderd/audit"
4443
"github.com/coder/coder/coderd/awsidentity"
4544
"github.com/coder/coder/coderd/database"
45+
"github.com/coder/coder/coderd/database/dbauthz"
4646
"github.com/coder/coder/coderd/database/dbtype"
4747
"github.com/coder/coder/coderd/gitauth"
4848
"github.com/coder/coder/coderd/gitsshkey"
@@ -159,8 +159,8 @@ func New(options *Options) *API {
159159
experiments:=initExperiments(options.Logger,options.DeploymentConfig.Experiments.Value,options.DeploymentConfig.Experimental.Value)
160160
// TODO: remove this once we promote authz_querier out of experiments.
161161
ifexperiments.Enabled(codersdk.ExperimentAuthzQuerier) {
162-
if_,ok:= (options.Database).(*authzquery.AuthzQuerier);!ok {
163-
options.Database=authzquery.New(
162+
if_,ok:= (options.Database).(*dbauthz.AuthzQuerier);!ok {
163+
options.Database=dbauthz.New(
164164
options.Database,
165165
options.Authorizer,
166166
options.Logger.Named("authz_query"),
@@ -209,8 +209,8 @@ func New(options *Options) *API {
209209
}
210210
// TODO: remove this once we promote authz_querier out of experiments.
211211
ifexperiments.Enabled(codersdk.ExperimentAuthzQuerier) {
212-
if_,ok:= (options.Database).(*authzquery.AuthzQuerier);!ok {
213-
options.Database=authzquery.New(options.Database,options.Authorizer,options.Logger.Named("authz_querier"))
212+
if_,ok:= (options.Database).(*dbauthz.AuthzQuerier);!ok {
213+
options.Database=dbauthz.New(options.Database,options.Authorizer,options.Logger.Named("authz_querier"))
214214
}
215215
}
216216
ifoptions.SetUserGroups==nil {

‎coderd/coderdtest/coderdtest.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ import (
5656
"github.com/coder/coder/cli/deployment"
5757
"github.com/coder/coder/coderd"
5858
"github.com/coder/coder/coderd/audit"
59-
"github.com/coder/coder/coderd/authzquery"
6059
"github.com/coder/coder/coderd/autobuild/executor"
6160
"github.com/coder/coder/coderd/awsidentity"
6261
"github.com/coder/coder/coderd/database"
62+
"github.com/coder/coder/coderd/database/dbauthz"
6363
"github.com/coder/coder/coderd/database/dbtestutil"
6464
"github.com/coder/coder/coderd/gitauth"
6565
"github.com/coder/coder/coderd/gitsshkey"
@@ -187,7 +187,7 @@ func NewOptions(t *testing.T, options *Options) (func(http.Handler), context.Can
187187
Wrapped:rbac.NewAuthorizer(prometheus.NewRegistry()),
188188
}
189189
}
190-
options.Database=authzquery.New(options.Database,options.Authorizer,slogtest.Make(t,nil).Leveled(slog.LevelDebug))
190+
options.Database=dbauthz.New(options.Database,options.Authorizer,slogtest.Make(t,nil).Leveled(slog.LevelDebug))
191191
}
192192
ifoptions.DeploymentConfig==nil {
193193
options.DeploymentConfig=DeploymentConfig(t)

‎coderd/authzquery/apikey.gorenamed to‎coderd/database/dbauthz/apikey.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageauthzquery
1+
packagedbauthz
22

33
import (
44
"context"

‎coderd/authzquery/apikey_test.gorenamed to‎coderd/database/dbauthz/apikey_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageauthzquery_test
1+
packagedbauthz_test
22

33
import (
44
"time"

‎coderd/authzquery/audit.gorenamed to‎coderd/database/dbauthz/audit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageauthzquery
1+
packagedbauthz
22

33
import (
44
"context"

‎coderd/authzquery/audit_test.gorenamed to‎coderd/database/dbauthz/audit_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageauthzquery_test
1+
packagedbauthz_test
22

33
import (
44
"github.com/coder/coder/coderd/database"

‎coderd/authzquery/authz.gorenamed to‎coderd/database/dbauthz/authz.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageauthzquery
1+
packagedbauthz
22

33
import (
44
"context"

‎coderd/authzquery/authz_test.gorenamed to‎coderd/database/dbauthz/authz_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageauthzquery_test
1+
packagedbauthz_test
22

33
import (
44
"context"
@@ -12,9 +12,9 @@ import (
1212

1313
"cdr.dev/slog"
1414
"cdr.dev/slog/sloggers/slogtest"
15-
"github.com/coder/coder/coderd/authzquery"
1615
"github.com/coder/coder/coderd/coderdtest"
1716
"github.com/coder/coder/coderd/database"
17+
"github.com/coder/coder/coderd/database/dbauthz"
1818
"github.com/coder/coder/coderd/database/dbfake"
1919
"github.com/coder/coder/coderd/database/dbgen"
2020
"github.com/coder/coder/coderd/rbac"
@@ -28,31 +28,31 @@ func TestNotAuthorizedError(t *testing.T) {
2828

2929
testErr:=xerrors.New("custom error")
3030

31-
err:=authzquery.LogNotAuthorizedError(context.Background(),slogtest.Make(t,nil),testErr)
31+
err:=dbauthz.LogNotAuthorizedError(context.Background(),slogtest.Make(t,nil),testErr)
3232
require.ErrorIs(t,err,sql.ErrNoRows,"must be a sql.ErrNoRows")
3333

34-
varauthErrauthzquery.NotAuthorizedError
34+
varauthErrdbauthz.NotAuthorizedError
3535
require.ErrorAs(t,err,&authErr,"must be a NotAuthorizedError")
3636
require.ErrorIs(t,authErr.Err,testErr,"internal error must match")
3737
})
3838

3939
t.Run("MissingActor",func(t*testing.T) {
4040
t.Parallel()
41-
q:=authzquery.New(dbfake.New(),&coderdtest.RecordingAuthorizer{
41+
q:=dbauthz.New(dbfake.New(),&coderdtest.RecordingAuthorizer{
4242
Wrapped:&coderdtest.FakeAuthorizer{AlwaysReturn:nil},
4343
},slog.Make())
4444
// This should fail because the actor is missing.
4545
_,err:=q.GetWorkspaceByID(context.Background(),uuid.New())
46-
require.ErrorIs(t,err,authzquery.NoActorError,"must be a NoActorError")
46+
require.ErrorIs(t,err,dbauthz.NoActorError,"must be a NoActorError")
4747
})
4848
}
4949

50-
//TestAuthzQueryRecursive is a simple test to search for infinite recursion
50+
//TestdbauthzRecursive is a simple test to search for infinite recursion
5151
// bugs. It isn't perfect, and only catches a subset of the possible bugs
5252
// as only the first db call will be made. But it is better than nothing.
53-
funcTestAuthzQueryRecursive(t*testing.T) {
53+
funcTestdbauthzRecursive(t*testing.T) {
5454
t.Parallel()
55-
q:=authzquery.New(dbfake.New(),&coderdtest.RecordingAuthorizer{
55+
q:=dbauthz.New(dbfake.New(),&coderdtest.RecordingAuthorizer{
5656
Wrapped:&coderdtest.FakeAuthorizer{AlwaysReturn:nil},
5757
},slog.Make())
5858
actor:= rbac.Subject{
@@ -63,7 +63,7 @@ func TestAuthzQueryRecursive(t *testing.T) {
6363
}
6464
fori:=0;i<reflect.TypeOf(q).NumMethod();i++ {
6565
varins []reflect.Value
66-
ctx:=authzquery.WithAuthorizeContext(context.Background(),actor)
66+
ctx:=dbauthz.WithAuthorizeContext(context.Background(),actor)
6767

6868
ins=append(ins,reflect.ValueOf(ctx))
6969
method:=reflect.TypeOf(q).Method(i)
@@ -84,7 +84,7 @@ func TestAuthzQueryRecursive(t *testing.T) {
8484
funcTestPing(t*testing.T) {
8585
t.Parallel()
8686

87-
q:=authzquery.New(dbfake.New(),&coderdtest.RecordingAuthorizer{},slog.Make())
87+
q:=dbauthz.New(dbfake.New(),&coderdtest.RecordingAuthorizer{},slog.Make())
8888
_,err:=q.Ping(context.Background())
8989
require.NoError(t,err,"must not error")
9090
}
@@ -94,7 +94,7 @@ func TestInTX(t *testing.T) {
9494
t.Parallel()
9595

9696
db:=dbfake.New()
97-
q:=authzquery.New(db,&coderdtest.RecordingAuthorizer{
97+
q:=dbauthz.New(db,&coderdtest.RecordingAuthorizer{
9898
Wrapped:&coderdtest.FakeAuthorizer{AlwaysReturn:xerrors.New("custom error")},
9999
},slog.Make())
100100
actor:= rbac.Subject{
@@ -105,14 +105,14 @@ func TestInTX(t *testing.T) {
105105
}
106106

107107
w:=dbgen.Workspace(t,db, database.Workspace{})
108-
ctx:=authzquery.WithAuthorizeContext(context.Background(),actor)
108+
ctx:=dbauthz.WithAuthorizeContext(context.Background(),actor)
109109
err:=q.InTx(func(tx database.Store)error {
110110
// The inner tx should use the parent's authz
111111
_,err:=tx.GetWorkspaceByID(ctx,w.ID)
112112
returnerr
113113
},nil)
114114
require.Error(t,err,"must error")
115-
require.ErrorAs(t,err,&authzquery.NotAuthorizedError{},"must be an authorized error")
115+
require.ErrorAs(t,err,&dbauthz.NotAuthorizedError{},"must be an authorized error")
116116
}
117117

118118
funcmust[Tany](valueT,errerror)T {

‎coderd/authzquery/authzquerier.gorenamed to‎coderd/database/dbauthz/authzquerier.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageauthzquery
1+
packagedbauthz
22

33
import (
44
"context"

‎coderd/authzquery/context.gorenamed to‎coderd/database/dbauthz/context.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageauthzquery
1+
packagedbauthz
22

33
import (
44
"context"
@@ -8,10 +8,6 @@ import (
88
"github.com/coder/coder/coderd/rbac"
99
)
1010

11-
// TODO:
12-
//- We still need a system user for system functions that a user should
13-
//not be able to call.
14-
1511
typeauthContextKeystruct{}
1612

1713
funcWithAuthorizeSystemContext(ctx context.Context,roles rbac.ExpandableRoles) context.Context {

‎coderd/authzquery/file.gorenamed to‎coderd/database/dbauthz/file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageauthzquery
1+
packagedbauthz
22

33
import (
44
"context"

‎coderd/authzquery/file_test.gorenamed to‎coderd/database/dbauthz/file_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageauthzquery_test
1+
packagedbauthz_test
22

33
import (
44
"github.com/coder/coder/coderd/database"

‎coderd/authzquery/group.gorenamed to‎coderd/database/dbauthz/group.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageauthzquery
1+
packagedbauthz
22

33
import (
44
"context"

‎coderd/authzquery/group_test.gorenamed to‎coderd/database/dbauthz/group_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageauthzquery_test
1+
packagedbauthz_test
22

33
import (
44
"github.com/google/uuid"

‎coderd/authzquery/interface.gorenamed to‎coderd/database/dbauthz/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageauthzquery
1+
packagedbauthz
22

33
import"github.com/coder/coder/coderd/database"
44

‎coderd/authzquery/job.gorenamed to‎coderd/database/dbauthz/job.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageauthzquery
1+
packagedbauthz
22

33
import (
44
"context"

‎coderd/authzquery/job_test.gorenamed to‎coderd/database/dbauthz/job_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageauthzquery_test
1+
packagedbauthz_test
22

33
import (
44
"encoding/json"

‎coderd/authzquery/license.gorenamed to‎coderd/database/dbauthz/license.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageauthzquery
1+
packagedbauthz
22

33
import (
44
"context"

‎coderd/authzquery/license_test.gorenamed to‎coderd/database/dbauthz/license_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageauthzquery_test
1+
packagedbauthz_test
22

33
import (
44
"context"

‎coderd/authzquery/methods.gorenamed to‎coderd/database/dbauthz/methods.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageauthzquery
1+
packagedbauthz
22

33
// This file contains uncategorized methods.
44

‎coderd/authzquery/methods_test.gorenamed to‎coderd/database/dbauthz/methods_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageauthzquery_test
1+
packagedbauthz_test
22

33
import (
44
"context"
@@ -18,9 +18,9 @@ import (
1818
"github.com/stretchr/testify/suite"
1919

2020
"cdr.dev/slog"
21-
"github.com/coder/coder/coderd/authzquery"
2221
"github.com/coder/coder/coderd/coderdtest"
2322
"github.com/coder/coder/coderd/database"
23+
"github.com/coder/coder/coderd/database/dbauthz"
2424
"github.com/coder/coder/coderd/database/dbfake"
2525
"github.com/coder/coder/coderd/rbac"
2626
)
@@ -55,7 +55,7 @@ type MethodTestSuite struct {
5555
// SetupSuite sets up the suite by creating a map of all methods on AuthzQuerier
5656
// and setting their count to 0.
5757
func (s*MethodTestSuite)SetupSuite() {
58-
az:=&authzquery.AuthzQuerier{}
58+
az:=&dbauthz.AuthzQuerier{}
5959
azt:=reflect.TypeOf(az)
6060
s.methodAccounting=make(map[string]int)
6161
fori:=0;i<azt.NumMethod();i++ {
@@ -105,14 +105,14 @@ func (s *MethodTestSuite) Subtest(testCaseF func(db database.Store, check *expec
105105
rec:=&coderdtest.RecordingAuthorizer{
106106
Wrapped:fakeAuthorizer,
107107
}
108-
az:=authzquery.New(db,rec,slog.Make())
108+
az:=dbauthz.New(db,rec,slog.Make())
109109
actor:= rbac.Subject{
110110
ID:uuid.NewString(),
111111
Roles: rbac.RoleNames{rbac.RoleOwner()},
112112
Groups: []string{},
113113
Scope:rbac.ScopeAll,
114114
}
115-
ctx:=authzquery.WithAuthorizeContext(context.Background(),actor)
115+
ctx:=dbauthz.WithAuthorizeContext(context.Background(),actor)
116116

117117
vartestCaseexpects
118118
testCaseF(db,&testCase)
@@ -192,7 +192,7 @@ func (s *MethodTestSuite) NoActorErrorTest(callMethod func(ctx context.Context)
192192
s.Run("NoActor",func() {
193193
// Call without any actor
194194
_,err:=callMethod(context.Background())
195-
s.ErrorIs(err,authzquery.NoActorError,"method should return NoActorError error when no actor is provided")
195+
s.ErrorIs(err,dbauthz.NoActorError,"method should return NoActorError error when no actor is provided")
196196
})
197197
}
198198

@@ -212,7 +212,7 @@ func (s *MethodTestSuite) NotAuthorizedErrorTest(ctx context.Context, az *coderd
212212
iferr!=nil||!hasEmptySliceResponse(resp) {
213213
s.Errorf(err,"method should an error with disallow authz")
214214
s.ErrorIsf(err,sql.ErrNoRows,"error should match sql.ErrNoRows")
215-
s.ErrorAs(err,&authzquery.NotAuthorizedError{},"error should be NotAuthorizedError")
215+
s.ErrorAs(err,&dbauthz.NotAuthorizedError{},"error should be NotAuthorizedError")
216216
}
217217
})
218218
}

‎coderd/authzquery/organization.gorenamed to‎coderd/database/dbauthz/organization.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageauthzquery
1+
packagedbauthz
22

33
import (
44
"context"

‎coderd/authzquery/organization_test.gorenamed to‎coderd/database/dbauthz/organization_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageauthzquery_test
1+
packagedbauthz_test
22

33
import (
44
"github.com/google/uuid"

‎coderd/authzquery/parameters.gorenamed to‎coderd/database/dbauthz/parameters.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageauthzquery
1+
packagedbauthz
22

33
import (
44
"context"

‎coderd/authzquery/parameters_test.gorenamed to‎coderd/database/dbauthz/parameters_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageauthzquery_test
1+
packagedbauthz_test
22

33
import (
44
"github.com/coder/coder/coderd/util/slice"

‎coderd/authzquery/system.gorenamed to‎coderd/database/dbauthz/system.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageauthzquery
1+
packagedbauthz
22

33
import (
44
"context"

‎coderd/authzquery/system_test.gorenamed to‎coderd/database/dbauthz/system_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageauthzquery_test
1+
packagedbauthz_test
22

33
import (
44
"context"

‎coderd/authzquery/template.gorenamed to‎coderd/database/dbauthz/template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageauthzquery
1+
packagedbauthz
22

33
import (
44
"context"

‎coderd/authzquery/template_test.gorenamed to‎coderd/database/dbauthz/template_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packageauthzquery_test
1+
packagedbauthz_test
22

33
import (
44
"time"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp