Skip to content

Commit

Permalink
Merge pull request #6 from paysera/remove_config_whitelist
Browse files Browse the repository at this point in the history
added ability to pass any configuration to the client without whitelisting
  • Loading branch information
Romas Navašinskas authored Jun 11, 2020
2 parents dcdf40a + e383041 commit 6801176
Show file tree
Hide file tree
Showing 24 changed files with 76 additions and 20 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## 2.4.0
### Added
- Added ability to pass any configuration without whitelisting to the client
### Removed
- Removed `ConfigHandler::appendConfiguration`, instead options are appended with configurations in `ClientFactoryAbstract::createApiClient:65`

## 2.3.1
### Added
- If request body contains JSON, `Content-Type: application/json` will be set
Expand Down
3 changes: 3 additions & 0 deletions src/Authentication/AuthenticationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Paysera\Component\RestClientCommon\Exception\AuthenticationConfigurationException;
use Paysera\Component\RestClientCommon\Middleware\Authentication\AuthenticationMiddlewareInterface;

/**
* @internal
*/
class AuthenticationProvider
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/Client/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

/**
* @api
*/
class ApiClient
{
private $client;
Expand Down
3 changes: 3 additions & 0 deletions src/Decoder/ResponseBodyDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use Paysera\Component\RestClientCommon\Exception\UnsupportedContentTypeException;
use Psr\Http\Message\ResponseInterface;

/**
* @internal
*/
class ResponseBodyDecoder
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/Decoder/ResponseDecoder/JsonResponseDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Psr\Http\Message\ResponseInterface;

/**
* @internal
*/
class JsonResponseDecoder implements ResponseDecoderInterface
{
public function decode(ResponseInterface $response)
Expand Down
3 changes: 3 additions & 0 deletions src/Decoder/ResponseDecoder/ResponseDecoderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Psr\Http\Message\ResponseInterface;

/**
* @internal
*/
interface ResponseDecoderInterface
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/Entity/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use ArrayAccess;

/**
* @api
*/
class Entity implements ArrayAccess
{
protected $data;
Expand Down
3 changes: 3 additions & 0 deletions src/Entity/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Paysera\Component\RestClientCommon\Entity;

/**
* @api
*/
class Filter extends Entity
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/Entity/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Countable;
use Iterator;

/**
* @api
*/
abstract class Result extends Entity implements Iterator, Countable
{
const METADATA_KEY = '_metadata';
Expand Down
3 changes: 3 additions & 0 deletions src/Exception/AuthenticationConfigurationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Paysera\Component\RestClientCommon\Exception;

/**
* @api
*/
class AuthenticationConfigurationException extends \Exception
{

Expand Down
3 changes: 3 additions & 0 deletions src/Exception/ClientException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Paysera\Component\RestClientCommon\Exception;

/**
* @api
*/
class ClientException extends RequestException
{

Expand Down
3 changes: 3 additions & 0 deletions src/Exception/ConfigurationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Exception;

/**
* @api
*/
class ConfigurationException extends Exception
{

Expand Down
3 changes: 3 additions & 0 deletions src/Exception/RequestException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

/**
* @api
*/
class RequestException extends \Exception
{
private $request;
Expand Down
3 changes: 3 additions & 0 deletions src/Exception/ServerException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Paysera\Component\RestClientCommon\Exception;

/**
* @api
*/
class ServerException extends RequestException
{

Expand Down
3 changes: 3 additions & 0 deletions src/Exception/UnsupportedContentTypeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Paysera\Component\RestClientCommon\Exception;

/**
* @api
*/
class UnsupportedContentTypeException extends \Exception
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use GuzzleHttp\Promise\PromiseInterface;
use Psr\Http\Message\RequestInterface;

/**
* @api
*/
interface AuthenticationMiddlewareInterface
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/Middleware/Authentication/BasicAuthentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use Paysera\Component\RestClientCommon\Util\ConfigHandler;
use Psr\Http\Message\RequestInterface;

/**
* @internal
*/
class BasicAuthentication implements AuthenticationMiddlewareInterface
{
const TYPE = 'basic';
Expand Down
3 changes: 3 additions & 0 deletions src/Middleware/Authentication/BearerAuthentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use Paysera\Component\RestClientCommon\Util\ConfigHandler;
use Psr\Http\Message\RequestInterface;

/**
* @internal
*/
class BearerAuthentication implements AuthenticationMiddlewareInterface
{
const TYPE = 'bearer';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Paysera\Component\RestClientCommon\Util\ConfigHandler;
use Paysera\Component\RestClientCommon\Exception\AuthenticationConfigurationException;

/**
* @internal
*/
class ClientCertificateAuthentication implements AuthenticationMiddlewareInterface
{
const TYPE = 'client_certificate';
Expand Down
3 changes: 3 additions & 0 deletions src/Middleware/Authentication/MacAuthentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Paysera\Component\RestClientCommon\Util\ConfigHandler;
use Psr\Http\Message\RequestInterface;

/**
* @internal
*/
class MacAuthentication implements AuthenticationMiddlewareInterface
{
const TYPE = 'mac';
Expand Down
3 changes: 3 additions & 0 deletions src/Middleware/Authentication/OAuthAuthentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

/**
* @internal
*/
class OAuthAuthentication implements AuthenticationMiddlewareInterface
{
const TYPE = 'oauth';
Expand Down
3 changes: 3 additions & 0 deletions src/Middleware/Exception/RequestExceptionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

/**
* @internal
*/
class RequestExceptionMiddleware
{
public function __invoke(callable $nextHandler, RequestInterface $request, array $options)
Expand Down
5 changes: 4 additions & 1 deletion src/Util/ClientFactoryAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
use Paysera\Component\RestClientCommon\Client\ApiClient;
use Paysera\Component\RestClientCommon\Middleware\Exception\RequestExceptionMiddleware;

/**
* @api
*/
abstract class ClientFactoryAbstract
{
const DEFAULT_BASE_URL = '';
Expand Down Expand Up @@ -62,7 +65,7 @@ public function createApiClient(array $options)
}
}

ConfigHandler::appendConfiguration($config, $options);
$config = array_merge($config, $options);

return $this->buildClient($baseUrl, $authBaseUrl, $config, $options);
}
Expand Down
22 changes: 3 additions & 19 deletions src/Util/ConfigHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

namespace Paysera\Component\RestClientCommon\Util;

/**
* @internal
*/
class ConfigHandler
{
const CONFIG_NAMESPACE = 'paysera';
const KEY_AUTHENTICATION = 'authentication';

private static $whitelistedConfiguration = [
'proxy',
'cookies',
'headers',
];

/**
* @param array $config
* @param string $parameter
Expand Down Expand Up @@ -46,17 +43,4 @@ public static function setAuthentication(array &$config, array $auth)
{
$config[self::CONFIG_NAMESPACE][self::KEY_AUTHENTICATION] = $auth;
}

public static function appendConfiguration(array &$config, array $options)
{
$optionsToAppend = [];

foreach ($options as $option => $value) {
if (in_array($option, self::$whitelistedConfiguration, true)) {
$optionsToAppend[$option] = $value;
}
}

$config = array_merge($config, $optionsToAppend);
}
}

0 comments on commit 6801176

Please sign in to comment.