refactor(zendesk): move API calls into a source-operations gateway

Merged
EV
4d ago
+953-272

Description

First PR for Zendesk permission sync. It moves every Zendesk API call into a SourceOperations gateway and adds named indexing checks. Indexing behavior does not change.

  • onyx/connectors/zendesk/source_operations.py: ZendeskSourceOperations owns the request function: the same rate limit (calls_per_minute) and capped Retry-After wait as before. The connector no longer imports requests.
  • The gateway turns HTTP errors into Onyx errors: 401 to CredentialExpiredError, 403 to InsufficientPermissionsError, others to ZendeskRequestError. The messages are the ones validate_connector_settings used.
  • Named indexing checks: zendesk_token (the token's user), zendesk_articles (content tags, one article and its author) and zendesk_tickets (one export page and one ticket's comments). Each content type runs only its own check.

Fixes found while moving the code:

  • Requests retry only rate limits, server errors and network failures. Before, a bad token or a 404 was retried 20 times (about 11 minutes) before it failed.
  • list_ticket_comments follows the comment cursor. Before, a ticket with more than 100 comments lost the comments after the first page.
  • validate_connector_settings probes the configured content type. Before, a tickets connector on an account without a Help Center failed validation on the articles endpoint.
  • An unauthenticated users/me returns 200 with an anonymous user; get_me reports that as a credential error.
  • The subdomain field also accepts http://, www. and a trailing path.

The next PRs add the article and ticket access, doc sync and group sync.

How Has This Been Tested?

  • Unit: the Zendesk connector tests now drive the real gateway with a stubbed request function, plus the source-operation coverage, import fence and check declaration tests.
  • New unit tests for the retry filter, the subdomain parsing, the anonymous user and the validation probe. The retry and probe tests fail without their fixes.
  • Daily: tests/daily/connectors/zendesk passes against the CI Zendesk account (articles and tickets, full and slim).

Docs

  • Customer-facing change: I updated documentation/ for the page's reader and task, at the level of detail of the whole page.
  • No docs change needed: the existing docs stay correct (internal, tests, CI, multi-tenant cloud only, or the UI explains it).

Additional Options

  • [Optional] Please cherry-pick this PR to the latest release version.

🤖 Generated with Claude Code


Summary by cubic

Moves every Zendesk API call into a ZendeskSourceOperations gateway and adds named indexing checks, with no change to indexing behavior. This is the first step toward Zendesk permission sync.

Refactors

  • The connector no longer imports requests; the gateway owns requests, rate limiting, and error mapping.
  • 401 becomes CredentialExpiredError, 403 InsufficientPermissionsError, other failures ZendeskRequestError, and an inactive Support product a validation error.
  • Indexing checks (zendesk_articles or zendesk_tickets) run per content type, gated by the connector config; each still probes zendesk_token.
  • Ticket indexing no longer reads Guide content tags, so Support-only accounts index without a Help Center.

Bug Fixes

  • Requests retry only rate limits, server errors, and network failures; a bad token, 404, or inactive Support product fails immediately instead of after ~11 minutes.
  • Cursor walks now fail when a page claims more items without advancing; before, list_ticket_comments dropped comments past the first 100 and checkpointed article indexing re-read the same page.
  • validate_connector_settings probes the configured content type and re-raises when Zendesk is unreachable, so an outage is not reported as a bad setting.
  • users/me returning an anonymous user is now a credential error, and a non-JSON 403 body no longer crashes the check.
  • User lookups log refusals other than a deleted user, and comment and content tag listings past 100,000 items fail loudly.
  • The tickets check reads the comments of a live ticket, skipping deleted ones.
  • The subdomain field accepts http://, www., and a trailing path.

[!NOTE]

Move Zendesk API calls into ZendeskSourceOperations gateway

  • Adds source_operations.py with typed page/user models, cursor validation, retry with capped Retry-After, per-minute rate limiting, and error translation (401 → CredentialExpiredError, 403 → InsufficientPermissionsError).
  • Rewrites the connector in connector.py to use the gateway for article/ticket pagination, author lookup, comment listing, and validation. The removed ZendeskClient is gone.
  • Adds Zendesk capability checks (token, articles, tickets) in capability_checks.py and registers them in the capability-check registry.
  • Behavioral changes: ticket indexing no longer requests Help Center content tags; article checkpoint retrieval now fails when a page does not advance its cursor; validation probes the selected content type instead of always fetching an article page. Check ZendeskConnector.validate_connector_settings and _retrieve_articles for regressions.

Macroscope summarized d7496e3.

Summary by CodeRabbit

  • New Features
    • Added Zendesk connection checks for credentials and access to articles and tickets, including related author and comment data.
    • Zendesk data retrieval supports pagination, rate limiting, and retries for temporary request failures.
    • Checks provide guidance when article authors cannot be read or no articles or tickets are available.
    • Article and ticket content are checked separately, so results reflect the selected content type.
    • Connection validation reports missing Zendesk content as not found and identifies other request errors.