diff --git a/README.md b/README.md index 2b933ee..40b79a0 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # Etcd PHP Client -[![Build Status](https://travis-ci.org/activecollab/etcd.svg?branch=master)](https://travis-ci.org/activecollab/etcd) +[![Build Status](https://travis-ci.org/SR02/etcd.svg?branch=master)](https://travis-ci.org/SR02/etcd) etcd is a distributed configuration system, part of the coreos project. -This repository provides a client library for etcd for PHP applications. It is based on [linkorb/etcd-php](https://github.com/linkorb/etcd-php). To learn why we forked it, jump [here](#why-fork). +This repository provides a client library for etcd for PHP applications. It is based on [linkorb/etcd-php](https://github.com/linkorb/etcd-php) and [activecollab/etcd](https://github.com/activecollab/etcd). ## Installating etcd @@ -27,7 +27,7 @@ Easiest way is to install it using composer: ## Using Client ```php -use use ActiveCollab\Etcd\Client as EtcdClient; +use ActiveCollab\Etcd\Client as EtcdClient; $client = new EtcdClient('http://127.0.0.1:4001'); @@ -102,8 +102,4 @@ as well as to use a custom CA file: ```php $client = (new Client('https://127.0.0.1:4001'))->verifySslPeer(true, '/path/to/ca/file'); -``` - -## Why Fork? - -While [original library](https://github.com/linkorb/etcd-php) works well, it depends on two big packages: Symfony Console and Guzzle. For a feature as low level as config access, we wanted something a bit nimbler, so we removed CLI commands and refactored the original library to use PHP's curl extension. +``` \ No newline at end of file diff --git a/composer.json b/composer.json index 5dd03a8..14bfc15 100644 --- a/composer.json +++ b/composer.json @@ -1,11 +1,11 @@ { - "name" : "activecollab/etcd", + "name" : "sr02/etcd", "type": "library", "description": "etcd client with minimal dependencies", "license" : "MIT", "prefer-stable": true, "keywords": [ "etcd", "client", "configuration" ], - "homepage": "https://labs.activecollab.com", + "homepage": "https://github.com/SR02/etcd", "authors": [ { "name" : "Cong Peijun", @@ -14,6 +14,10 @@ { "name": "Ilija Studen", "email": "ilija.studen@activecollab.com" + }, + { + "name": "Brian Salvaggio", + "email": "salvaggio.brian@gmail.com" } ], "require" : { diff --git a/src/Client.php b/src/Client.php index c04508c..ca2e8dd 100644 --- a/src/Client.php +++ b/src/Client.php @@ -42,13 +42,26 @@ class Client implements ClientInterface */ private $custom_ca_file; + /** + * @var string + */ + private $etcd_user; + /** + * @var string + */ + private $etcd_pass; + /** * @param string $server + * @param string $etcd_user + * @param string $etcd_pass * @param string $api_version */ - public function __construct($server = 'http://127.0.0.1:4001', $api_version = 'v2') + public function __construct($server = 'http://127.0.0.1:4001', $etcd_user = null, $etcd_pass = null, $api_version = 'v2') { $this->setServer($server); + $this->setEtcdUser($etcd_user); + $this->setEtcdPass($etcd_pass); $this->setApiVersion($api_version); } @@ -140,6 +153,26 @@ public function setApiVersion($version) return $this; } + /** + * @param string $user + * @return $this + */ + public function setEtcdUser($user) + { + $this->etcd_user = $user; + return $this; + } + + /** + * @param string $pass + * @return $this + */ + public function setEtcdPass($pass) + { + $this->etcd_pass = $pass; + return $this; + } + /** * @return string */ @@ -614,6 +647,9 @@ private function getCurlHandle($url) curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); + if($this->etcd_user !== null) { + curl_setopt($curl, CURLOPT_USERPWD, $this->etcd_user.':'.$this->etcd_pass); + } if ($this->is_https && $this->verify_ssl_peer) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); diff --git a/test/bin/build_etcd.sh b/test/bin/build_etcd.sh index f768ebe..af7a112 100644 --- a/test/bin/build_etcd.sh +++ b/test/bin/build_etcd.sh @@ -2,7 +2,7 @@ wget -c https://storage.googleapis.com/golang/go1.4.linux-amd64.tar.gz tar -zxf go1.4.linux-amd64.tar.gz -git clone https://github.com/coreos/etcd.git +git clone -b release-2.3 https://github.com/coreos/etcd.git export GOROOT=$PWD/go #export GOPATH=$PWD/go export PATH=$GOPATH/bin:$PATH diff --git a/test/src/ClientTest.php b/test/src/ClientTest.php index 48e6724..52aa00a 100644 --- a/test/src/ClientTest.php +++ b/test/src/ClientTest.php @@ -27,13 +27,14 @@ class ClientTest extends \PHPUnit_Framework_TestCase protected function setUp() { $this->client = new Client(); - + $this->client->setEtcdUser('user'); + $this->client->setEtcdPass('pass'); $this->client->setSandboxPath('/'); try { $this->client->removeDir($this->dirname, true); } catch (EtcdException $e) { - + die; } $create_dir = $this->client->createDir($this->dirname);