kmx.io/ex_ovh/docs/mix_task.md

Branch

Stephen Moloney 028b24372 2017-02-23T12:19:43
v0.3.0 (refactor for httpipe)

Mix Task

Generate ExOvh Config

The ovh mix task makes requests to the OVH API on the user’s behalf to generate an OVH application.

The environment variables generated by the task are automatically save to a .env file. It is best to ensure that this file is outside version control.

Example 1

Shell input:

mix ovh --login=<username-ovh> --password=<password> --appname='my_app_name'

Shell Output:

config :ex_ovh,
  ovh: [
    application_key: System.get_env("EX_OVH_APPLICATION_KEY"),
    application_secret: System.get_env("EX_OVH_APPLICATION_SECRET"),
    consumer_key: System.get_env("EX_OVH_CONSUMER_KEY"),
    endpoint: "ovh-eu",
    api_version: "1.0"
  ]

Terms explained:

Example 2

Shell Input:

mix ovh \
--login=<username-ovh> \
--password=<password> \
--appdescription='Ovh Application for my app' \
--endpoint='ovh-eu' \
--apiversion='1.0' \
--redirecturi='http://localhost:4000/' \
--accessrules='get-[/*]::put-[/me,/me/*,/cdn/webstorage,/cdn/webstorage/*]::post-[/me,/cdn/webstorage,/cdn/webstorage/*]::delete-[/cdn/webstorage,/cdn/webstorage/*]' \
--appname='my_app' \
--clientname='OvhClient'

Shell Output:

config :my_app, MyApp.OvhClient,
    ovh: [
      application_key: System.get_env("MY_APP_OVH_CLIENT_APPLICATION_KEY"),
      application_secret: System.get_env("MY_APP_OVH_CLIENT_APPLICATION_SECRET"),
      consumer_key: System.get_env("MY_APP_OVH_CLIENT_CONSUMER_KEY"),
      endpoint: "ovh-eu",
      api_version: "1.0"
    ]

Terms explained:

Add the settings to the environment

source .env

Source

# Mix Task

#### Generate ExOvh Config

The ovh mix task makes requests to the OVH API on the user's behalf to generate an OVH application.

- The mix task:

  1. Creates an application on the user's behalf by sending http requests using the user's username and password credentials.
  2. Gets a consumer key and validation url.
  3. Validates the validation url on the user's behalf by sending http requests using the user's username and password credentials.
  4. Adds the application key, application secret and associated consumer key to the environment configuration.
  
The environment variables generated by the task are automatically save to a `.env` file. It is best to ensure that this file is outside
version control.


#### Example 1


**Shell input:**

```shell
mix ovh --login=<username-ovh> --password=<password> --appname='my_app_name'
```

- `login`: username/nic_handle for logging into OVH services. *Note*: must include `-ovh` at the end of the string.
- `password`: password for logging into OVH services.
- `appname`: this should correspond to the `otp_app` name in the elixir application. It also doubles as the application name 
for the application in the OVH servers.
- `redirecturi`: defaults to `""` when absent.
- `endpoint`: defaults to `"ovh-eu"` wen absent.
- `accessrules`: defaults to `get-[/*]::put-[/*]::post-[/*]::delete-[/*]` when absent giving the application all
  full priveleges. One may consider fine-tuning the accessrules, see advanced example below.
- `appdescription`: defaults to `appname` if absent
- `clientname`:" This is the elixir client name. defaults to `ExOvh` when the appname is exactly equal to `ex_ovh`, otherwise defaults to `OvhClient`.


**Shell Output:**

```elixir
config :ex_ovh,
  ovh: [
    application_key: System.get_env("EX_OVH_APPLICATION_KEY"),
    application_secret: System.get_env("EX_OVH_APPLICATION_SECRET"),
    consumer_key: System.get_env("EX_OVH_CONSUMER_KEY"),
    endpoint: "ovh-eu",
    api_version: "1.0"
  ]
```

Terms explained:

- `EX_OVH_APPLICATION_KEY`: The system environment variable name for the application key.
- `EX_OVH_APPLICATION_SECRET`: The system environment variable name for the application secret.
- `EX_OVH_CONSUMER_KEY`: The system environment variable name for the consumer key.


#### Example 2

**Shell Input:**

```shell
mix ovh \
--login=<username-ovh> \
--password=<password> \
--appdescription='Ovh Application for my app' \
--endpoint='ovh-eu' \
--apiversion='1.0' \
--redirecturi='http://localhost:4000/' \
--accessrules='get-[/*]::put-[/me,/me/*,/cdn/webstorage,/cdn/webstorage/*]::post-[/me,/cdn/webstorage,/cdn/webstorage/*]::delete-[/cdn/webstorage,/cdn/webstorage/*]' \
--appname='my_app' \
--clientname='OvhClient'
```

- `login`: username/nic_handle for logging into OVH services. *Note*: must include `-ovh` at the end of the string.
- `password`: password for logging into OVH services.
- `appname`: this should correspond to the `otp_app` name in the elixir application. It also doubles as the application name
for the application in the OVH servers.
- `clientname`:" This is the elixir client name. defaults to `ExOvh` when the appname is exactly equal to `ex_ovh`, otherwise defaults to `OvhClient`. `clientname` corresponds to the name of the client. So for example, if appname is `'my_app'` and clientname is
  `'Client'` then the config file will be `config :my_app, MyApp.Client`. Also, the client in application code can be referred
  to as `MyApp.Client.function_name`.
- `appdescription`: A description for the application saved to OVH.
- `endpoint`: OVH endpoint to be used. May vary depending on the OVH service. See `ExOvh.Defaults`.
- `apiversion`: version of the api to use. Only one version available currently.
- `redirecturi`: redirect url for oauth authentication. Should be https.
- `accessrules`: restrictions can be added to the access rules. In this example, `get` requests to all endpoints are allowed,
  `put` and `post` requests to `/me` and `/cdn` and `delete` requests are forbidden.


**Shell Output:**


```elixir
config :my_app, MyApp.OvhClient,
    ovh: [
      application_key: System.get_env("MY_APP_OVH_CLIENT_APPLICATION_KEY"),
      application_secret: System.get_env("MY_APP_OVH_CLIENT_APPLICATION_SECRET"),
      consumer_key: System.get_env("MY_APP_OVH_CLIENT_CONSUMER_KEY"),
      endpoint: "ovh-eu",
      api_version: "1.0"
    ]
```


Terms explained:

- `MY_APP_OVH_CLIENT_APPLICATION_KEY`: The system environment variable name for the application key.
- `MY_APP_OVH_CLIENT_APPLICATION_SECRET`: The system environment variable name for the application secret.
- `MY_APP_OVH_CLIENT_CONSUMER_KEY`: The system environment variable name for the consumer key.


#### Add the settings to the environment

- Copy the configuration outputted by the commandline to `config.exs`.

- The enviroment variables are saved to a file called `.env` automatically by the mix task.
**Do not add the `.env` file to version control.** It would be prudent to add `.env` to the `.gitignore` file.
Add the variables to the system environment by running the command or some other commands as appropriate
to the deployment method.


```shell
source .env
```
Download