|
| 1 | +Lightweight wrapper around OVH's APIs. Handles all the hard work including |
| 2 | +credential creation and requests signing. |
| 3 | + |
| 4 | +.. code:: lua |
| 5 | +
|
| 6 | + local OVH = require 'ovh-api' |
| 7 | +
|
| 8 | + local client = OVH.client( |
| 9 | + "ovh-eu", |
| 10 | + "API_KEY", |
| 11 | + "SECRET_KEY", |
| 12 | + "CONSUMER_KEY" |
| 13 | + ) |
| 14 | +
|
| 15 | + -- Print nice welcome message |
| 16 | + print("Welcome"..client:get('/me')['firstname']) |
| 17 | +
|
| 18 | +Installation |
| 19 | +============ |
| 20 | + |
| 21 | +The easiest way to get the latest stable release is to grab it from ```luarocks``. |
| 22 | + |
| 23 | +.. code:: bash |
| 24 | +
|
| 25 | + luarocks install ovh-api |
| 26 | +
|
| 27 | +Example Usage |
| 28 | +============= |
| 29 | + |
| 30 | +Use the API on behalf of a user |
| 31 | +------------------------------- |
| 32 | + |
| 33 | +1. Create an application |
| 34 | +************************ |
| 35 | + |
| 36 | +To interact with the APIs, the SDK needs to identify itself using an |
| 37 | +``application_key`` and an ``application_secret``. To get them, you need |
| 38 | +to register your application. Depending the API you plan yo use, visit: |
| 39 | + |
| 40 | +- `OVH Europe <https://eu.api.ovh.com/createApp/>`_ |
| 41 | +- `OVH North-America <https://ca.api.ovh.com/createApp/>`_ |
| 42 | +- `So you Start Europe <https://eu.api.soyoustart.com/createApp/>`_ |
| 43 | +- `So you Start North America <https://ca.api.soyoustart.com/createApp/>`_ |
| 44 | +- `Kimsufi Europe <https://eu.api.kimsufi.com/createApp/>`_ |
| 45 | +- `Kimsufi North America <https://ca.api.kimsufi.com/createApp/>`_ |
| 46 | +- `RunAbove <https://api.runabove.com/createApp/>`_ |
| 47 | + |
| 48 | +Once created, you will obtain an **application key (AK)** and an **application |
| 49 | +secret (AS)**. |
| 50 | + |
| 51 | +2. Authorize your application to access a customer account |
| 52 | +********************************************************** |
| 53 | + |
| 54 | +To allow your application to access a customer account using the API on your |
| 55 | +behalf, you need a **consumer key (CK)**. |
| 56 | + |
| 57 | +Here is a sample code you can use to allow your application to access a |
| 58 | +customer's informations: |
| 59 | + |
| 60 | +.. code:: lua |
| 61 | +
|
| 62 | + local OVH = require 'ovh-api' |
| 63 | +
|
| 64 | + local client = OVH.client( |
| 65 | + 'ovh-eu', |
| 66 | + 'API_KEY', |
| 67 | + 'SECRET_KEY', |
| 68 | + ) |
| 69 | +
|
| 70 | + local data = client:request_consumerkey({ |
| 71 | + { method = 'GET', path = '/*'}, |
| 72 | + { method = 'POST', path = '/*'}, |
| 73 | + { method = 'PUT', path = '/*'} |
| 74 | + }) |
| 75 | +
|
| 76 | + print('Your consumer key is: '..data.consumerKey..'\n') |
| 77 | + print('Visit '..data.validationUrl..' to validate the consumer key\n') |
| 78 | + print('Press enter when validated\n') |
| 79 | + io.read() |
| 80 | + print('Welcome '..client:get('/me')['firstname']) |
| 81 | +
|
| 82 | +
|
| 83 | +Returned ``consumerKey`` should then be kept to avoid re-authenticating your |
| 84 | +end-user on each use. |
| 85 | + |
| 86 | +.. note:: To request full and unlimited access to the API, you may use wildcards: |
| 87 | + |
| 88 | +.. code:: lua |
| 89 | +
|
| 90 | + client:request_consumerkey({ |
| 91 | + { method = 'GET', path = '/*'}, |
| 92 | + { method = 'POST', path = '/*'}, |
| 93 | + { method = 'PUT', path = '/*'}, |
| 94 | + { method = 'DELETE', path = '/*'} |
| 95 | + }) |
| 96 | +
|
| 97 | +List application authorized to access your account |
| 98 | +-------------------------------------------------- |
| 99 | + |
| 100 | +Thanks to the application key / consumer key mechanism, it is possible to |
| 101 | +finely track applications having access to your data and revoke this access. |
| 102 | +This examples lists validated applications. It could easily be adapted to |
| 103 | +manage revocation too. |
| 104 | + |
| 105 | +This example assumes an existing Configuration_ with valid ``API_KEY``, |
| 106 | +``SECRET_KEY`` and ``CONSUMER_KEY``. |
| 107 | + |
| 108 | +.. code:: lua |
| 109 | +
|
| 110 | + local OVH = require '../ovh' |
| 111 | +
|
| 112 | + -- Get configuration from environment variables |
| 113 | + local END_POINT = os.getenv("OVH_END_POINT") |
| 114 | + local API_KEY = os.getenv("OVH_API_KEY") |
| 115 | + local SECRET_KEY = os.getenv("OVH_SECRET_KEY") |
| 116 | + local CONSUMER_KEY = os.getenv("OVH_CONSUMER_KEY") |
| 117 | +
|
| 118 | + local client = OVH.client( |
| 119 | + END_POINT, |
| 120 | + API_KEY, |
| 121 | + SECRET_KEY, |
| 122 | + CONSUMER_KEY |
| 123 | + ) |
| 124 | +
|
| 125 | + local credentials = client:get('/me/api/credential', {status='validated'}) |
| 126 | +
|
| 127 | + local text = 'List of validated credentials: \n' |
| 128 | + for _, credentialId in pairs(credentials) do |
| 129 | + local url = '/me/api/credential/'..credentialId |
| 130 | + credential_data = client:get(url) |
| 131 | + credentail_app = client:get(url..'/application') |
| 132 | +
|
| 133 | + local expiration = credential_data.expiration or '' |
| 134 | + local lastUse = credential_data.expiration or '' |
| 135 | + text = text..'Credential ID: '..credentialId..'\n' |
| 136 | + ..'Name: '..credentail_app.name..'\n' |
| 137 | + ..'Description: '..credentail_app.description..'\n' |
| 138 | + ..'Status: '..credentail_app.status..'\n' |
| 139 | + ..'Creation: '..credential_data.creation..'\n' |
| 140 | + ..'Expiration: '..expiration..'\n' |
| 141 | + ..'Last Use: '..lastUse..'\n\n' |
| 142 | + end |
| 143 | +
|
| 144 | + print(text) |
| 145 | +
|
| 146 | +Supported APIs |
| 147 | +============== |
| 148 | + |
| 149 | +OVH Europe |
| 150 | +---------- |
| 151 | + |
| 152 | +- **Documentation**: https://eu.api.ovh.com/ |
| 153 | +- ** Community support**: [email protected] |
| 154 | +- **Console**: https://eu.api.ovh.com/console |
| 155 | +- **Create application credentials**: https://eu.api.ovh.com/createApp/ |
| 156 | +- **Create script credentials** (all keys at once): https://eu.api.ovh.com/createToken/ |
| 157 | + |
| 158 | +OVH North America |
| 159 | +----------------- |
| 160 | + |
| 161 | +- **Documentation**: https://ca.api.ovh.com/ |
| 162 | +- ** Community support**: [email protected] |
| 163 | +- **Console**: https://ca.api.ovh.com/console |
| 164 | +- **Create application credentials**: https://ca.api.ovh.com/createApp/ |
| 165 | +- **Create script credentials** (all keys at once): https://ca.api.ovh.com/createToken/ |
| 166 | + |
| 167 | +So you Start Europe |
| 168 | +------------------- |
| 169 | + |
| 170 | +- **Documentation**: https://eu.api.soyoustart.com/ |
| 171 | +- ** Community support**: [email protected] |
| 172 | +- **Console**: https://eu.api.soyoustart.com/console/ |
| 173 | +- **Create application credentials**: https://eu.api.soyoustart.com/createApp/ |
| 174 | +- **Create script credentials** (all keys at once): https://eu.api.soyoustart.com/createToken/ |
| 175 | + |
| 176 | +So you Start North America |
| 177 | +-------------------------- |
| 178 | + |
| 179 | +- **Documentation**: https://ca.api.soyoustart.com/ |
| 180 | +- ** Community support**: [email protected] |
| 181 | +- **Console**: https://ca.api.soyoustart.com/console/ |
| 182 | +- **Create application credentials**: https://ca.api.soyoustart.com/createApp/ |
| 183 | +- **Create script credentials** (all keys at once): https://ca.api.soyoustart.com/createToken/ |
| 184 | + |
| 185 | +Kimsufi Europe |
| 186 | +-------------- |
| 187 | + |
| 188 | +- **Documentation**: https://eu.api.kimsufi.com/ |
| 189 | +- ** Community support**: [email protected] |
| 190 | +- **Console**: https://eu.api.kimsufi.com/console/ |
| 191 | +- **Create application credentials**: https://eu.api.kimsufi.com/createApp/ |
| 192 | +- **Create script credentials** (all keys at once): https://eu.api.kimsufi.com/createToken/ |
| 193 | + |
| 194 | +Kimsufi North America |
| 195 | +--------------------- |
| 196 | + |
| 197 | +- **Documentation**: https://ca.api.kimsufi.com/ |
| 198 | +- ** Community support**: [email protected] |
| 199 | +- **Console**: https://ca.api.kimsufi.com/console/ |
| 200 | +- **Create application credentials**: https://ca.api.kimsufi.com/createApp/ |
| 201 | +- **Create script credentials** (all keys at once): https://ca.api.kimsufi.com/createToken/ |
| 202 | + |
| 203 | +Runabove |
| 204 | +-------- |
| 205 | + |
| 206 | +- **Community support**: https://community.runabove.com/ |
| 207 | +- **Console**: https://api.runabove.com/console/ |
| 208 | +- **Create application credentials**: https://api.runabove.com/createApp/ |
| 209 | +- **High level SDK**: https://github.com/runabove/python-runabove |
0 commit comments