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)
| 171 | // that user is authorized to `ActionRead` on. The provided context must have |
| 172 | // a dbauthz actor set. |
| 173 | func (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 | |
| 200 | func produceUpdate(oldWS, newWS workspacesByID) (out *proto.WorkspaceUpdate, updated bool) { |
| 201 | out = &proto.WorkspaceUpdate{ |