Giter Club home page Giter Club logo

lua-ovh-api's Introduction

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

lua-ovh-api's People

Contributors

yagop avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.