Add seed-sample.ps1 file - #3070
Conversation
📝 WalkthroughWalkthroughThe PR adds a PowerShell 5.1+ sample-seeding script for API and MCP samples. It adds authentication, documentation uploads, duplicate handling, failure reporting, distribution packaging, and Windows usage documentation. The Bash script also encodes credentials and reports failures through its exit status. ChangesSample seeding workflows
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant PowerShellScript
participant curl.exe
participant PlatformAPI
participant SampleDirectories
PowerShellScript->>SampleDirectories: Read API and MCP samples
PowerShellScript->>curl.exe: Send URL-encoded login request
curl.exe->>PlatformAPI: Authenticate administrator
PlatformAPI-->>PowerShellScript: Return access token
PowerShellScript->>PlatformAPI: Create sample entries
PowerShellScript->>PlatformAPI: Upload documentation archives
PlatformAPI-->>PowerShellScript: Return operation statuses
PowerShellScript->>PowerShellScript: Report totals and exit status
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
portals/api-portal/distribution/README.md (1)
86-92: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a curl.exe prerequisite note for Windows, matching the setup.ps1 precedent.
The Quick Start section notes the
opensslprerequisite forsetup.ps1on Windows (Lines 46-47). This section documentsseed-samples.ps1the same way but omits that the script requirescurl.exeon PATH (per the script's own header comment). Add a short note here, consistent with the existing pattern.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@portals/api-portal/distribution/README.md` around lines 86 - 92, Update the Windows Quick Start instructions for seed-samples.ps1 to add a concise prerequisite note that curl.exe must be installed and available on PATH, matching the existing setup.ps1 prerequisite wording and the script header.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@portals/api-portal/scripts/seed-samples.ps1`:
- Around line 229-304: Wrap the complete per-sample workflow in
Invoke-SeedEntry, including Invoke-SeedDocs, in a try/catch so terminating
errors are handled locally. In the catch block, write the sample as failed using
the existing failure symbols/output style, call Add-Counter $Endpoint 'FAILED',
and return without rethrowing; keep the existing success, skip, and API-error
paths unchanged so the ForEach-Object loops continue processing later samples.
- Around line 135-137: URL-encode both $AdminUsername and $AdminPassword before
constructing $loginBody in the PowerShell login flow, preserving the form field
names and login request. Apply the equivalent percent-encoding to the username
and password in the seed-samples.sh login call so both scripts handle special
characters consistently.
- Around line 306-321: The seed-samples script currently reports failures
without returning a failing process status. Update the final summary flow after
calculating $TotalFailed so the script exits with code 1 when $TotalFailed -gt
0, while preserving the existing successful completion behavior and output.
---
Nitpick comments:
In `@portals/api-portal/distribution/README.md`:
- Around line 86-92: Update the Windows Quick Start instructions for
seed-samples.ps1 to add a concise prerequisite note that curl.exe must be
installed and available on PATH, matching the existing setup.ps1 prerequisite
wording and the script header.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 77d772cf-88a8-4bf8-9c0b-ef6d30ef411a
📒 Files selected for processing (3)
portals/api-portal/Makefileportals/api-portal/distribution/README.mdportals/api-portal/scripts/seed-samples.ps1
f0cc5cb to
1a6ef09
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@portals/api-portal/scripts/seed-samples.sh`:
- Around line 100-107: Update the administrator login curl invocation in the
TOKEN assignment to remove the insecure -k option, preserving certificate
validation. If private CA support is required, configure curl with an explicit
trusted bundle via --cacert instead.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: aa36801d-f40e-40cf-b259-9af962bc679f
📒 Files selected for processing (4)
portals/api-portal/Makefileportals/api-portal/distribution/README.mdportals/api-portal/scripts/seed-samples.ps1portals/api-portal/scripts/seed-samples.sh
🚧 Files skipped from review as they are similar to previous changes (2)
- portals/api-portal/Makefile
- portals/api-portal/distribution/README.md
1a6ef09 to
de57a64
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
portals/api-portal/scripts/seed-samples.ps1 (1)
138-141: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick winTLS certificate validation is disabled on every Platform/API Portal call in both scripts.
seed-samples.ps1andseed-samples.shboth invoke curl with-k/-sk, and both scripts acceptAPI_PORTAL_URL/PLATFORM_API_URLoverrides, so a failure to validate the server certificate is not confined to local, self-signed docker-compose endpoints. This shared root cause exposesADMIN_USERNAME,ADMIN_PASSWORD, and the bearer token to interception when either script targets a remote host.
portals/api-portal/scripts/seed-samples.ps1#L138-L141: remove-kfrom the logincurl.execall, or add an explicit--cacert <bundle>option sourced from an env var for trusted self-signed CAs.portals/api-portal/scripts/seed-samples.ps1#L213-L218: apply the same fix to the docs-asset uploadcurl.execall.portals/api-portal/scripts/seed-samples.ps1#L252-L257: apply the same fix to the entry-creationcurl.execall built via$curlArgs.portals/api-portal/scripts/seed-samples.sh#L100-L107: apply the same fix to the logincurlcall (this specific instance was already flagged as Major in a prior review round and remains unresolved).🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@portals/api-portal/scripts/seed-samples.ps1` around lines 138 - 141, The curl calls disable TLS certificate validation; remove -k/-sk from all four affected calls or replace them with an explicit --cacert bundle sourced from an environment variable. Update portals/api-portal/scripts/seed-samples.ps1 lines 138-141 (login), 213-218 (docs-asset upload), and 252-257 (entry creation via $curlArgs), plus portals/api-portal/scripts/seed-samples.sh lines 100-107 (login), while preserving support for configured API/Platform URLs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Duplicate comments:
In `@portals/api-portal/scripts/seed-samples.ps1`:
- Around line 138-141: The curl calls disable TLS certificate validation; remove
-k/-sk from all four affected calls or replace them with an explicit --cacert
bundle sourced from an environment variable. Update
portals/api-portal/scripts/seed-samples.ps1 lines 138-141 (login), 213-218
(docs-asset upload), and 252-257 (entry creation via $curlArgs), plus
portals/api-portal/scripts/seed-samples.sh lines 100-107 (login), while
preserving support for configured API/Platform URLs.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 45bc6892-c130-4ea5-be66-5033ee7b9067
📒 Files selected for processing (4)
portals/api-portal/Makefileportals/api-portal/distribution/README.mdportals/api-portal/scripts/seed-samples.ps1portals/api-portal/scripts/seed-samples.sh
🚧 Files skipped from review as they are similar to previous changes (2)
- portals/api-portal/Makefile
- portals/api-portal/distribution/README.md
Purpose
$subject
Security checks