MCPcopy Index your code
hub / github.com/coder/coder / Subscribe

Method Subscribe

coderd/workspaceupdates.go:173–198  ·  view source on GitHub ↗

Subscribe subscribes to workspace updates for a user, for the workspaces that user is authorized to `ActionRead` on. The provided context must have a dbauthz actor set.

(ctx context.Context, userID uuid.UUID)

Source from the content-addressed store, hash-verified

171// that user is authorized to `ActionRead` on. The provided context must have
172// a dbauthz actor set.
173func (u *updatesProvider) Subscribe(ctx context.Context, userID uuid.UUID) (tailnet.Subscription, error) {
174 actor, ok := dbauthz.ActorFromContext(ctx)
175 if !ok {
176 return nil, xerrors.Errorf("actor not found in context")
177 }
178 ctx, cancel := context.WithCancel(u.ctx)
179 ctx = dbauthz.As(ctx, actor)
180 ch := make(chan *proto.WorkspaceUpdate, 1)
181 sub := &sub{
182 ctx: ctx,
183 cancelFn: cancel,
184 userID: userID,
185 ch: ch,
186 db: u.db,
187 ps: u.ps,
188 logger: u.logger.Named(fmt.Sprintf("workspace_updates_subscriber_%s", userID)),
189 prev: workspacesByID{},
190 }
191 err := sub.start(ctx)
192 if err != nil {
193 _ = sub.Close()
194 return nil, err
195 }
196
197 return sub, nil
198}
199
200func produceUpdate(oldWS, newWS workspacesByID) (out *proto.WorkspaceUpdate, updated bool) {
201 out = &proto.WorkspaceUpdate{

Callers

nothing calls this directly

Calls 6

startMethod · 0.95
CloseMethod · 0.95
ActorFromContextFunction · 0.92
AsFunction · 0.92
NamedMethod · 0.80
ErrorfMethod · 0.45

Tested by

no test coverage detected