diff --git a/.travis.yml b/.travis.yml index 6f5df45..afda944 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ before_script: - curl -s https://getcomposer.org/installer | php && php composer.phar update --dev - sudo add-apt-repository -y ppa:chris-lea/node.js - sudo apt-get update - - npm install -g apiaxle-proxy apiaxle-api + - npm install -g apiaxle-proxy@1.10 apiaxle-api@1.10 - apiaxle-proxy -p 3000 & - sleep 3 - apiaxle-api -p 8000 & diff --git a/README.md b/README.md index 3dbb339..ed53b96 100644 --- a/README.md +++ b/README.md @@ -12,14 +12,18 @@ ApiAxle is a proxy that sits on your network, in front of your API(s) and manage * [curl](http://php.net/curl) * [ApiAxle](http://apiaxle.com) proxy with the apiaxle-api package installed +## Special Note about ApiAxle version 1.11 ## +The tests for this library are not all able to run successfully with ApiAxle version 1.11. I'm working with the ApiAxle team to figure out what changed to cause the problem, but for now I recommend if you are using this library to use ApiAxle 1.10. + ## Features / Goals / TODO ## - [x] Readily consumable, configuration based, object oriented library - [x] Support for Api objects - [x] Support for Key objects -- [ ] Support for Keychain objects +- [x] Support for Keyring objects - [x] Set up continuous integration with Travis-CI: (https://travis-ci.org/fillup/apiaxle-module) - [ ] Create objects to represent stats, charts, etc? - [ ] Fix serialization of PHP boolean to string for ApiAxle API. Currently API wants string of either true or false, but serializing PHP boolean results in 0 or 1. +- [ ] Add support for new features in ApiAxle 1.11 to support capturing path statistics ## Installation ## ### Using Composer - Recommended ### diff --git a/config/config.local.php.dist b/config/config.local.php.dist index cb0578e..765b888 100644 --- a/config/config.local.php.dist +++ b/config/config.local.php.dist @@ -3,5 +3,9 @@ return array( 'endpoint' => 'http://domain.com:port/v1/', 'key' => 'somerandomstring', - 'secret' => 'somelongerrandomstring' + 'secret' => 'somelongerrandomstring', + 'ssl_verifypeer' => true, + 'proxy_enable' => false, + 'proxy_host' => '127.0.0.1', + 'proxy_port' => '8888', ); diff --git a/src/ApiAxle/Shared/Config.php b/src/ApiAxle/Shared/Config.php index 1cd0257..88fb89e 100644 --- a/src/ApiAxle/Shared/Config.php +++ b/src/ApiAxle/Shared/Config.php @@ -36,6 +36,34 @@ class Config */ protected $secret; + /** + * Enable/Disable verification of peer certificate when calling API + * + * @var bool $ssl_verifypeer + */ + protected $ssl_verifypeer = true; + + /** + * Enable/disable usage of a proxy server + * + * @var bool $proxy_enable + */ + protected $proxy_enable = false; + + /** + * Set proxy server hostname + * + * @var string $proxy_host + */ + protected $proxy_host; + + /** + * Set proxy server port + * + * @var string $proxy_port + */ + protected $proxy_port; + /** * Initialization status */ @@ -56,6 +84,10 @@ public function __construct($config = array()) $this->setEndpoint($config->getEndpoint()); $this->setKey($config->getKey()); $this->setSecret($config->getSecret()); + $this->setSslVerifypeer($config->getSslVerifypeer()); + $this->setProxyEnable($config->getProxyEnable()); + $this->setProxyHost($config->getProxyHost()); + $this->setProxyPort($config->getProxyPort()); } else { $this->loadConfigFile(); } @@ -75,6 +107,10 @@ public function setConfg($config) $this->setEndpoint(isset($config['endpoint']) ? $config['endpoint'] : false); $this->setKey(isset($config['key']) ? $config['key'] : false); $this->setSecret(isset($config['secret']) ? $config['secret'] : false); + $this->setSslVerifypeer(isset($config['ssl_verifypeer']) ? $config['ssl_verifypeer'] : true); + $this->setProxyEnable(isset($config['proxy_enable']) ? $config['proxy_enable'] : false); + $this->setProxyHost(isset($config['proxy_host']) ? $config['proxy_host'] : null); + $this->setProxyPort(isset($config['proxy_port']) ? $config['proxy_port'] : null); } /** @@ -152,6 +188,46 @@ public function setSecret($secret) $this->secret = $secret; } + public function getSslVerifypeer() + { + return $this->ssl_verifypeer; + } + + public function setSslVerifypeer($ssl_verifypeer) + { + $this->ssl_verifypeer = $ssl_verifypeer; + } + + public function getProxyEnable() + { + return $this->proxy_enable; + } + + public function setProxyEnable($proxy_enable) + { + $this->proxy_enable = $proxy_enable; + } + + public function getProxyHost() + { + return $this->proxy_host; + } + + public function setProxyHost($proxy_host) + { + $this->proxy_host = $proxy_host; + } + + public function getProxyPort() + { + return $this->proxy_port; + } + + public function setProxyPort($proxy_port) + { + $this->proxy_port = $proxy_port; + } + /** * Generate an API signature based on key and shared secret. * diff --git a/src/ApiAxle/Shared/HttpRequest.php b/src/ApiAxle/Shared/HttpRequest.php index 8e8f545..8844bcd 100644 --- a/src/ApiAxle/Shared/HttpRequest.php +++ b/src/ApiAxle/Shared/HttpRequest.php @@ -35,19 +35,19 @@ class HttpRequest * response as a string. * @throws \ErrorException On error making the HTTP request. */ - public static function request($uri,$method='GET',$postfields=false,$headers=false) { + public static function request($uri,$method='GET',$postfields=false,$headers=false,$config=false) { $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, $uri); curl_setopt($ch, CURLINFO_HEADER_OUT, true); - /** - * Added for debugging with Charles proxy - */ -// curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1'); -// curl_setopt($ch, CURLOPT_PROXYPORT, '8888'); -// curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, true); -// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - + if($config){ + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $config->getSslVerifypeer()); + if($config->getProxyEnable()){ + curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, $config->getProxyEnable()); + curl_setopt($ch, CURLOPT_PROXY, $config->getProxyHost()); + curl_setopt($ch, CURLOPT_PROXYPORT, $config->getProxyPort()); + } + } $method = strtoupper($method); if($method == 'GET'){ diff --git a/src/ApiAxle/Shared/Utilities.php b/src/ApiAxle/Shared/Utilities.php index 6129176..02024a4 100644 --- a/src/ApiAxle/Shared/Utilities.php +++ b/src/ApiAxle/Shared/Utilities.php @@ -64,7 +64,7 @@ public static function callApi($apiPath, $method='GET', $data=null, $config) } $url = $config->getEndpoint().'/'.$apiPath; - $request = HttpRequest::request($url, $method, $json_data, $headers); + $request = HttpRequest::request($url, $method, $json_data, $headers, $config); if($request){ $results = json_decode($request); if($results->meta->status_code >= 200 && $results->meta->status_code < 300){ diff --git a/vagrant-setup.sh b/vagrant-setup.sh old mode 100644 new mode 100755 index e1adf61..6924549 --- a/vagrant-setup.sh +++ b/vagrant-setup.sh @@ -4,7 +4,7 @@ sudo add-apt-repository -y ppa:chris-lea/node.js sudo apt-get update -y sudo apt-get install -y git python-software-properties build-essential libxml2-dev nodejs redis-server php5 php5-curl -sudo npm install -g apiaxle-repl apiaxle-proxy apiaxle-api +sudo npm install -g apiaxle-base apiaxle-repl apiaxle-proxy apiaxle-api # Start ApiAxle processes apiaxle-proxy -p 3000 &