Skip to content

Add encrypted GitHub library tokens and retrieval diagnostics - #1948

Open
adamant-pwn wants to merge 5 commits into
maths:devfrom
adamant-pwn:iss1947
Open

adamant-pwn wants to merge 5 commits into
maths:devfrom
adamant-pwn:iss1947

Conversation

@adamant-pwn

@adamant-pwn adamant-pwn commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Administrators can configure encrypted GitHub tokens in STACK settings to access private question libraries and authenticate public-library requests. A default token can serve several libraries, with optional tokens for individual entries. Access is shared with authorised external-library users.

STACK tries the library token first, then a different default token if GitHub denies access. Rate limits and connection or server errors do not trigger fallback. Downloads use the token selected when listing the library. Changing tokens or library settings clears the cache.

Browser requests and CLI scripts use the same settings. CI populates the default setting with its temporary read-only token and preserves it across PHPUnit resets. Requests are restricted to HTTPS on api.github.com without redirects. Retrieval errors report HTTP status, cURL errors and numeric rate-limit information without exposing credentials or response bodies.

Preview images remain accessible without login to anyone with their URL; the settings help explains this limitation. Site backups must include Moodle’s encryption key.

Prepared with AI assistance.

@sangwinc
sangwinc requested a review from EJMFarrow October 30, 2026 10:49
@sangwinc

Copy link
Copy Markdown
Member

Thanks @adamant-pwn. @EJMFarrow could you please review this?

@EJMFarrow EJMFarrow left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @adamant-pwn . Good idea! It just needs to be a bit more useable by normal users. Happy to discuss.

Comment thread stack/questionlibrary.class.php Resolved
Comment thread stack/questionlibrary.class.php Resolved
@adamant-pwn adamant-pwn changed the title Support optional GitHub authentication and clearer retrieval errors Add encrypted GitHub library tokens and retrieval diagnostics Nov 6, 2026
Use encrypted default and per-library tokens for browser and CLI requests, with access-error fallback. Populate the same setting in CI and preserve it across PHPUnit resets. Use Moodle HTTP header collection and retain numeric rate-limit diagnostics.
@adamant-pwn

adamant-pwn commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator Author

Thanks for the review! It's now a bit bigger, but also hopefully better integrate it with a way for administrators to set this up without server access, so it's useful outside CI too.

Comment thread stack/questionlibrary.class.php Resolved
Moodle setting names allow only letters, digits and underscores, so the catalogue key is hashed. The full SHA-256 made the name shown under each admin field overflow. Keep the first 16 hex characters, as the private demo manifest does for question IDs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@EJMFarrow

Copy link
Copy Markdown
Collaborator

Code looking good, @adamant-pwn . I think I must have closed the review by accident, though! I still want to have a look over the tests a bit further.

@EJMFarrow EJMFarrow left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, looks good. Thank you!

This branch has not been deployed

No deployments
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.

3 participants