1
0
mirror of https://github.com/ovh/php-ovh.git synced 2023-11-05 03:20:26 +01:00

Adding Github actions, codecov config, updating tests accordingly and re-organize README file

Signed-off-by: Germain Carré git@germain.sh
This commit is contained in:
Germain Carré 2022-08-03 20:28:35 +02:00
parent cbb47888f5
commit 7d606bdcc1
13 changed files with 447 additions and 421 deletions

97
.github/workflows/ci.yaml vendored Normal file
View File

@ -0,0 +1,97 @@
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
name: "CI"
on:
pull_request:
push:
branches:
- "main"
- "master"
env:
COMPOSER_ROOT_VERSION: "1.99.99"
APP_KEY: ${{ secrets.OVH_TESTS_APP_KEY }}
APP_SECRET: ${{ secrets.OVH_TESTS_APP_SECRET }}
CONSUMER: ${{ secrets.OVH_TESTS_CONSUMER_KEY }}
ENDPOINT: ${{ secrets.OVH_TESTS_ENDPOINT }}
jobs:
lint:
name: "Lint"
runs-on: "ubuntu-latest"
strategy:
fail-fast: false
matrix:
php-version: [ '7.4', '8.0', '8.1', '8.2' ]
steps:
- uses: "actions/checkout@v2"
- uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
coverage: "none"
ini-values: "memory_limit=-1, zend.assertions=1, error_reporting=-1, display_errors=On"
tools: "composer:v2"
- uses: "ramsey/composer-install@v2"
- name: "Lint the PHP source code"
run: "composer parallel-lint"
coding-standards:
name: "Coding Standards"
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v2"
- uses: "shivammathur/setup-php@v2"
with:
php-version: "latest"
coverage: "none"
ini-values: "memory_limit=-1"
tools: "composer:v2"
- uses: "ramsey/composer-install@v2"
- name: "Check coding standards"
run: "composer phpcs"
coverage:
name: "Coverage"
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v2"
- uses: "shivammathur/setup-php@v2"
with:
php-version: "latest"
coverage: "pcov"
ini-values: "memory_limit=-1, zend.assertions=1, error_reporting=-1, display_errors=On"
tools: "composer"
- name: "Prepare for tests"
run: "mkdir -p build/logs"
- uses: "ramsey/composer-install@v2"
- name: "Run unit tests"
run: "composer phpunit"
- name: "Publish coverage report to Codecov"
uses: "codecov/codecov-action@v2"
with:
files: ./build/logs/clover.xml
unit-tests:
needs: coverage
name: "Unit Tests"
runs-on: "ubuntu-latest"
strategy:
max-parallel: 1
fail-fast: false
matrix:
php-version: [ '7.4', '8.0', '8.1', '8.2' ]
steps:
- uses: "actions/checkout@v2"
- uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
coverage: "none"
ini-values: "memory_limit=-1, zend.assertions=1, error_reporting=-1, display_errors=On"
tools: "composer"
- name: "Prepare for tests"
run: "mkdir -p build/logs"
- uses: "ramsey/composer-install@v2"
- name: "Run unit tests"
run: "composer phpunit"

4
.gitignore vendored
View File

@ -1,7 +1,9 @@
node_modules node_modules
vendor /build
/vendor
composer.lock composer.lock
composer.phar composer.phar
/phpunit.xml /phpunit.xml
/build.properties /build.properties
/docs /docs
.phpunit.*.cache

View File

@ -1,17 +0,0 @@
addons:
apt:
packages:
- libcurl4-openssl-dev
language: php
dist: focal
php:
- 8.1.0
- 8.0
- 7.4
before_script:
- composer self-update
- composer install
script: vendor/bin/phpunit tests/ApiTest.php

469
README.md
View File

