ExOvh is an elixir library for the Ovh Api.
Add :ex_ovh to the dependencies.
defp deps() do
[
{:ex_ovh, "~> 0.0.1"}
]
end
Create an OVH account at OVH
Create an API application at the OVH API page. Follow the steps outlined by OVH there. This is the correct way to create the OVH application.
Alternatively, there is a mix task which:
Examples using the mix ovh task:
Shell Input:
mix ovh \
--login=<username-ovh> \
--password=<password> \
--appname='ex_ovh'
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. The same name will be used as
the name for the application in OVH. 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
:” 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: System.get_env("EX_OVH_ENDPOINT"),
api_version: System.get_env("EX_OVH_API_VERSION") || "1.0"
]
This configuration can be added to config.exs
.
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.
EX_OVH_ENDPOINT
: The system environment variable name for the ovh endpoint.
EX_OVH_API_VERSION
: The system environment variable name for the api version.
The enviroment variables are saved to a file called .env
automatically by the mix task.
Do not add the .env
file to version control. Add the variables to the system environment
by running the command or some other commands as appropriate to the deployment method.
source .env
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,/cdn]::post-[/me,/cdn]::delete-[]' \
--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
: appname corresponds to the otp_app
name in the elixir application. The same name will be used as
the name for the application in OVH. clientname
:” 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.Ovh.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: System.get_env("MY_APP_OVH_CLIENT_ENDPOINT"),
api_version: System.get_env("MY_APP_OVH_CLIENT_API_VERSION") || "1.0"
]
This configuration can be added to config.exs
.
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.
EX_OVH_ENDPOINT
: The system environment variable name for the ovh endpoint.
EX_OVH_API_VERSION
: The system environment variable name for the api version.
The enviroment variables are saved to a file called .env
automatically by the mix task.
Do not add the .env
file to version control. Add the variables to the system environment
by running the command or some other commands as appropriate to the deployment method.
source .env
Make further configurations if necessary, depending on which OVH services are being used.
In the example below, EX_OVH_WEBSTORAGE_CDN_NAME
is added to the environment variables.
config :ex_ovh,
ovh: [],
swift: [
webstorage: [
cdn_name: System.get_env("MY_APP_OVH_CLIENT_WEBSTORAGE_CDN_NAME"),
type: :webstorage
]
]
In the example below, MY_APP_OVH_CLIENT_CLOUDSTORAGE_TENANT_ID
and MY_APP_OVH_CLIENT_CLOUDSTORAGE_USER_ID
are
added to the environment variables.
config :ex_ovh,
ovh: [],
swift: [
cloudstorage: [
tenant_id: System.get_env("MY_APP_OVH_CLIENT_CLOUDSTORAGE_TENANT_ID"), # mandatory, corresponds to a project id
user_id: System.get_env("MY_APP_OVH_CLIENT_CLOUDSTORAGE_USER_ID"), # optional, if absent a user will be created using the ovh api.
keystone_endpoint: "https://auth.cloud.ovh.net/v2.0", # default endpoint for keystone (identity) auth
region: :nil, # defaults to "SBG1" if set to :nil
type: :cloudstorage
]
]
Optionally configure :openstex
which allows customization of httpoison opts
for each request.
Example configuration for custom httpoison opts (optional):
config :openstex,
httpoison: [
connect_timeout: 30000, # 30 seconds
receive_timeout: (60000 * 30) # 30 minutes
]
The final phase of configuration is to set up the supervision tree. There are effectively two ways to do this:
The ‘correct way’ where a client is setup for the otp_app, therefore allowing for the creation of multiple clients.
Example configuration:
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: System.get_env("MY_APP_OVH_CLIENT_ENDPOINT"),
api_version: System.get_env("MY_APP_OVH_CLIENT_API_VERSION") || "1.0"
]
Add supervisors to the supervision tree of the application, for example:
def start(_type, _args) do
import Supervisor.Spec, warn: false
spec1 = [supervisor(MyApp.Endpoint, [])]
spec2 = [supervisor(MyApp.OvhClient, [])]
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
Supervisor.start_link(spec1 ++ spec2, opts)
end
The ‘quick way’ which is quite useful when only one client is needed.
Example Configuration:
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: System.get_env("EX_OVH_ENDPOINT"),
api_version: System.get_env("EX_OVH_API_VERSION") || "1.0"
]
Then simply add the application to the project applications list. The supervision tree is then started from the application level.
def application do
[
applications: [:ex_ovh]
]
end
Get account details and containers for given account
Creating a new container
Get the container count
Adding an object to the “default” container in OVH CDN Webstorage
Listing all objects for “default” container in OVH CDN Webstorage
Warning No tests have been performed or added yet. This is on my radar.
This is an unofficial client to the OVH api and is not maintained by OVH.
MIT