Feature: Add support for user-configurable egg/nests index file.#2287
Feature: Add support for user-configurable egg/nests index file.#2287JorgenVatle wants to merge 3 commits intopelican-dev:mainfrom
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughThe egg index source URL is now configurable via Changes
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
I have read the CLA Document and I hereby sign the CLA |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@app/Console/Commands/Egg/UpdateEggIndexCommand.php`:
- Line 16: The UpdateEggIndexCommand currently assumes the HTTP response
assigned to $data contains a nested structure (e.g. $data['nests']) which can
throw if the JSON is malformed; validate the schema after the GET: check that
$data is an array, that 'nests' exists and is an array, and that each nest
contains an 'eggs' array with the expected keys before indexing; in the
UpdateEggIndexCommand replace direct indexing of $data['nests']/$nest['eggs']
with guarded checks (using is_array/array_key_exists or Laravel helpers like
Arr::get/data_get), log a clear error and abort or skip when the shape is
invalid, and default to an empty list to avoid breaking downstream egg
selection.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: a0c7d71a-06c8-475d-bb74-c2edb04b8b21
📒 Files selected for processing (2)
app/Console/Commands/Egg/UpdateEggIndexCommand.phpconfig/panel.php
| { | ||
| try { | ||
| $data = Http::timeout(5)->connectTimeout(1)->get('https://raw.githubusercontent.com/pelican-eggs/pelican-eggs.github.io/refs/heads/main/content/pelican.json')->throw()->json(); | ||
| $data = Http::timeout(5)->connectTimeout(1)->get(config('panel.egg.index_url'))->throw()->json(); |
There was a problem hiding this comment.
Validate response schema before indexing nested keys.
With a user-configurable URL, non-conforming JSON is now much more likely. Accessing $data['nests'] (and deeper keys) without guards can fail at runtime and break downstream egg selection that assumes a strict cached shape.
🔧 Proposed hardening
- $data = Http::timeout(5)->connectTimeout(1)->get(config('panel.egg.index_url'))->throw()->json();
+ $data = Http::timeout(5)->connectTimeout(1)->get(config('panel.egg.index_url'))->throw()->json();
} catch (Exception $exception) {
$this->error($exception->getMessage());
return 1;
}
+
+ if (!is_array($data) || !isset($data['nests']) || !is_array($data['nests'])) {
+ $this->error('Invalid egg index payload: expected top-level "nests" array.');
+ return 1;
+ }
$index = [];
foreach ($data['nests'] as $nest) {
+ if (
+ !is_array($nest) ||
+ !isset($nest['nest_type'], $nest['Eggs']) ||
+ !is_array($nest['Eggs'])
+ ) {
+ continue;
+ }
$nestName = $nest['nest_type'];
@@
$nestEggs = [];
foreach ($nest['Eggs'] as $egg) {
+ if (
+ !is_array($egg) ||
+ !isset($egg['download_url'], $egg['egg']['name'])
+ ) {
+ continue;
+ }
$eggName = $egg['egg']['name'];🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@app/Console/Commands/Egg/UpdateEggIndexCommand.php` at line 16, The
UpdateEggIndexCommand currently assumes the HTTP response assigned to $data
contains a nested structure (e.g. $data['nests']) which can throw if the JSON is
malformed; validate the schema after the GET: check that $data is an array, that
'nests' exists and is an array, and that each nest contains an 'eggs' array with
the expected keys before indexing; in the UpdateEggIndexCommand replace direct
indexing of $data['nests']/$nest['eggs'] with guarded checks (using
is_array/array_key_exists or Laravel helpers like Arr::get/data_get), log a
clear error and abort or skip when the shape is invalid, and default to an empty
list to avoid breaking downstream egg selection.
There was a problem hiding this comment.
This was an issue prior to the changes introduced here. I'd like to follow up with a separate PR to emit less obscure validation errors if the received JSON is malformed.
There was a problem hiding this comment.
@JorgenVatle, that's fair — this concern predates the changes in this PR. Would you like me to open a GitHub issue to track the follow-up validation work so it doesn't get lost?
| { | ||
| try { | ||
| $data = Http::timeout(5)->connectTimeout(1)->get('https://raw.githubusercontent.com/pelican-eggs/pelican-eggs.github.io/refs/heads/main/content/pelican.json')->throw()->json(); | ||
| $data = Http::timeout(5)->connectTimeout(1)->get(config('panel.egg.nest_url'))->throw()->json(); |
There was a problem hiding this comment.
Move the config value to panel.cdn.egg_index_url.
Bit of a feature suggestion here. Noticed the URL used to build up the list of suggested official eggs was hardcoded. This pull request moves the URL into the application config with an optional environment override.
We have a number of custom egg configs that we want to offer to our admins. Copy pasting URLs for those was getting a little tedious, especially if one is accidentally deleted and you don't have the original URL handy.
This should address that, plus open up for users to make eggs discoverable through the import menu, or limit which nests should appear in the menu.
Not sure what you have on the roadmap, but I'd be happy to work on a follow-up to this where nests can be merged with a user-provided URL instead of replaced outright.