Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5aa6149

Browse files
committed
set up an authorization context for OrganizationSyncEnabled
1 parent 738faf6 commit 5aa6149

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

cli/server.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,14 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
851851
lic.Trial = &trial
852852
return nil
853853
},
854-
OrganizationSyncEnabled: coderAPI.IDPSync.OrganizationSyncEnabled,
854+
OrganizationSyncEnabled: func() bool {
855+
if coderAPI == nil || coderAPI.IDPSync == nil {
856+
return false
857+
}
858+
// AsSystemRestricted is fine here because it's a read-only operation
859+
// used for telemetry reporting.
860+
return coderAPI.IDPSync.OrganizationSyncEnabled(dbauthz.AsSystemRestricted(ctx), options.Database)
861+
},
855862
})
856863
if err != nil {
857864
return xerrors.Errorf("create telemetry reporter: %w", err)

coderd/telemetry/telemetry.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type Options struct {
5656
// We pass this function instead of the IDPSync interface because it creates
5757
// a circular import. We don't need all the other methods, and this approach
5858
// is simpler than refactoring the package structure.
59-
OrganizationSyncEnabled func(ctx context.Context, db database.Store) bool
59+
OrganizationSyncEnabled func() bool
6060
}
6161

6262
// New constructs a reporter for telemetry data.
@@ -250,7 +250,7 @@ func (r *remoteReporter) deployment() error {
250250

251251
idpOrgSync := false
252252
if r.options.OrganizationSyncEnabled != nil {
253-
idpOrgSync = r.options.OrganizationSyncEnabled(r.ctx, r.options.Database)
253+
idpOrgSync = r.options.OrganizationSyncEnabled()
254254
} else {
255255
r.options.Logger.Debug(r.ctx, "organization sync enabled function is nil, skipping IDP org sync check")
256256
}

0 commit comments

Comments
 (0)