Skip to content
Lua OVH module for OVH API
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
rockspecs
LICENSE
README.rst
ovh.lua

README.rst

Lightweight wrapper around OVH's APIs. Handles all the hard work including credential creation and requests signing.

local OVH = require 'ovh-api'

local client = OVH.client(
  "ovh-eu",
  "API_KEY",
  "SECRET_KEY",
  "CONSUMER_KEY"
)

-- Print nice welcome message
print("Welcome"..client:get('/me')['firstname'])

Installation

The easiest way to get the latest stable release is to grab it from `luarocks.

luarocks install ovh-api

Example Usage

Use the API on behalf of a user

1. Create an application

To interact with the APIs, the SDK needs to identify itself using an application_key and an application_secret. To get them, you need to register your application. Depending the API you plan yo use, visit:

Once created, you will obtain an application key (AK) and an application secret (AS).

2. Authorize your application to access a customer account

To allow your application to access a customer account using the API on your behalf, you need a consumer key (CK).

Here is a sample code you can use to allow your application to access a customer's informations:

local OVH = require 'ovh-api'

local client = OVH.client(
  'ovh-eu',
  'API_KEY',
  'SECRET_KEY',
)

local data = client:request_consumerkey({
  { method = 'GET', path = '/*'},
  { method = 'POST', path = '/*'},
  { method = 'PUT', path = '/*'}
})

print('Your consumer key is: '..data.consumerKey..'\n')
print('Visit '..data.validationUrl..' to validate the consumer key\n')
print('Press enter when validated\n')
io.read()
print('Welcome '..client:get('/me')['firstname'])

Returned consumerKey should then be kept to avoid re-authenticating your end-user on each use.

Note

To request full and unlimited access to the API, you may use wildcards:

client:request_consumerkey({
  { method = 'GET', path = '/*'},
  { method = 'POST', path = '/*'},
  { method = 'PUT', path = '/*'},
  { method = 'DELETE', path = '/*'}
})

List application authorized to access your account

Thanks to the application key / consumer key mechanism, it is possible to finely track applications having access to your data and revoke this access. This examples lists validated applications. It could easily be adapted to manage revocation too.

This example assumes an existing Configuration_ with valid API_KEY, SECRET_KEY and CONSUMER_KEY.

local OVH = require '../ovh'

-- Get configuration from environment variables
local END_POINT    = os.getenv("OVH_END_POINT")
local API_KEY      = os.getenv("OVH_API_KEY")
local SECRET_KEY   = os.getenv("OVH_SECRET_KEY")
local CONSUMER_KEY = os.getenv("OVH_CONSUMER_KEY")

local client = OVH.client(
  END_POINT,
  API_KEY,
  SECRET_KEY,
  CONSUMER_KEY
)

local credentials = client:get('/me/api/credential', {status='validated'})

local text = 'List of validated credentials: \n'
for _, credentialId in pairs(credentials) do
  local url = '/me/api/credential/'..credentialId
  credential_data = client:get(url)
  credentail_app = client:get(url..'/application')

  local expiration = credential_data.expiration or ''
  local lastUse = credential_data.expiration or ''
  text = text..'Credential ID: '..credentialId..'\n'
    ..'Name: '..credentail_app.name..'\n'
    ..'Description: '..credentail_app.description..'\n'
    ..'Status: '..credentail_app.status..'\n'
    ..'Creation: '..credential_data.creation..'\n'
    ..'Expiration: '..expiration..'\n'
    ..'Last Use: '..lastUse..'\n\n'
end

print(text)

Supported APIs

OVH Europe

OVH North America

So you Start Europe

So you Start North America

Kimsufi Europe

Kimsufi North America

Runabove

You can’t perform that action at this time.