ListActiveSessions returns a set of all active sessions in a given storage.
(ctx context.Context)
| 187 | |
| 188 | // ListActiveSessions returns a set of all active sessions in a given storage. |
| 189 | func (bm *WriteManager) ListActiveSessions(ctx context.Context) (map[SessionID]*SessionInfo, error) { |
| 190 | blobs, err := blob.ListAllBlobs(ctx, bm.st, BlobIDPrefixSession) |
| 191 | if err != nil { |
| 192 | return nil, errors.Wrap(err, "unable to list session blobs") |
| 193 | } |
| 194 | |
| 195 | m := map[SessionID]*SessionInfo{} |
| 196 | |
| 197 | var payload gather.WriteBuffer |
| 198 | defer payload.Close() |
| 199 | |
| 200 | var decrypted gather.WriteBuffer |
| 201 | defer decrypted.Close() |
| 202 | |
| 203 | for _, b := range blobs { |
| 204 | payload.Reset() |
| 205 | decrypted.Reset() |
| 206 | |
| 207 | sid := SessionIDFromBlobID(b.BlobID) |
| 208 | if sid == "" { |
| 209 | return nil, errors.Errorf("found invalid session blob %v", b.BlobID) |
| 210 | } |
| 211 | |
| 212 | si := &SessionInfo{} |
| 213 | |
| 214 | err := bm.st.GetBlob(ctx, b.BlobID, 0, -1, &payload) |
| 215 | if err != nil { |
| 216 | if errors.Is(err, blob.ErrBlobNotFound) { |
| 217 | continue |
| 218 | } |
| 219 | |
| 220 | return nil, errors.Wrapf(err, "error loading session: %v", b.BlobID) |
| 221 | } |
| 222 | |
| 223 | err = blobcrypto.Decrypt(bm.format, payload.Bytes(), b.BlobID, &decrypted) |
| 224 | if err != nil { |
| 225 | return nil, errors.Wrapf(err, "error decrypting session: %v", b.BlobID) |
| 226 | } |
| 227 | |
| 228 | if err := json.NewDecoder(decrypted.Bytes().Reader()).Decode(si); err != nil { |
| 229 | return nil, errors.Wrapf(err, "error parsing session: %v", b.BlobID) |
| 230 | } |
| 231 | |
| 232 | if old := m[sid]; old == nil || si.CheckpointTime.After(old.CheckpointTime) { |
| 233 | m[sid] = si |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | return m, nil |
| 238 | } |
nothing calls this directly
no test coverage detected