Commit 6d5e680
authored
feat(pools): channel parity (REST + Telegram) and refresh-grant token-host scoping (#47)
* feat(poolops): extract channel-agnostic pool operations
Move pool create/list/status/rotate/remove logic into internal/poolops
so CLI, REST, and Telegram share one implementation. Adds structured
errors (already-pooled member, live-member removal, delete conflict)
returned channel-neutrally.
* feat(cli): wire pool subcommand through poolops
sluice pool create|list|status|rotate|remove now delegate to the
shared poolops package; rotate-race hint points to 'sluice pool status'.
* feat(api): rest endpoints for credential pools
Add /api/pools CRUD plus status/rotate via poolops; pool-create
honors the 409 conflict contract and returns structured
pool-delete conflict payloads. Token-host grant parse restricted
to form bodies.
* feat(telegram): /pool create|list|status|rotate|remove commands
Telegram bot reaches pool management through poolops, matching CLI
and REST channel parity.
* fix(proxy): scope pool token-host phantom expansion to refresh_token grants
Restrict the pool token-host phantom split-host expansion to
refresh_token grant requests so non-refresh traffic is unaffected;
parse only form bodies.
* feat(telegram): friendlier pool failover notification text
Reword the pool failover Telegram notice into human-readable text
(task 4b).
* docs: document /pool and /api/pools surfaces; channel-parity plan
Document the pool management surfaces across CLI/REST/Telegram in
CLAUDE.md and README, and record the channel-feature-parity plan
(incl. task 4b) as completed.
* fix(api): dedicated pool-referenced 409 schema; build create 201 from request data
split the pool-delete 409 body into PoolReferencedErrorResponse so the
generic ErrorResponse envelope is no longer coupled to one endpoint
(regenerated api.gen.go via oapi-codegen). PostApiPools now builds the
201 body from the request members + failover default instead of gating
on a store read-back, so a read-back error can no longer report a
successful create as a 500. poolStatusError no longer checks
ErrCredentialInUseByPool, which is unreachable from the pool handlers
(raised only by the credential-removal path).
* fix(proxy): gate grant_type probe to token-host POSTs; raise+observe probe cap
requestFlowGrantType now skips the string(body)+ParseQuery grant_type
probe unless the request is an HTTP POST whose scheme+host matches a
known OAuth token endpoint (new OAuthIndex.MatchesHost), removing the
per-request body parse on the hot path for non-OAuth traffic. The
form/JSON parsers in extractRequestRefreshToken and requestGrantType no
longer double-stringify the body for an explicit form Content-Type. The
probe cap is raised 8KiB->64KiB so a large RFC 7523 refresh payload at a
pool token host is still expanded, with a rate-limited WARNING when the
cap truncates a probe. StreamRequestModifier's buffered-path-only
limitation is documented explicitly.
* fix(proxy): drop awkward parenthetical from empty-reason failover notice
FormatFailoverNotice rendered '(unknown reason)' / 'after unknown
reason' when the reason tag was empty. Drop the reason clause entirely
in that case for both the exhausted and normal messages. The
cred_failover / pool_exhausted audit Reason format is unchanged.
* fix(telegram): escape pool name in rotate-race hint; assert pool removal
the /pool status hint in the rotate-race message wrote the raw pool name
into an HTML-parsed reply, so a name with <,>,& would break rendering;
htmlCode it like the other occurrence. The pool-remove test guarded on
'err == nil', which GetPool returns even for a missing pool; assert the
pool row is actually gone instead.
* docs(readme): note bearer auth required for REST API examples
the /api/* curl examples omit the Authorization header though the
endpoints are behind BearerAuth; add a single leading note covering the
credential, pool, and rule examples.
* fix(telegram): drop dead ErrCredentialInUseByPool branch in poolRemove
* fix(api): map internal pool-create failures to 500 not 400
Invert poolCreateError: conflict sentinels stay 409, genuine client-input
validation sentinels are 400, and everything else (tx/DB/INSERT failures
inside store.CreatePoolWithMembers, which are wrapped fmt.Errorf strings
with no sentinel) now defaults to 500 instead of being misclassified as a
client 400. Add typed, errors.Is-able sentinels in internal/store for the
client-validation cases that previously had only wrapped messages
(ErrPoolNoMembers, ErrPoolStrategyInvalid, ErrPoolMemberDuplicate,
ErrPoolMemberNotFound, ErrPoolMemberNotOAuth), wrapped at origin so the
existing human-readable text is preserved verbatim. Document the new 500
response on POST /api/pools in the OpenAPI spec and regenerate.
* fix(proxy): make unknown failover reason read naturally; drop dead empty case
humanizeFailoverReason now renders an unknown tag as 'unknown reason
(<tag>)' so the surrounding 'failed over ... after %s.' and exhausted
'... to (%s).' clauses read naturally instead of the redundant 'failed
over ... after failover (<tag>).'. Remove the unreachable case "":
branch: FormatFailoverNotice is the sole caller and short-circuits an
empty reason before ever calling here, so the empty-tag wording has a
single source of truth there. Update the notice/humanize tests
accordingly.
* fix(telegram): HTML-escape pool member LastFailureReason in status
poolStatus sends with HTML parse mode (htmlCode emits <code>), but
appended m.LastFailureReason (upstream error text, may contain < > &)
raw, which breaks rendering or is rejected by the Bot API. Escape it
with htmlEscape (prose, not an identifier, so not htmlCode) consistent
with every other user-facing value on that line. Add a test asserting a
reason with < > & is rendered escaped.
* fix(telegram): html-escape bind hint in pool create reply1 parent 2e54339 commit 6d5e680
25 files changed
Lines changed: 3276 additions & 228 deletions
File tree
- api
- cmd/sluice
- docs/plans
- internal
- api
- poolops
- proxy
- store
- telegram
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
| 184 | + | |
| 185 | + | |
184 | 186 | | |
185 | 187 | | |
186 | 188 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
329 | 329 | | |
330 | 330 | | |
331 | 331 | | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
332 | 337 | | |
333 | 338 | | |
334 | 339 | | |
| |||
338 | 343 | | |
339 | 344 | | |
340 | 345 | | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
341 | 351 | | |
342 | 352 | | |
343 | 353 | | |
| |||
350 | 360 | | |
351 | 361 | | |
352 | 362 | | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
353 | 383 | | |
354 | 384 | | |
355 | 385 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
519 | 519 | | |
520 | 520 | | |
521 | 521 | | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
522 | 655 | | |
523 | 656 | | |
524 | 657 | | |
| |||
619 | 752 | | |
620 | 753 | | |
621 | 754 | | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
622 | 785 | | |
623 | 786 | | |
624 | 787 | | |
| |||
1009 | 1172 | | |
1010 | 1173 | | |
1011 | 1174 | | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
1012 | 1267 | | |
1013 | 1268 | | |
1014 | 1269 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
516 | 516 | | |
517 | 517 | | |
518 | 518 | | |
519 | | - | |
520 | | - | |
521 | | - | |
522 | | - | |
523 | | - | |
524 | | - | |
| 519 | + | |
525 | 520 | | |
526 | 521 | | |
527 | 522 | | |
| |||
0 commit comments