Kourou is coming or why you should use the Kuzzle CLI

Today we see CLI from everywhere, everybody wants it’s own CLI: Heroku, Vue.js, React, and so on.

 

But why this hype?

 

Version française

 

At Kuzzle we also wondered what we would get out of having a nice CLI full of features, because we were a bit fed up with curl and wscat.

 

So we started to develop a CLI to allow us to work more efficiently in our daily projects, and now we would like to officially share it with all our users :-)

Have you met Kourou ?

Kourou is therefore a command line interface that allows you to administer your Kuzzle.

 

But why Kourou? The French who read us may know this name: it is the launch base for the Ariane rockets in French Guiana.

 

It's a multi-command CLI that uses Oclif, Heroku's CLI framework, and bonus to be even more hype: we even developed it in Typescript.

 

 

 

Currently Kourou is still under heavy development and we are adding features every week.

 

Of course, these commands interact with the Kuzzle API by logging in and logging in, but not only that!

 

Let’s install it:

$ npm install -g kourou

Launch a Kuzzle stack

The first command is of course a command that launches a complete Kuzzle stack!

 

You can even launch several of them, the port numbers will be automatically shifted (7512, 7513, ...).

 

And you can even see the logs of your instances ;-)

 

$ kourou instance:spawn

$ kourou instance:logs

Manage your API keys

You may not know it but since Kuzzle v2 you can connect with API keys.

 

Kourou offers to create, delete and list them from your terminal.

 

$ kourou api-key:create aschen --description "Awesome API key"

🚀 Kourou - Creates a new API Key for a user

[] Connecting to http://localhost:7512 ...

Successfully created API Key "8Og2wnABna5MX9iEmgsX" for user "aschen"

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiJhc2NoZW4iLCJpYXQiOjE1ODM4MDYzMjN9.hWV3Y2QJKH_AFYa9DoFRRmzM4EvMFWzeIzYEDwUpCYU

 

$ kourou api-key:search aschen

🚀 Kourou - Lists a user's API Keys.

[] Connecting to http://localhost:7512 ...

2 API Keys found for user aschen

- Key "8Og2wnABna5MX9iEmgsX"
Description: Awesome API key
Expires at: -1

- Key "8ug3wnABna5MX9iEtwua"
Description: Too lazy to login key
Expires at: -1

Given the simplicity, you have no more excuses not to use them ;-)

Dump and restore Kuzzle data

We all know the frustration of a bug present on the server but not reproducible locally because of database differences.

 

With Kourou it is possible to easily dump an entire index, or a collection, and then re-import it elsewhere!

 

$ kourou index:export corona-data --path /backups
 🚀 Kourou - Dump an entire index content (JSONL format)
 
 [] Connecting to https://localhost:7512 ...
 Dumping index "corona-data" in ./backups/corona-data/ ...
 Dumping france |========================================| 100% || 42/42 documents
 Dumping italie |========================================| 100% || 21/21 documents
 Dumping espagne |========================================| 100% || 84/84 documents
 [] Index corona-data dumped

 

$ kourou index:import /backups/corona-data  
🚀 Kourou - Restore the content of a previously dumped index
 
 [] Connecting to http://localhost:7512 ...
 [] Start importing dump from /backups/corona-data in same index
  [] Successfully imported 42 documents in "corona-data:france"
  [] Successfully imported 21 documents in "corona-data:italie"
  [] Successfully imported 84 documents in "corona-data:espagne" 
 [] Dump directory /backups/corona-data successfully imported

 

 

The format used is JSONL, portable and readable. Kourou handles large volumes, allowing millions of documents to be imported or exported easily.

Encrypting and decrypting the Vault

Using the Vault to share the secrets of a project is cool but using Kourou to manage it is totally hype!

 

You can easily add a key to an existing file without having to decrypt everything and then encrypt it again.

 

$ kourou vault:add secrets.enc.json kuzzle.apiKey some-key --vault-key vault-password
 
 🚀 Kourou - Adds an encrypted key to a secrets file
 
 [] Key "kuzzle.apiKey" has been securely added "secrets.enc.json"

 

And if you have forgotten what was in a particular API key, you can display the content of a key in a single line.

 

$ kourou vault:show secrets.enc.json kuzzle.apiKey --vault-key vault-password     
 
 🚀 Kourou - Prints an encrypted key.
 
 [] Key "kuzzle.apiKey" content:
 some-key

Send API requests directly to Kuzzle

The Kuzzle API is quite huge and we're not going to reproduce it identically in Kourou (at least not right away).


But don't panic, we've added the query command which allows to send a request directly by specifying controller, action, arguments and body ;-)

 

$ kourou query index:create --arg index=corona-data
 
 🚀 Kourou - Executes an API query
 
 [] Connecting to http://localhost:7512 ...
 Successfully executed "index:create"

 

$ kourou query admin:loadMappings < mappings.json
 
 🚀 Kourou - Executes an API query
 
 [] Connecting to http://localhost:7512 ...
 Successfully executed "admin:loadMappings"

And a lot of other things!

New commands are added as soon as they are useful, for example you can manage your documents or send requests directly to Elasticsearch.

 

The complete list is available in the README on Github or by typing kourou --help

Conclusion

You'll have understood, Kourou is the tool you need to be even more productive with Kuzzle ;-)

 

If you have ideas of features to add, don't hesitate to propose it to us by opening an issue on Github!
Or even better, try to develop it yourself and do a PR, we love it :-)

Alexandre Bouthinon

Related posts