opensearch-project / opensearch-cli

A full-featured command line interface (CLI) for OpenSearch.
https://opensearch.org/docs/latest/clients/cli/
Apache License 2.0
44 stars 24 forks source link

[BUG] CLI cannot create/send multipart POST REST request (from file) #76

Closed jnschbrt closed 10 months ago

jnschbrt commented 1 year ago

What is the bug? My goal is to use opensearch-cli to import the /_dashboards/api/saved_objects/_import REST API However, the API expects the POST request with content-type: multipart/form-data

See: https://github.com/opensearch-project/OpenSearch-Dashboards/blob/d7004dc5b0392477fdd54ac66b29d231975a173b/src/core/server/saved_objects/routes/import.ts

The Opensearch CLI only offers the possibility to specify a file with the --data flag. Native CURL commands offer the possibility to specify the file via --data-binary flag.

The CURL POST command generated by the Opensearch CLI cannot automatically set the multipart boundary, so the post command fails as follows:

I use the authenticated curl post command here as follows:

Without providing headers

opensearch-cli curl post --profile local --path "/_dashboards/api/saved_objects/_import" --data @export.ndjson Error:

{
  "error": "Unsupported Media Type",
  "message": "Unsupported Media Type",
  "statusCode": 415
}

Providing multipart-form-data header

opensearch-cli curl post --profile local --path "/_dashboards/api/saved_objects/_import" -H "content-type:multipart/form-data;" --data @export.ndjson Error:

{
  "error": "Bad Request",
  "message": "Invalid content-type header: multipart missing boundary",
  "statusCode": 400
}

Providing multipart-form-data header and any random boundary

opensearch-cli curl post --profile local --path "/_dashboards/api/saved_objects/_import" -H "content-type:multipart/form-data; boundary:something;" --data @export.ndjson Error:

{
  "error": "Bad Request",
  "message": "Invalid content-type header: multipart missing boundary",
  "statusCode": 400
}

How can one reproduce the bug? Steps to reproduce the behavior:

  1. Export any saved objects via Opensearch Web UI
  2. Try to import these using the cli curl commands above

What is your host/environment?

wbeckler commented 1 year ago

This looks worth fixing. Feel free to submit a PR.

jnschbrt commented 11 months ago

now that the merge request for this issue is already merged into the main. can we expect a new tag or release soon? :)

wbeckler commented 11 months ago

@VachaShah would you be willing to do a release?

VachaShah commented 10 months ago

We have a release planned for today for 1.2.0.

VachaShah commented 10 months ago

We have the release process in progress but figuring out some issues along the way. Build release issue: https://github.com/opensearch-project/opensearch-build/issues/4185

VachaShah commented 10 months ago

Version 1.2.0 is released: https://github.com/opensearch-project/opensearch-cli/releases/tag/v1.2.0