Added simple script to fetch API specs, #PG-5043#949
Conversation
| $params['token_auth'] = $tokenAuth; | ||
|
|
||
| $url = $baseUrl . '/index.php?' . http_build_query($params); | ||
| $response = @file_get_contents($url); |
There was a problem hiding this comment.
we should use curl ideally for remote URLs
|
|
||
| $written++; | ||
| } catch (Throwable $e) { | ||
| fwrite(STDERR, "Failed for $plugin: {$e->getMessage()}\n"); |
There was a problem hiding this comment.
Here it will keep continuing unnecessarily if file_put_contents fail, the issue would be consistent for all
AltamashShaikh
left a comment
There was a problem hiding this comment.
@lachiebol left few comments
|
From codex: This doesn't seem too bad for our use case right? I know we could write to a tmp folder then move after everything is done. Not sure if I need to address that one. |
AltamashShaikh
left a comment
There was a problem hiding this comment.
@lachiebol AI review
High-risk issues (blocking)
- Secret leakage in error output: fetch-openapi-specs.php:26 and fetch-openapi-specs.php:43 include the full request URL in thrown exceptions. That URL contains token_auth, so any network/API failure will print
credentials to stderr via the top-level handlers at fetch-openapi-specs.php:71 and fetch-openapi-specs.php:112. For a script likely to run in CI or shared shells, that is a real credential exposure.
- Stale spec files are never removed: the script only writes files for the current whitelist, but the docs app enumerates all matching files on disk via app/helpers/OpenApiSpecRegistry.php:21. If a plugin is removed
from the whitelist or renamed, its old *_openapi_spec_v1.0.0.json file remains and will still be shown in the UI. That makes the generated docs drift from the source instance.
Secret leakage in error output: Should only be leaking token_auth anonymous but can remove that Stale spec files are never removed: Can fix that one |
AltamashShaikh
left a comment
There was a problem hiding this comment.
@lachiebol Looks good we can test it together after deployment and I should be able to create a cron for you
Description
NOTE: This OpenApiDocs change is needed to run this script matomo-org/plugin-ApiReference#30
Script to pull specs from cloud, default MATOMO_BASE_URL will be demo.matomo.cloud
MATOMO_BASE_URL="{matomo-url}" php fetch-openapi-specs.phpChecklist
Review