Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andreafspeziale/os-cli
Opinionated and convenient OpenSearch CLI 🔍
https://github.com/andreafspeziale/os-cli
aws cli nest nestjs opensearch searchengine
Last synced: 4 days ago
JSON representation
Opinionated and convenient OpenSearch CLI 🔍
- Host: GitHub
- URL: https://github.com/andreafspeziale/os-cli
- Owner: andreafspeziale
- License: mit
- Created: 2023-07-19T16:32:08.000Z (over 1 year ago)
- Default Branch: develop
- Last Pushed: 2024-04-27T21:21:24.000Z (7 months ago)
- Last Synced: 2024-04-29T23:18:12.761Z (7 months ago)
- Topics: aws, cli, nest, nestjs, opensearch, searchengine
- Language: TypeScript
- Homepage:
- Size: 1.08 MB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
OpenSearch CLI built in Nest,
a progressive Node.js framework for building efficient and scalable server-side applications.
## Installation
> The Official [opensearch-cli](https://opensearch.org/docs/latest/tools/cli/) is also available### npm
```sh
npm install -g @andreafspeziale/os-cli
```### yarn
```sh
yarn global add @andreafspeziale/os-cli
```### pnpm
```sh
pnpm add -g @andreafspeziale/os-cli
```### docker
```sh
docker pull andreafspeziale/os-cli
docker run --rm --env-file .env andreafspeziale/os-cli
```> If using a local (docker) OpenSearch image like the one included in the `docker-compose` file be sure to set correctly the `network` option and `OS_HOST` env variable (OS_HOST=http://opensearch:9200) in the above command (`docker run --rm --env-file .env --network os-cli_default andreafspeziale/os-cli`)
> If using the dockerized CLI and you need to use your json payloads as inputs you'll need to mount the folder into the CLI execution context (e.g `docker run --rm --env-file .env -v ./recipes:/opt/os-cli/recipes --network os-cli_default andreafspeziale/os-cli d q -i books -f recipes/query.json`)
## How to use?
![](./assets/terminal.gif)
### Quickstart
To taste the CLI very quickly using `npx` or after installing it you can spawn OpenSearch locally by using the `docker-compose` file included in the repository:
- `git clone [email protected]:andreafspeziale/os-cli.git`
- `cd os-cli`
- `docker compose up -d`
- `export OS_CONNECTION_METHOD=local`
- `npx @andreafspeziale/os-cli i l` or `os-cli i l`Like the `docker-compose` file there are also some recipes included in the repository:
- `npx @andreafspeziale/os-cli i cr -i books -f ./recipes/create-index.json` or `os-cli i cr -i books -f ./recipes/create-index.json`
- `npx @andreafspeziale/os-cli d cr -i books -f ./recipes/create-documents.json` or `os-cli d cr -i books -f ./recipes/create-documents.json`
- `npx @andreafspeziale/os-cli d q -i books -f ./recipes/query.json` or `os-cli d q -i books -f ./recipes/query.json`### Configuration
> For proxy mode check [aws-sigv4-proxy](https://github.com/awslabs/aws-sigv4-proxy)The CLI leverages environment variables in order to set connection and logging options just once.
| Name | Required | Default | Description | Values |
|-----------------------------|-----------------------------------------------------------|----------------------------------|------------------------------------------------|-----------------------------------------------------------------|
| OS_HOST | when `OS_CONNECTION_METHOD` is NOT _local_ or _proxy_ | `http://localhost:(9200 or 8080)` | OpenSearch connection host | - |
| OS_CONNECTION_METHOD | Yes | - | How you want to connect to OpenSearch | [`local`, `proxy`, `serviceAccount`, `credentials`] |
| AWS_REGION | only when `OS_CONNECTION_METHOD` is NOT _local_ or _proxy_ | - | OpenSearch AWS connection region | - |
| AWS_ROLE_ARN | only when `OS_CONNECTION_METHOD` is _serviceAccount_ | - | AWS role ARN for assume role connection | - |
| AWS_WEB_IDENTITY_TOKEN_FILE | only when `OS_CONNECTION_METHOD` is _serviceAccount_ | - | AWS web identity token file | - |
| AWS_ACCESS_KEY_ID | only when `OS_CONNECTION_METHOD` is _credentials_ | - | AWS access key id for canonical connection | - |
| AWS_SECRET_ACCESS_KEY | only when `OS_CONNECTION_METHOD` is _credentials_ | - | AWS secret access key for canonical connection | - |
| LOGGER_LEVEL | No | `debug` | Which logs will be displayed | [`silent`, `error`, `warn`, `info`, `http`, `verbose`, `debug`] |
| LOGGER_PRETTY | No | `true` | Boolean to enable/disable logs formatting | `true`, `false` |
| LOGGER_REDACT | No | `''` | Removed specified words from logs | - |For a docker local OpenSearch instance all you need to do is:
`export OS_CONNECTION_METHOD=local`
Instead for a canonical AWS connection method a receipt along with your values would be:
```
export OS_HOST=
export OS_CONNECTION_METHOD=credentials
export AWS_REGION=
export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
```## Development
After cloning the repository:
- `cd os-cli`
- `cp ./env/.env.development ./env`
- `docker compose up -d`
- `pnpm install`I personally prefer build in a terminal window and run the compiled version in a separate one like so:
- `pnpm build --watch`
- `pnpm start:prod` or `node dist/os-cli.js`## Stay in touch
- Author - [Andrea Francesco Speziale](https://twitter.com/andreafspeziale)
- Website - [https://nestjs.com](https://nestjs.com/)
- Twitter - [@nestframework](https://twitter.com/nestframework)## License
os-cli [MIT licensed](LICENSE).