Skip to content

WEB-8371: Delete the v1 upload fallback for non-kst tokens - #360

Open
sammyd wants to merge 1 commit into
developmentfrom
web-8371-delete-v1-upload-fallback
Open

sammyd wants to merge 1 commit into
developmentfrom
web-8371-delete-v1-upload-fallback

Conversation

@sammyd

@sammyd sammyd commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Jira: WEB-8371 (part of WEB-7849, API v2 phase 3)

alexandria and betamax removed their v1 endpoints on 16 Nov, so robles's fallback to v1 for a non-kst_ token could only end in a 404 that didn't say the token was the problem. This deletes the fallback. API v2 is the only upload path, and a wrong or missing token now fails before any request, with a message that says what to fix.

What changed

No files removed.

Code paths deleted

  • book_uploader.rb: PUBLISH_URL, the v1 post, api_uri, conn and include Util::Logging (only conn used it).
  • content_module_uploader.rb: PUBLISH_URL, OPEN_TIMEOUT/READ_TIMEOUT, the v1 post with its rescue Faraday::Error, the v1 log helpers (log_upload_start/success/failure, monotonic_now, elapsed_since), api_uri and conn. include Util::Logging stays for the v2 log line.
  • video_course_uploader.rb: UPLOAD_URL, the v1 post, api_uri and conn.
  • upload_with_api_v2 is folded into upload in all three. The module's log line still comes before the post, and the video course's after it.

Added

  • Api::V2Client::TokenError < StandardError and Api::V2Client.require_service_token!(token, name:, service:). Each uploader calls it first. It isn't an Api::V2Client::Error, because no request is made; the runner's rescue StandardError still sends the Slack failure notice. The message (alexandria; betamax is the same with its names):

    Can't publish to alexandria: ALEXANDRIA_SERVICE_API_TOKEN is empty or isn't robles's API v2 token, which starts with "kst_". The old shared token no longer works. Ask Kodeco engineering for robles's kst_ token, and save it in this repo's ALEXANDRIA_SERVICE_API_TOKEN_STAGING or ALEXANDRIA_SERVICE_API_TOKEN_PRODUCTION Actions secret.

    It never includes the token, and empty and wrong tokens get the same message.

Comments reworded where they described v1 as live: the three uploaders, v2_client.rb (the switch comment and the timeout comment that pointed at the deleted constants), config/initialisers/alexandria.rb and .env.sample.

Kept: ALEXANDRIA_SERVICE_API_TOKEN / BETAMAX_SERVICE_API_TOKEN (not renamed), the token: and client: keywords, V2_PUBLISH_PATH, V2_UPLOAD_PATH, V2_TIMEOUT, the payload methods and service_token?.

Tests

  • Deleted: stub_v1 (all three), assert_v1_upload (video), the v1 tests (book 3, module 3, video 2) and test_kst_token_never_builds_v1 (book, module).
  • Rewritten: module test_kst_token_timeout_skips_v1_rescue → test_kst_token_timeout (asserts an Api::V2Client::Error naming Faraday::TimeoutError); video test_kst_token_logs_and_never_builds_v1 → test_kst_token_logs (@conn assertion dropped); video v1_body → upload_body; UnusedClient comments reworded.
  • Added: test_shared_token_is_refused and test_no_token_is_refused in each uploader test, through a shared assert_token_refused helper in test/support/v2_client_stubs.rb (asserts a TokenError, that the message names the variable and both secrets, and that it doesn't contain the token); test_require_service_token in v2_client_test.rb (KST_TOKEN passes; nil, '', the shared token and an upper-case KST_ token raise).

Size: non-test +53 / −171, test +60 / −126. No Gemfile, workflow or config change.

How I verified it

  • bin/test: 215 runs, 0 failures (run in a Debian ruby:4.0.9 container, since the Alpine image's packages can't be fetched here).
  • bin/rubocop: no offences.
  • bundle-audit check --update: only the 7 existing puma 8.0.2 advisories. The bundler-audit job on this PR is red for that reason, not because of this change. Bump puma to 8.0.4 for bundler-audit #359 bumps puma and fixes it; once it merges, development will be merged into this branch.
  • Both greps from the brief come back empty:
    • git grep -n -E "/api/(editions|content_modules)/publish|/api/v1/|PUBLISH_URL|UPLOAD_URL|api_uri|def conn|stub_v1|v1_requests|_uses_v1|never_builds_v1" -- app test config .env.sample
    • git grep -n "uses v1" -- app config .env.sample

Out of scope

  • WEB-8210, WEB-8322 (the secrets command and REPO_* variables), and WEB-8365 to WEB-8370 and WEB-8372.
  • Content repos' Actions secrets and workflows, including the 5 release-v1 books, and the release-v1 image.
  • Dropping the now-unused faraday-retry gem.
  • Checking the token before images are processed.

Rollout

  • Merging into development rebuilds :staging, which every staging workflow uses from its next run. Then run one book and one module staging workflow and check the log for Api::V2Client POST /api/v2/... 201 and Slack success (with ENV=staging a failed run still exits 0).
  • Production: release robles as usual (v2.9.0). There's no migration, flag, environment variable or secret change, and no deploy order.
  • After the deploy, the conductor runs the brief's counts-only checks (api_v2_audit lines from caller robles, by status, for 7 days).
  • Rollback: revert on development; if released, release the revert as a patch.

Generated by Claude Code

alexandria and betamax removed their v1 endpoints on 16 Nov, so the
fallback could only end in a 404. API v2 is now the only upload path.
Api::V2Client.require_service_token! refuses any token but robles's
kst_ token before a request, with a TokenError that says which variable
and which Actions secrets to fix, and never includes the token.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012zKenG3Uv4daWuHUSyQ3qi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant