Nexmo / nexmo-cli

Nexmo CLI (Command Line Interface)
https://nexmo.com
MIT License
78 stars 52 forks source link

Read API Key and Secret from Environment #192

Closed cr0wst closed 5 years ago

cr0wst commented 5 years ago

Summary

This PR updates the CLI to look for NEXMO_API_KEY and NEXMO_API_SECRET environment variables to load the configuration before looking to see if a .nexmorc file has been created.

The motivation for this was in utilizing the CLI in automation tasks (such as GH Actions) required calling:

nexmo setup ${NEXMO_API_KEY} ${NEXMO_API_SECRET}
nexmo sms ...

This allows for the environment to be used as follows:

NEXMO_API_KEY=1234 NEXMO_API_SECRET=abcd nexmo sms...

I was originally going to look into --api-key and --api-secret flags, but I wasn't sure how to add those globally. If there's an easier way to go about doing it, please feel free to reject the PR and I will look into the alternatives.

Other Information

I chose to allow the environment to override the file. This is also useful when testing things using multiple accounts because the environment can be changed at runtime without needing to use a local .nexmorc or modifying an existing .nexmorc.