Skip to content

Feat/mandi publish tools - CLI - #39

Open
kelvinprabhu wants to merge 16 commits into
mainfrom
feat/mandi-publish-tools
Open

kelvinprabhu wants to merge 16 commits into
mainfrom
feat/mandi-publish-tools

Conversation

@kelvinprabhu

Copy link
Copy Markdown
Collaborator

What's in this PR

This PR adds a new mandi_publish CLI for publishing Agmarknet Vistaar market data, along with shared infrastructure for catalog publishing.

1. Added mandi_publish

Adds a CLI under:

tools/publish/mandi_publish

It:

  • Collects market data from Agmarknet Vistaar.
  • Builds catalog/publish payloads for each state.
  • Supports writing generated catalogs to disk.
  • Optionally publishes the catalogs to a provider adapter.

Example:

export MANDI_TOKEN_USER=...
export MANDI_TOKEN_SECRET=...

go run ./tools/publish/mandi_publish \
  --states MH \
  --from 01-09-2026 \
  --to 30-09-2026 \
  --catalog-out ./catalog

Use --publish to send the generated catalog to the adapter:

go run ./tools/publish/mandi_publish \
  --states MH \
  --from 01-09-2026 \
  --to 30-09-2026 \
  --catalog-out ./catalog \
  --publish \
  --publish-url http://localhost:9200

2. Added shared internal/catalogpublish transport

Introduces:

internal/catalogpublish

This provides the shared transport used by mandi_publish to send catalog/publish requests.

The transport is intended to be reusable by other publishing tools in the future.

3. Updated the adapter Docker image

Dockerfile.adapter-with-plugins now builds all tools under:

tools/publish/

As a result, mandi_publish is available inside the adapter image at:

/app/bin/mandi_publish

4. Updated the Mandi catalog structure

The Mandi catalog was updated to follow the canonical OpenAgriNet conventions:

  • Schema references now use the canonical openagrinet.github.io/network-specs/... URLs instead of the stale raw.githubusercontent.com/... URLs.
  • Catalog IDs now follow:
catalog:mandi-price:<STATE>
  • Resource IDs now follow:
resource:mandi-price:market:<id>
  • Added resourceAttributes.source.
  • Added state-level coverageAreas using ISO-3166-2.
  • Added the longDesc and shortDesc fields expected by the schema.

5. End-to-end verification

The complete flow was tested against a local OAN quick-start stack:

mandi_publish
      ↓
catalog/publish
      ↓
discover
      ↓
select
      ↓
Agmarknet market price

Verified successfully:

  • Catalog publishing
  • Spatial filtering during discovery
  • Commodity filtering during discovery
  • Select returning the real Agmarknet price
  • Direct mode round-trip

Running inside Docker

docker exec \
  -e MANDI_TOKEN_USER=your_user \
  -e MANDI_TOKEN_SECRET=your_secret \
  -e MANDI_API_URI=http://34.0.4.235:8080 \
  -e MANDI_PUBLISH_URL=http://localhost:9200 \
  -e MANDI_PARTICIPANT_ID=agmarknet-live \
  -e APP_NETWORK_ID=oan-dev \
  onix-adapter \
  /app/bin/mandi_publish \
  --from 01-09-2026 \
  --to 30-09-2026 \
  --catalog-out /app/catalog \
  --publish

…data

- Implemented main functionality to authenticate and collect market master data across India.
- Added configuration handling for base URL, states, date range, and output file.
- Introduced data collection logic with error handling for state-specific failures.
- Created mappings for market-commodity and master data to facilitate data transformation.
- Developed comprehensive tests to ensure functionality and error handling.
- Embedded mappings into the binary to avoid external dependencies.
…ctionality

- Introduced a new YAML mapping file for generating Beckn catalog payloads from Agmarknet market data.
- Implemented HTTP client for publishing catalogs to the provider adapter.
- Added tests for handling scenarios with no data from upstream and ensuring proper error reporting.
- Created a run function to collect data and build catalogs without generating a collection document.
- Enhanced publish functionality to handle transport errors and catalog retirement.
- Updated `build_test.go` to improve market resource validation and ensure accurate reporting of geometry-related issues.
- Introduced `chunk_test.go` to validate chunking behavior for states exceeding geometry limits and ensure proper handling of markets without coordinates.
- Enhanced `main.go` to improve catalog reporting, including detailed summaries of excluded markets and geometry-less markets.
- Added `publish.go` changes to correctly associate catalog files with their respective states, accommodating split states.
- Created `report_test.go` to validate the accuracy of reports generated for excluded markets and chunked states.
- Updated `catalog.yaml` to streamline market object creation and ensure correct catalog IDs.
- Removed redundant tests in `main_test.go` to maintain clarity and focus on essential functionality.
Move serveMappings() and newMapper() from mandi_publish/mappings.go to
internal/catalogpublish/mapper.go as public functions that accept an embed.FS
and directory name. Update all call sites in mandi_publish to use the new
public API. This generalizes the mapper setup for reuse by other tools.
Const block was space-indented instead of tab-indented, with a stray
blank line before the following const block. No functional change.
…coverage area to catalog mapping

Bring the catalog/publish payload closer to the OpenAgriNet target schema:
resourceAttributes.source, resource longDesc, provider shortDesc, and an
ISO-3166-2 state coverageArea alongside the existing district one. Left
market.location.geo out deliberately — coverageAreas is already the sole
geometry copy, per the existing per-catalog geometry budget.
@github-actions

Copy link
Copy Markdown

📊 Test Coverage: ✅ Passed — 84% of changed lines covered, min 80%

@github-actions

Copy link
Copy Markdown

🛡️ Trivy security scan (CRITICAL,HIGH,MEDIUM,LOW)

View full run

Go dependencies

No findings at CRITICAL,HIGH,MEDIUM,LOW.

Container image

Package Severity Installed Fixed in Advisory
zlib MEDIUM 1.3.2-r7 1.3.3-r0 CVE-2026-85091

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.

1 participant