Skip to content

Commit 81b6a3f

Browse files
committed
chore: Remove interface from coderd and lift API surface
Abstracting coderd into an interface added misdirection because the interface was never intended to be fulfilled outside of a single implementation. This lifts the abstraction, and attaches all handlers to a root struct named `*coderd.API`.
1 parent c78f947 commit 81b6a3f

21 files changed

+206
-227
lines changed

cli/server.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ func server() *cobra.Command {
319319
// These errors are typically noise like "TLS: EOF". Vault does similar:
320320
// https://github.com/hashicorp/vault/blob/e2490059d0711635e529a4efcbaa1b26998d6e1c/command/server.go#L2714
321321
ErrorLog: log.New(io.Discard, "", 0),
322-
Handler: coderDaemon.Handler(),
322+
Handler: coderDaemon,
323323
BaseContext: func(_ net.Listener) context.Context {
324324
return shutdownConnsCtx
325325
},
@@ -387,15 +387,15 @@ func server() *cobra.Command {
387387
signal.Notify(stopChan, os.Interrupt)
388388
select {
389389
case <-cmd.Context().Done():
390-
coderDaemon.CloseWait()
390+
coderDaemon.Close()
391391
return cmd.Context().Err()
392392
case err := <-tunnelErrChan:
393393
if err != nil {
394394
return err
395395
}
396396
case err := <-errCh:
397397
shutdownConns()
398-
coderDaemon.CloseWait()
398+
coderDaemon.Close()
399399
return err
400400
case <-stopChan:
401401
}
@@ -459,7 +459,7 @@ func server() *cobra.Command {
459459

460460
_, _ = fmt.Fprintf(cmd.OutOrStdout(), cliui.Styles.Prompt.String()+"Waiting for WebSocket connections to close...\n")
461461
shutdownConns()
462-
coderDaemon.CloseWait()
462+
coderDaemon.Close()
463463
return nil
464464
},
465465
}
@@ -555,7 +555,7 @@ func createFirstUser(cmd *cobra.Command, client *codersdk.Client, cfg config.Roo
555555
}
556556

557557
// nolint:revive
558-
func newProvisionerDaemon(ctx context.Context, coderDaemon coderd.CoderD,
558+
func newProvisionerDaemon(ctx context.Context, coderDaemon *coderd.API,
559559
logger slog.Logger, cacheDir string, errChan chan error, dev bool) (*provisionerd.Server, error) {
560560
err := os.MkdirAll(cacheDir, 0700)
561561
if err != nil {

coderd/authorize.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import (
1212
"github.com/coder/coder/coderd/rbac"
1313
)
1414

15-
func AuthorizeFilter[O rbac.Objecter](api *api, r *http.Request, action rbac.Action, objects []O) []O {
15+
func AuthorizeFilter[O rbac.Objecter](api *API, r *http.Request, action rbac.Action, objects []O) []O {
1616
roles := httpmw.UserRoles(r)
1717
return rbac.Filter(r.Context(), api.Authorizer, roles.ID.String(), roles.Roles, action, objects)
1818
}
1919

20-
func (api *api) Authorize(rw http.ResponseWriter, r *http.Request, action rbac.Action, object rbac.Objecter) bool {
20+
func (api *API) Authorize(rw http.ResponseWriter, r *http.Request, action rbac.Action, object rbac.Objecter) bool {
2121
roles := httpmw.UserRoles(r)
2222
err := api.Authorizer.ByRoleName(r.Context(), roles.ID.String(), roles.Roles, action, object.RBACObject())
2323
if err != nil {

0 commit comments

Comments
 (0)