Branch
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.
Shell input:
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:
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. 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'
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:
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.
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.
source .env
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
# 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
```