@ -1,140 +1,62 @@
# OVHcloud APIs lightweight PHP wrapper
[![PHP Wrapper for OVH APIs](https://github.com/ovh/php-ovh/blob/master/img/logo.png)](https://packagist.org/packages/ovh/ovh) [![PHP Wrapper for OVH APIs](https://github.com/ovh/php-ovh/blob/master/img/logo.png)](https://packagist.org/packages/ovh/ovh)
This PHP package is a lightweight wrapper for OVH APIs. That's the easiest way to use OVH.com APIs in your PHP applications. [![Source Code](https://img.shields.io/badge/source-ovh/php--ovh-blue.svg?style=flat-square)](https://github.com/ovh/php-ovh)
[![Build Status](https://img.shields.io/github/actions/workflow/status/ovh/php-ovh/ci.yaml?label=CI&logo=github&style=flat-square)](https://github.com/ovh/php-ovh/actions?query=workflow%3ACI)
[![Codecov Code Coverage](https://img.shields.io/codecov/c/gh/ovh/php-ovh?label=codecov&logo=codecov&style=flat-square)](https://codecov.io/gh/ovh/php-ovh)
[![Total Downloads](https://img.shields.io/packagist/dt/ovh/ovh.svg?style=flat-square)](https://packagist.org/packages/ovh/ovh)
[![Build Status](https://travis-ci.org/ovh/php-ovh.svg)](https://travis-ci.org/ovh/php-ovh) This PHP package is a lightweight wrapper for OVHcloud APIs.
[![HHVM Status](https://img.shields.io/hhvm/ovh/ovh.svg)](http://hhvm.h4cc.de/package/ovh/ovh)
```php The easiest way to use OVHcloud APIs in your PHP applications.
<?php
/**
* # Instantiate. Visit https://api.ovh.com/createToken/index.cgi?GET=/me
* to get your credentials
*/
require __DIR__ . '/vendor/autoload.php';
use \Ovh\Api;
$ovh = new Api( $applicationKey, Compatible with PHP 7.4, 8.0, 8.1, 8.2.
$applicationSecret,
$endpoint,
$consumer_key);
echo "Welcome " . $ovh->get('/me')['firstname'];
?>
```
Quickstart ## Installation
----------
To download this wrapper and integrate it inside your PHP application, you can use [Composer](https://getcomposer.org). Install this wrapper and integrate it inside your PHP application with [Composer](https://getcomposer.org) :
Quick integration with the following command:
composer require ovh/ovh composer require ovh/ovh
Or add the repository in your **composer.json** file or, if you don't already have ## Basic usage
this file, create it at the root of your project with this content:
```json
{
"name": "Example Application",
"description": "This is an example of OVH APIs wrapper usage",
"require": {
"ovh/ovh": "dev-master"
}
}
```
Then, you can install OVH APIs wrapper and dependencies with:
php composer.phar install
This will install ``ovh/ovh`` to ``./vendor``, along with other dependencies
including ``autoload.php``.
OVH cookbook
------------
Do you want to use OVH APIs? Maybe the script you want is already written in the [example part](examples/README.md) of this repository!
How to login as a user?
-----------------------
To communicate with APIs, the SDK uses a token on each request to identify the
user. This token is called *Consumer Key*. To have a validated *Consumer Key*,
you need to redirect your user on specific authentication page. Once the user has
logged in, the token is validated and user will be redirected on __$redirection__ url.
```php ```php
<?php <?php
require __DIR__ . '/vendor/autoload.php'; require __DIR__ . '/vendor/autoload.php';
use \Ovh\Api; use \Ovh\Api;
session_start(); // Api credentials can be retreived from the urls specified in the "Supported endpoints" section below.
$ovh = new Api($applicationKey,
// Informations about your application
$applicationKey = "your_app_key";
$applicationSecret = "your_app_secret";
$redirection = "http://your_url.ovh";
// Information about API and rights asked
$endpoint = 'ovh-eu';
$rights = array( (object) [
'method' => 'GET',
'path' => '/me*'
]);
// Get credentials
$conn = new Api($applicationKey, $applicationSecret, $endpoint);
$credentials = $conn->requestCredentials($rights, $redirection);
// Save consumer key and redirect to authentication page
$_SESSION['consumer_key'] = $credentials["consumerKey"];
header('location: '. $credentials["validationUrl"]);
...
?>
```
How to use OVH API to enable network burst on SBG1 servers?
-----------------------------------------------------------
```php
<?php
require __DIR__ . '/vendor/autoload.php';
use \Ovh\Api;
// Informations about your application
$applicationKey = "your_app_key";
$applicationSecret = "your_app_secret";
$consumer_key = "your_consumer_key";
// Information about API and rights asked
$endpoint = 'ovh-eu';
// Get servers list
$conn = new Api( $applicationKey,
$applicationSecret, $applicationSecret,
$endpoint, $endpoint,
$consumer_key); $consumerKey);
$servers = $conn->get('/dedicated/server/'); echo 'Welcome '.$ovh->get('/me')['firstname'];
foreach ($servers as $server) {
// Search servers inside SBG1
$details = $conn->get('/dedicated/server/'. $server);
if ($details['datacenter'] == 'sbg1') {
// Activate burst on server
$content = (object) array('status' => "active");
$conn->put('/dedicated/server/'. $server . '/burst', $content);
echo "We burst " . $server;
}
}
?>
``` ```
How to customize HTTP client configuration?
------------------------------------------- ## Advanced usage
### Handle exceptions
Under the hood, ```php-ovh``` uses [Guzzle](http://docs.guzzlephp.org/en/latest/quickstart.html) by default to issue API requests.
If everything goes well, it will return the response directly as shown in the examples above.
If there is an error like a missing endpoint or object (404), an authentication or authorization error (401 or 403) or a parameter error, the Guzzle will raise a ``GuzzleHttp\Exception\ClientException`` exception. For server-side errors (5xx), it will raise a ``GuzzleHttp\Exception\ServerException`` exception.
You can get the error details with a code like:
```php
try {
echo "Welcome " . $ovh->get('/me')['firstname'];
} catch (GuzzleHttp\Exception\ClientException $e) {
$response = $e->getResponse();
$responseBodyAsString = $response->getBody()->getContents();
echo $responseBodyAsString;
}
```
### Customize HTTP client configuration
You can inject your own HTTP client with your specific configuration. For instance, you can edit user-agent and timeout for all your requests You can inject your own HTTP client with your specific configuration. For instance, you can edit user-agent and timeout for all your requests
@ -144,170 +66,205 @@ require __DIR__ . '/vendor/autoload.php';
use \Ovh\Api; use \Ovh\Api;
use GuzzleHttp\Client; use GuzzleHttp\Client;
// Informations about your application // Instantiate a custom Guzzle HTTP client and tweak it
$applicationKey = "your_app_key";
$applicationSecret = "your_app_secret";
$consumer_key = "your_consumer_key";
// Information about API and rights asked
$endpoint = 'ovh-eu';
$client = new Client(); $client = new Client();
$client->setDefaultOption('timeout', 1); $client->setDefaultOption('timeout', 1);
$client->setDefaultOption('headers', array('User-Agent' => 'api_client') ); $client->setDefaultOption('headers', ['User-Agent' => 'api_client']);
// Get servers list
$conn = new Api( $applicationKey,
$applicationSecret,
$endpoint,
$consumer_key,
$client);
$webHosting = $conn->get('/hosting/web/');
foreach ($webHosting as $webHosting) {
echo "One of our web hosting: " . $webHosting . "\n";
}
?>
```
How to print API error details?
-------------------------------
Under the hood, ```php-ovh``` uses [GuzzlePHP 6](http://docs.guzzlephp.org/en/latest/quickstart.html) by default to issue API requests. If everything goes well, it will return the response directly as shown in the examples above. If there is an error like a missing endpoint or object (404), an authentication or authorization error (401 or 403) or a parameter error, the Guzzle will raise a ``GuzzleHttp\Exception\ClientException`` exception. For server-side errors (5xx), it will raise a ``GuzzleHttp\Exception\ServerException`` exception.
You can get the error details with a code like:
```php
<?php
/**
* # Instantiate. Visit https://api.ovh.com/createToken/index.cgi?GET=/me
* to get your credentials
*/
require __DIR__ . '/vendor/autoload.php';
use \Ovh\Api;
// Api credentials can be retreived from the urls specified in the "Supported endpoints" section below.
// Inject the custom HTTP client as the 5th argument of the constructor
$ovh = new Api($applicationKey, $ovh = new Api($applicationKey,
$applicationSecret, $applicationSecret,
$endpoint, $endpoint,
$consumer_key); $consumerKey,
$client);
try { echo 'Welcome '.$ovh->get('/me')['firstname'];
echo "Welcome " . $ovh->get('/me')['firstname'];
} catch (GuzzleHttp\Exception\ClientException $e) {
$response = $e->getResponse();
$responseBodyAsString = $response->getBody()->getContents();
echo $responseBodyAsString;
}
?>
``` ```
### Authorization flow
How to build the documentation? This flow will allow you to request consumerKey from an OVHcloud account owner.
------------------------------- After allowing access to his account, he will be redirected to your application.
Documentation is based on phpdocumentor. To install it with other quality tools, See "OVHcloud API authentication" section below for more information about the authorization flow.
you can install local npm project in a clone a project
git clone https://github.com/ovh/php-ovh.git
cd php-ovh
php composer.phar install
```php
use \Ovh\Api;
session_start();
// Api credentials can be retreived from the urls specified in the "Supported endpoints" section below.
$ovh = new Api($applicationKey,
$applicationSecret,
$endpoint);
// Specify the list of API routes you want to request
$rights = [
[ 'method' => 'GET', 'path' => '/me*' ],
];
// After allowing your application access, the customer will be redirected to this URL.
$redirectUrl = 'https://your_application_redirect_url'
$credentials = $conn->requestCredentials($rights, $redirectUrl);
// Save consumer key and redirect to authentication page
$_SESSION['consumerKey'] = $credentials['consumerKey'];
header('location: '. $credentials['validationUrl']);
// After successful redirect, the consumerKey in the session will be activated and you will be able to use it to make API requests like in the "Basic usage" section above.
```
### Code sample : Enable network burst on GRA1 dedicated servers
Here is a more complex example of how to use the wrapper to enable network burst on GRA1 dedicated servers.
```php
<?php
require __DIR__ . '/vendor/autoload.php';
use \Ovh\Api;
// Api credentials can be retreived from the urls specified in the "Supported endpoints" section below.
$ovh = new Api($applicationKey,
$applicationSecret,
$endpoint,
$consumerKey);
// Load the list of dedicated servers
$servers = $conn->get('/dedicated/server/');
foreach ($servers as $server) {
// Load the server details
$details = $conn->get('/dedicated/server/'.$server);
// Filter servers only inside GRA1
if ($details['datacenter'] == 'gra1') {
// Activate burst on server
$content = ['status' => 'active'];
$conn->put('/dedicated/server/'.$server.'/burst', $content);
echo 'Burst enabled on '.$server;
}
}
```
### More code samples
Do you want to use OVH APIs? Maybe the script you want is already written in the [example part](examples/README.md) of this repository!
## OVHcloud API authentication
To use the OVHcloud APIs you need three credentials :
* An application key
* An application secret
* A consumer key
The application key and secret are not granting access to a specific account and are unique to identify your application.
The consumer key is used to grant access to a specific OVHcloud account to a specified application.
They can be created separately if your application is intended to be used by multiple accounts (your app will need to implement an authorization flow).
In the authorization flow, the customer will be prompted to allow access to his account to your application, then he will be redirected to your application.
They can also be created together if your application is intended to use only your own OVHcloud account.
## Supported endpoints
### OVHcloud Europe
* ```$endpoint = 'ovh-eu';```
* Documentation: <https://eu.api.ovh.com/>
* Console: <https://eu.api.ovh.com/console>
* Create application credentials (generate only application credentials, your app will need to implement an authorization flow): <https://eu.api.ovh.com/createApp/>
* Create account credentials (all keys at once for your own account only): <https://eu.api.ovh.com/createToken/>
* Community support: api-subscribe@ml.ovh.net
### OVHcloud US
* ```$endpoint = 'ovh-us';```
* Documentation: <https://api.us.ovhcloud.com/>
* Console: <https://api.us.ovhcloud.com/console>
* Create application credentials (generate only application credentials, your app will need to implement an authorization flow): <https://api.us.ovhcloud.com/createApp/>
* Create account credentials (all keys at once for your own account only): <https://api.us.ovhcloud.com/createToken/>
### OVHcloud North America / Canada
* ```$endpoint = 'ovh-ca';```
* Documentation: <https://ca.api.ovh.com/>
* Console: <https://ca.api.ovh.com/console>
* Create application credentials (generate only application credentials, your app will need to implement an authorization flow): <https://ca.api.ovh.com/createApp/>
* Create account credentials (all keys at once for your own account only): <https://ca.api.ovh.com/createToken/>
* Community support: api-subscribe@ml.ovh.net
### So you Start Europe
* ```$endpoint = 'soyoustart-eu';```
* Documentation: <https://eu.api.soyoustart.com/>
* Console: <https://eu.api.soyoustart.com/console/>
* Create application credentials (generate only application credentials, your app will need to implement an authorization flow): <https://eu.api.soyoustart.com/createApp/>
* Create account credentials (all keys at once for your own account only): <https://eu.api.soyoustart.com/createToken/>
* Community support: api-subscribe@ml.ovh.net
### So you Start North America
* ```$endpoint = 'soyoustart-ca';```
* Documentation: <https://ca.api.soyoustart.com/>
* Console: <https://ca.api.soyoustart.com/console/>
* Create application credentials (generate only application credentials, your app will need to implement an authorization flow): <https://ca.api.soyoustart.com/createApp/>
* Create account credentials (all keys at once for your own account only): <https://ca.api.soyoustart.com/createToken/>
* Community support: api-subscribe@ml.ovh.net
### Kimsufi Europe
* ```$endpoint = 'kimsufi-eu';```
* Documentation: <https://eu.api.kimsufi.com/>
* Console: <https://eu.api.kimsufi.com/console/>
* Create application credentials (generate only application credentials, your app will need to implement an authorization flow): <https://eu.api.kimsufi.com/createApp/>
* Create account credentials (all keys at once for your own account only): <https://eu.api.kimsufi.com/createToken/>
* Community support: api-subscribe@ml.ovh.net
### Kimsufi North America
* ```$endpoint = 'kimsufi-ca';```
* Documentation: <https://ca.api.kimsufi.com/>
* Console: <https://ca.api.kimsufi.com/console/>
* Create application credentials (generate only application credentials, your app will need to implement an authorization flow): <https://ca.api.kimsufi.com/createApp/>
* Create account credentials (all keys at once for your own account only): <https://ca.api.kimsufi.com/createToken/>
* Community support: api-subscribe@ml.ovh.net
## Building documentation
Documentation is based on phpdocumentor and inclued in the project.
To generate documentation, it's possible to use directly: To generate documentation, it's possible to use directly:
vendor/bin/phing phpdocs composer phpdoc
Documentation is available in docs/ directory. Documentation is available in docs/ directory.
How to run tests? ## Code check / Linting
-----------------
Tests are based on phpunit. To install it with other quality tools, you can install Code check is based on PHP CodeSniffer and inclued in the project.
local npm project in a clone a project To check code, it's possible to use directly:
git https://github.com/ovh/php-ovh.git composer phpcs
cd php-ovh
php composer.phar install
vendor/bin/phpunit tests/ApiTest.php
Code linting is based on PHP Code Beautifier and Fixer and inclued in the project.
To lint code, it's possible to use directly:
composer phpcbf
## Testing
Tests are based on phpunit and inclued in the project.
To run functionals tests, you need to provide valid API credentials, that you can provide them via environment: To run functionals tests, you need to provide valid API credentials, that you can provide them via environment:
APP_KEY=xxx APP_SECRET=xxx CONSUMER=xxx ENDPOINT=xxx vendor/bin/phpunit tests/ApiFunctionalTest.php APP_KEY=xxx APP_SECRET=xxx CONSUMER=xxx ENDPOINT=xxx composer phpunit
Supported APIs ## Contributing
--------------
## OVH Europe Please see [CONTRIBUTING](https://github.com/ovh/php-ovh/blob/master/CONTRIBUTING.rst) for details.
* ```$endpoint = 'ovh-eu';``` ## Credits
* Documentation: https://eu.api.ovh.com/
* Community support: api-subscribe@ml.ovh.net
* Console: https://eu.api.ovh.com/console
* Create application credentials: https://eu.api.ovh.com/createApp/
* Create script credentials (all keys at once): https://eu.api.ovh.com/createToken/
## OVH US [All Contributors from this repo](https://github.com/ovh/php-ovh/contributors)
* ```$endpoint = 'ovh-us';``` ## License
* Documentation: https://api.us.ovhcloud.com/
* Console: https://api.us.ovhcloud.com/console
* Create application credentials: https://api.us.ovhcloud.com/createApp/
* Create script credentials (all keys at once): https://api.us.ovhcloud.com/createToken/
## OVH North America
* ```$endpoint = 'ovh-ca';```
* Documentation: https://ca.api.ovh.com/
* Community support: api-subscribe@ml.ovh.net
* Console: https://ca.api.ovh.com/console
* Create application credentials: https://ca.api.ovh.com/createApp/
* Create script credentials (all keys at once): https://ca.api.ovh.com/createToken/
## So you Start Europe
* ```$endpoint = 'soyoustart-eu';```
* Documentation: https://eu.api.soyoustart.com/
* Community support: api-subscribe@ml.ovh.net
* Console: https://eu.api.soyoustart.com/console/
* Create application credentials: https://eu.api.soyoustart.com/createApp/
* Create script credentials (all keys at once): https://eu.api.soyoustart.com/createToken/
## So you Start North America
* ```$endpoint = 'soyoustart-ca';```
* Documentation: https://ca.api.soyoustart.com/
* Community support: api-subscribe@ml.ovh.net
* Console: https://ca.api.soyoustart.com/console/
* Create application credentials: https://ca.api.soyoustart.com/createApp/
* Create script credentials (all keys at once): https://ca.api.soyoustart.com/createToken/
## Kimsufi Europe
* ```$endpoint = 'kimsufi-eu';```
* Documentation: https://eu.api.kimsufi.com/
* Community support: api-subscribe@ml.ovh.net
* Console: https://eu.api.kimsufi.com/console/
* Create application credentials: https://eu.api.kimsufi.com/createApp/
* Create script credentials (all keys at once): https://eu.api.kimsufi.com/createToken/
## Kimsufi North America
* ```$endpoint = 'kimsufi-ca';```
* Documentation: https://ca.api.kimsufi.com/
* Community support: api-subscribe@ml.ovh.net
* Console: https://ca.api.kimsufi.com/console/
* Create application credentials: https://ca.api.kimsufi.com/createApp/
* Create script credentials (all keys at once): https://ca.api.kimsufi.com/createToken/
## Runabove
* ```$endpoint = 'runabove-ca';```
* Documentation: https://community.runabove.com/kb/en/instances/how-to-use-runabove-api.html
* Community support: https://community.runabove.com
* Console: https://api.runabove.com/console/
* Create application credentials: https://api.runabove.com/createApp/
## Related links
* Contribute: https://github.com/ovh/php-ovh
* Report bugs: https://github.com/ovh/php-ovh/issues
(Modified) BSD license. Please see [LICENSE](https://github.com/ovh/php-ovh/blob/master/LICENSE) for more information.

114
build.xml
View File

@ -1,114 +0,0 @@
<?xml version="1.0"?>
<project name="ovh/ovh" default="all">
<property name="base" value="${project.basedir}/" />
<property environment="env" />
<if>
<available file="${base}build.properties" property="" />
<then>
<property file="${base}build.properties" override="true" />
</then>
</if>
<!--##########################################################################################################-->
<target name="help">
<echo message="${phing.project.name} on [${git.branch}]" />
<echo message=" Available commands are:" />
<echo message=" test -> Run unit tests" />
<echo message=" clean -> Clean current environment" />
<echo message=" server -> Launch PHP built-in server" />
<echo message=" watch -> Run precommit task on every file changed" />
<echo message=" precommit -> Source code validation before commit" />
<echo message=" Specific tools tasks:" />
<echo message=" phpcs -> Run PHP Code Sniffer" />
<echo message=" phplint -> Run PHP Lint" />
<echo message=" phpdocs -> Run PHP Documentor" />
<echo message=" phpunit -> Run PHPUnit" />
</target>
<!--##########################################################################################################-->
<target name="test" description="Run unit tests">
<phingcall target="phpunit" />
</target>
<target name="clean" description="Clean current environment">
<delete dir="docs" includeemptydirs="true" verbose="true" failonerror="true" />
</target>
<target name="precommit" description="Source code validation before commit">
<phingcall target="phplint" />
<phingcall target="phpcs" />
<phingcall target="phpunit" />
</target>
<target name="all" description="Make a full integration check">
<phingcall target="phplint" />
<phingcall target="phpcs" />
<phingcall target="phpunit" />
<phingcall target="phpdocs" />
</target>
<!--##########################################################################################################-->
<target name="phpcs" description="Run PHP Code Sniffer">
<phpcodesniffer
standard="PSR2"
format="summary"
>
<fileset dir=".">
<include name="src/**/*.php"/>
<include name="test/**/*.php"/>
</fileset>
</phpcodesniffer>
</target>
<target name="phpcbf" description="Run PHP Code Sniffer">
<exec command="vendor/bin/phpcbf --standard=PSR2 src" logoutput="true" />
</target>
<target name="phplint" description="Run PHP Lint">
<phplint deprecatedAsError="true">
<fileset dir=".">
<include name="src/**/*.php"/>
<include name="test/**/*.php"/>
</fileset>
</phplint>
</target>
<target name="phpdocs" description="Run PHP Documentor" depends="clean">
<if>
<not><available file="docs" /></not>
<then>
<mkdir dir="docs" />
</then>
</if>
<phpdoc2 destdir="docs">
<fileset dir="src">
<include name="**/*.php" />
</fileset>
</phpdoc2>
</target>
<target name="phpunit" description="Run PHPUnit">
<if>
<and>
<isset property="only.units" />
<equals arg1="${only.units}" arg2="true" />
</and>
<then>
<fileset dir="tests" id="tests">
<include name="ApiTest.php"/>
</fileset>
</then>
<else>
<fileset dir="tests" id="tests">
<include name="**/*.php"/>
</fileset>
</else>
</if>
<phpunit
haltonfailure="true"
haltonerror="true"
bootstrap="tests/bootstrap.php"
printsummary="true"
>
<formatter type="plain" usefile="false"/>
<batchtest>
<fileset refid="tests" />
</batchtest>
</phpunit>
</target>
<!--##########################################################################################################-->
</project>

29
codecov.yml Normal file
View File

@ -0,0 +1,29 @@
codecov:
require_ci_to_pass: yes
coverage:
precision: 2
round: down
range: "70...100"
status:
project:
default:
target: auto
threshold: 0%
patch:
default:
target: auto
threshold: 0%
parsers:
gcov:
branch_detection:
conditional: yes
loop: yes
method: no
macro: no
comment:
layout: "reach,diff,flags,tree"
behavior: default
require_changes: false

View File

@ -1,20 +1,45 @@
{ {
"name": "ovh/ovh", "name": "ovh/ovh",
"description": "Wrapper for OVH APIs", "description": "Wrapper for OVHcloud APIs",
"license": "BSD-3-Clause", "license": "BSD-3-Clause",
"config": {
"sort-packages": true,
"allow-plugins": {
"phpdocumentor/shim": true
}
},
"keywords": [
"api",
"client",
"authorization",
"authorisation",
"ovh",
"ovhcloud"
],
"require": { "require": {
"php": ">=7.4", "php": ">=7.4",
"guzzlehttp/guzzle": "^6.0||^7.0", "guzzlehttp/guzzle": "^6.0||^7.0",
"ext-json": "*" "ext-json": "*"
}, },
"require-dev": {
"php-parallel-lint/php-parallel-lint": "^1.3.1",
"phpdocumentor/shim": "^3",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.6"
},
"autoload": { "autoload": {
"psr-4": {"Ovh\\": "src/"} "psr-4": {"Ovh\\": "src/"}
}, },
"require-dev": { "autoload-dev": {
"phpunit/phpunit": "^9.5", "psr-4": {
"phpdocumentor/phpdocumentor": "v3.0.0", "Ovh\\tests\\": "test/"
"squizlabs/php_codesniffer": "^3.5", }
"phpdocumentor/graphviz": "^2.0@dev", },
"symfony/flex": "^1.11" "scripts": {
"phpdoc": "vendor/bin/phpdoc",
"phpcs": "vendor/bin/phpcs -sp --colors",
"phpcbf": "vendor/bin/phpcbf -sp",
"parallel-lint": "vendor/bin/parallel-lint src tests",
"phpunit": "vendor/bin/phpunit --colors=always"
} }
} }

12
phpcs.xml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0"?>
<ruleset name="PHP_CodeSniffer">
<rule ref="PSR2" />
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="180"/>
</properties>
</rule>
<file>src</file>
<file>tests</file>
<arg name="encoding" value="utf-8"/>
</ruleset>

19
phpdoc.dist.xml Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
<phpdocumentor
configVersion="3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://www.phpdoc.org"
xsi:noNamespaceSchemaLocation="https://docs.phpdoc.org/latest/phpdoc.xsd"
>
<paths>
<output>docs</output>
<cache>build/phpdoc-cache</cache>
</paths>
<version number="3.0.0">
<api>
<source dsn=".">
<path>src</path>
</source>
</api>
</version>
</phpdocumentor>

View File

@ -1,19 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="tests/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"> <phpunit
<coverage> bootstrap="./vendor/autoload.php"
<include> colors="true"
<directory>src</directory> convertErrorsToExceptions="true"
</include> convertWarningsToExceptions="true"
</coverage> convertNoticesToExceptions="true"
convertDeprecationsToExceptions="true"
>
<testsuites> <testsuites>
<testsuite name="OVH APIs wrapper"> <testsuite name="all">
<directory>tests</directory> <directory>./tests</directory>
</testsuite> </testsuite>
</testsuites> </testsuites>
<php>
<env name="ENDPOINT" value=""/> <coverage>
<env name="APP_KEY" value=""/> <include>
<env name="APP_SECRET" value=""/> <directory suffix=".php">src/</directory>
<env name="CONSUMER" value=""/> </include>
</php>
<report>
<clover outputFile="build/logs/clover.xml" />
<html outputDirectory="build/coverage" />
<text outputFile="php://stdout" />
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
</phpunit> </phpunit>

View File

@ -198,8 +198,10 @@ class ApiFunctionalTest extends TestCase
{ {
$result = $this->api->get('/me/accessRestriction/ip'); $result = $this->api->get('/me/accessRestriction/ip');
$restrictionId = array_pop($result); foreach ($result as $restrictionId) {
$restriction = $this->api->get('/me/accessRestriction/ip/' . $restrictionId);
if (in_array($restriction["ip"], [$this->rangeIP, $this->alternativeRangeIP])) {
$this->assertNull( $this->assertNull(
$this->api->put('/me/accessRestriction/ip/' . $restrictionId, ['rule' => 'accept', 'warning' => true]) $this->api->put('/me/accessRestriction/ip/' . $restrictionId, ['rule' => 'accept', 'warning' => true])
); );
@ -207,6 +209,8 @@ class ApiFunctionalTest extends TestCase
$restriction = $this->api->get('/me/accessRestriction/ip/' . $restrictionId); $restriction = $this->api->get('/me/accessRestriction/ip/' . $restrictionId);
$this->assertEquals('accept', $restriction['rule']); $this->assertEquals('accept', $restriction['rule']);
} }
}
}
/** /**
* Test if delete request on /me * Test if delete request on /me
@ -220,7 +224,6 @@ class ApiFunctionalTest extends TestCase
if (in_array($restriction["ip"], [$this->rangeIP, $this->alternativeRangeIP])) { if (in_array($restriction["ip"], [$this->rangeIP, $this->alternativeRangeIP])) {
$result = $this->api->delete('/me/accessRestriction/ip/' . $restrictionId); $result = $this->api->delete('/me/accessRestriction/ip/' . $restrictionId);
$this->assertNull($result); $this->assertNull($result);
break;
} }
} }
} }
@ -232,7 +235,8 @@ class ApiFunctionalTest extends TestCase
{ {
$api = new Api($this->application_key, $this->application_secret, $this->endpoint, null, $this->client); $api = new Api($this->application_key, $this->application_secret, $this->endpoint, null, $this->client);
$invoker = self::getPrivateMethod('rawCall'); $invoker = self::getPrivateMethod('rawCall');
$invoker->invokeArgs($api, ['GET', '/xdsl/incidents']); $result = $invoker->invokeArgs($api, ['GET', '/xdsl/incidents']);
$this->assertIsObject($result);
} }
/** /**
@ -250,7 +254,8 @@ class ApiFunctionalTest extends TestCase
*/ */
public function testApiGetWithQueryString() public function testApiGetWithQueryString()
{ {
$this->api->get('/me/api/credential', ['status' => 'pendingValidation']); $result = $this->api->get('/me/api/credential', ['status' => 'pendingValidation']);
$this->assertIsArray($result);
} }
/** /**
@ -258,7 +263,8 @@ class ApiFunctionalTest extends TestCase
*/ */
public function testApiGetWithoutAuthentication() public function testApiGetWithoutAuthentication()
{ {
$api = new Api(NULL,NULL, $this->endpoint, null, $this->client); $api = new Api(null, null, $this->endpoint, null, $this->client);
$api->get('/hosting/web/moduleList',null,null,false); $result = $api->get('/hosting/web/moduleList', null, null, false);
$this->assertIsArray($result);
} }
} }

View File

@ -156,7 +156,7 @@ class ApiTest extends TestCase
->withHeader('Content-Type', 'application/json; charset=utf-8') ->withHeader('Content-Type', 'application/json; charset=utf-8')
->withBody($body); ->withBody($body);
})); }));
$api = new Api(NULL, NULL, $this->endpoint, $this->consumer_key, $this->client); $api = new Api(null, null, $this->endpoint, $this->consumer_key, $this->client);
$api->get('/unauthcall', null, null, false); $api->get('/unauthcall', null, null, false);
$this->assertEquals(1, 1); $this->assertEquals(1, 1);
} }
@ -563,5 +563,4 @@ class ApiTest extends TestCase
$api = new Api($this->application_key, $this->application_secret, $this->endpoint, $this->consumer_key, $this->client); $api = new Api($this->application_key, $this->application_secret, $this->endpoint, $this->consumer_key, $this->client);
$api->requestCredentials([]); $api->requestCredentials([]);
} }
} }

View File

@ -26,4 +26,3 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
require __DIR__ . '/../vendor/autoload.php'; require __DIR__ . '/../vendor/autoload.php';