Skip to content

Commit

Permalink
added configuration option to not verify ssl certs. also changed trav…
Browse files Browse the repository at this point in the history
…is to use apiaxle 1.10 due to issues with 1.11
  • Loading branch information
Phillip Shipley committed Oct 23, 2013
1 parent fec66de commit 9f615a2
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 &
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###
Expand Down
6 changes: 5 additions & 1 deletion config/config.local.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
76 changes: 76 additions & 0 deletions src/ApiAxle/Shared/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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();
}
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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.
*
Expand Down
18 changes: 9 additions & 9 deletions src/ApiAxle/Shared/HttpRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'){
Expand Down
2 changes: 1 addition & 1 deletion src/ApiAxle/Shared/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
2 changes: 1 addition & 1 deletion vagrant-setup.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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 &
Expand Down

0 comments on commit 9f615a2

Please sign in to comment.