Skip to content

Add seed-sample.ps1 file - #3070

Merged
Piumal1999 merged 1 commit into
wso2:mainfrom
lasanthaS:devportal-fixes
Aug 3, 2026
Merged

Add seed-sample.ps1 file#3070
Piumal1999 merged 1 commit into
wso2:mainfrom
lasanthaS:devportal-fixes

Conversation

@lasanthaS

Copy link
Copy Markdown
Contributor

Purpose

$subject

Security checks

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

Sample seeding workflows

Layer / File(s) Summary
Script foundation and runtime setup
portals/api-portal/scripts/seed-samples.ps1
The PowerShell script adds configuration, path discovery, logging, error handling, terminal output, and curl.exe validation.
Authentication and documentation upload
portals/api-portal/scripts/seed-samples.ps1
The script authenticates with the Platform API, creates ZIP archives with built-in APIs, and uploads documentation archives.
API and MCP sample seeding
portals/api-portal/scripts/seed-samples.ps1
The script traverses sample directories, creates API and MCP entries, handles duplicates and failures, updates counters, and reports totals.
Bash authentication and failure status
portals/api-portal/scripts/seed-samples.sh
The Bash script URL-encodes login credentials and exits with status 1 when a seed operation fails.
Distribution packaging and instructions
portals/api-portal/Makefile, portals/api-portal/distribution/README.md
The distribution includes seed-samples.ps1 and documents Windows PowerShell commands for running it.

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
Loading

Possibly related PRs

  • wso2/api-platform#2734: The PowerShell seeding support and Bash script hardening extend the existing sample-seeding distribution and script functionality.

Suggested reviewers: krishanx92, piumal1999, renuka-fernando

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description contains only a placeholder purpose and security checks, while most required template sections are missing. Complete the Purpose, Goals, Approach, User stories, Documentation, Automation tests, Samples, Related PRs, and Test environment sections.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title identifies the main change, but it uses the singular filename and omits related distribution and shell-script updates.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
portals/api-portal/distribution/README.md (1)

86-92: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a curl.exe prerequisite note for Windows, matching the setup.ps1 precedent.

The Quick Start section notes the openssl prerequisite for setup.ps1 on Windows (Lines 46-47). This section documents seed-samples.ps1 the same way but omits that the script requires curl.exe on 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7a73a65 and f0cc5cb.

📒 Files selected for processing (3)
  • portals/api-portal/Makefile
  • portals/api-portal/distribution/README.md
  • portals/api-portal/scripts/seed-samples.ps1

Comment thread portals/api-portal/scripts/seed-samples.ps1
Comment thread portals/api-portal/scripts/seed-samples.ps1
Comment thread portals/api-portal/scripts/seed-samples.ps1

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between f0cc5cb and 1a6ef09.

📒 Files selected for processing (4)
  • portals/api-portal/Makefile
  • portals/api-portal/distribution/README.md
  • portals/api-portal/scripts/seed-samples.ps1
  • portals/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

Comment thread portals/api-portal/scripts/seed-samples.sh

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
portals/api-portal/scripts/seed-samples.ps1 (1)

138-141: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

TLS certificate validation is disabled on every Platform/API Portal call in both scripts. seed-samples.ps1 and seed-samples.sh both invoke curl with -k/-sk, and both scripts accept API_PORTAL_URL/PLATFORM_API_URL overrides, so a failure to validate the server certificate is not confined to local, self-signed docker-compose endpoints. This shared root cause exposes ADMIN_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 -k from the login curl.exe call, 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 upload curl.exe call.
  • portals/api-portal/scripts/seed-samples.ps1#L252-L257: apply the same fix to the entry-creation curl.exe call built via $curlArgs.
  • portals/api-portal/scripts/seed-samples.sh#L100-L107: apply the same fix to the login curl call (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

📥 Commits

Reviewing files that changed from the base of the PR and between 1a6ef09 and de57a64.

📒 Files selected for processing (4)
  • portals/api-portal/Makefile
  • portals/api-portal/distribution/README.md
  • portals/api-portal/scripts/seed-samples.ps1
  • portals/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

@Piumal1999
Piumal1999 merged commit 397df10 into wso2:main Aug 3, 2026
11 checks passed
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.

2 participants