# Webtask CLI: all you need is code Command line tool for using [webtasks](https://webtask.io) to create microservices in seconds. ## Setup ```bash $ npm i -g wt-cli $ wt init ``` ## Usage ### Create a webtask Write webtask code to the *hello-world.js* file: ```javascript module.exports = function (cb) { cb(null, 'Hello webtasks!'); } ``` ```bash wt create hello-world.js ``` and call it... ```bash curl https://webtask.it.auth0.com/api/run/{yours}/hello-world ``` ### Create a webtask (from a public URL) ```bash wt create https://raw.githubusercontent.com/auth0/wt-cli/master/sample-webtasks/html-response.js \ --name html-response-url ``` ### Create a webtask with a secret ```bash wt create https://raw.githubusercontent.com/auth0/wt-cli/master/sample-webtasks/mongodb.js \ --name mongo \ --secret MONGO_URL=mongodb://webtask:supersecret@ds047592.mongolab.com:47592/webtask-examples ``` > This is a real mongodb URL (powered by mongolab), no guarantee that it will work :) ### Create a webtask that integrates with express.js ```bash wt create https://raw.githubusercontent.com/auth0/wt-cli/master/sample-webtasks/express.js \ --name express \ --dependency express \ --dependency body-parser ``` ### Log streaming ```bash wt logs ``` ### Cron a webtask (long running) ```bash wt cron schedule -n mongocron \ -s MONGO_URL=mongodb://webtask:supersecret@ds047592.mongolab.com:47592/webtask-examples \ "*/10 * * * *" \ https://raw.githubusercontent.com/auth0/wt-cli/master/sample-webtasks/mongodb.js ``` > This cron will insert a document in a mongo collection every 10 minutes ### Get cron history ```bash wt cron history mongogron ``` ### Get all scheduled webtasks ```bash wt cron ls ``` # Auth0 CLI: extend Auth0 with custom code (BETA) Auth0 hooks enable you to extend the Auth0 platform with custom code. Auth0 CLI allows you to manage Auth0 hooks for your Auth0 account. Auth0 hooks are webtasks associated with specific extensibility points of the Auth0 platform that are invoked by Auth0 runtime to execute your custom logic. ## Setup Follow the instructions from the Account > Webtasks panel on the Auth0 management dashboard to install and configure `wt-cli`. The package now includes `auth0` binary in addition to `wt`. **NOTE** While Auth0 CLI is in BETA, the `wt-cli` tool must be installed from a branch of this repository instead of the public npm registry. Use `npm i -g auth0/wt-cli#auth0` to install the tool. The rest of the instructions on the Auth0 management portal applies without changes. ## Overview Auth0 CLI allows you to create, list, enable/disable, edit, and remove Auth0 hooks associated with specific extensibility points within the Auth0 platform, as well as receive real-time logging information generated by custom code. The list of supported extensibility points will be growing over time. Currently, the following extensibility points are supported: [client-credentials-exchange](https://github.com/auth0/auth0-ext-compilers/blob/master/client-credentials-exchange.md) [password-exchange](https://github.com/auth0/auth0-ext-compilers/blob/master/password-exchange.md) [pre-user-registration](https://github.com/auth0/auth0-ext-compilers/blob/master/pre-user-registration.md) [post-user-registration](https://github.com/auth0/auth0-ext-compilers/blob/master/post-user-registration.md) For each of the extensibility points, there can be several Auth0 hooks created. A hook can be enabled or disabled, but only up to one hook per extensibility point can be enabled at a time. Disabled hooks are useful for staging new functionality. ## Synopsis The script below assumes you are creating an Auth0 hook for the `pre-user-registration` extensibility point using profile name `tj-default`. You can use any of the extensibility points listed above and the actual profile name has been provided to you during `wt-cli` setup. ```bash # Scaffold sample code of an Auth0 hook: auth0 scaffold -t pre-user-registration > file.js # Create a new, disabled Auth0 hook: auth0 create -t pre-user-registration --name my-extension-1 -p tj-default file.js # Edit code of the Auth0 hook: auth0 edit my-extension-1 # Enable the newly created extensibility point (all other hooks associated # with the same extensibility point will be disabled): auth0 enable my-extension-1 -p tj-default # List hooks for a specific extensibility point: auth0 ls -t pre-user-registration -p tj-default # List all Auth0 hooks on your account: auth0 ls -p tj-default # Access streaming, real-time logs of all of your hooks: auth0 logs -p tj-default # Disable a hook: auth0 disable my-extension-1 -p tj-default # Delete a hook: auth0 rm my-extension-1 -p tj-default ``` # Closing remarks ## Working behind a proxy `wt-cli` supports operating behind a proxy as of `v6.1.0`. The cli relies on the `HTTP_PROXY` (or `http_proxy`) environment variable to determine if proxy support needs to be enabled. The `HTTP_PROXY` environment variable must be set to a uri according to the following table: | Protocol | Proxy Agent for `http` requests | Proxy Agent for `https` requests | Example |:----------:|:-------------------------------:|:--------------------------------:|:--------: | `http` | [http-proxy-agent](https://github.com/TooTallNate/node-http-proxy-agent) | [https-proxy-agent](https://github.com/TooTallNate/node-https-proxy-agent) | `http://proxy-server-over-tcp.com:3128` | `https` | [http-proxy-agent](https://github.com/TooTallNate/node-http-proxy-agent) | [https-proxy-agent](https://github.com/TooTallNate/node-https-proxy-agent) | `https://proxy-server-over-tls.com:3129` | `socks(v5)`| [socks-proxy-agent](https://github.com/TooTallNate/node-socks-proxy-agent) | [socks-proxy-agent](https://github.com/TooTallNate/node-socks-proxy-agent) | `socks://username:password@some-socks-proxy.com:9050` (username & password are optional) | `socks5` | [socks-proxy-agent](https://github.com/TooTallNate/node-socks-proxy-agent) | [socks-proxy-agent](https://github.com/TooTallNate/node-socks-proxy-agent) | `socks5://username:password@some-socks-proxy.com:9050` (username & password are optional) | `socks4` | [socks-proxy-agent](https://github.com/TooTallNate/node-socks-proxy-agent) | [socks-proxy-agent](https://github.com/TooTallNate/node-socks-proxy-agent) | `socks4://some-socks-proxy.com:9050` | `pac` | [pac-proxy-agent](https://github.com/TooTallNate/node-pac-proxy-agent) | [pac-proxy-agent](https://github.com/TooTallNate/node-pac-proxy-agent) | `pac+http://www.example.com/proxy.pac` > * See [http-proxy-agent](https://github.com/TooTallNate/node-proxy-agent/blob/master/README.md) for the source of this table. ## Issue Reporting If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The [Responsible Disclosure Program](https://auth0.com/whitehat) details the procedure for disclosing security issues. ## Author [Auth0](https://auth0.com) ## License This project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more info.