From bc44dfc36de9bc2d37651c1d1e87b770352f5dcf Mon Sep 17 00:00:00 2001 From: Brian Salvaggio Date: Thu, 28 Dec 2017 15:31:15 -0500 Subject: [PATCH 1/7] added basic auth Updated build_etcd.sh to pull latest v2 release added unit tests for etcd_user added unit tests for etcd_pass --- composer.json | 4 ++++ src/Client.php | 38 +++++++++++++++++++++++++++++++++++++- test/bin/build_etcd.sh | 2 +- test/src/ClientTest.php | 3 ++- 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 5dd03a8..a90a388 100644 --- a/composer.json +++ b/composer.json @@ -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..e736b49 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 $etcd_user + * @return $this + */ + public function setEtcdUser($etcd_user) + { + $this->etcd_user = $etcd_user; + return $this; + } + + /** + * @param string $etcd_pass + * @return $this + */ + public function setEtcdPass($etcd_pass) + { + $this->etcd_pass = $etcd_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..d33db4e 100644 --- a/test/src/ClientTest.php +++ b/test/src/ClientTest.php @@ -27,7 +27,8 @@ 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 { From 24e496fbbb4b36188e901970dc75b4cce3ac664a Mon Sep 17 00:00:00 2001 From: Brian Salvaggio Date: Thu, 28 Dec 2017 15:37:07 -0500 Subject: [PATCH 2/7] Updated travis config to only build 7 --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7578689..19c62ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: php php: - - 5.6 - 7.0 before_install: - composer self-update From 2b47c38e7ee8dd1e24939a136c50324b02ebee45 Mon Sep 17 00:00:00 2001 From: Brian Salvaggio Date: Thu, 28 Dec 2017 15:45:11 -0500 Subject: [PATCH 3/7] Added back 5.6 to .travis.yml --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 19c62ee..7578689 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: php php: + - 5.6 - 7.0 before_install: - composer self-update From 2af8e72d233ac8b17ca7d463783adcb78243ce49 Mon Sep 17 00:00:00 2001 From: Brian Salvaggio Date: Thu, 28 Dec 2017 16:20:09 -0500 Subject: [PATCH 4/7] Updated all the things as activecollab/etcd appears to be abandoned --- README.md | 10 +++------- composer.json | 4 ++-- test/src/ClientTest.php | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 2b933ee..52a60f3 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 @@ -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 a90a388..a94dd7f 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", diff --git a/test/src/ClientTest.php b/test/src/ClientTest.php index d33db4e..52aa00a 100644 --- a/test/src/ClientTest.php +++ b/test/src/ClientTest.php @@ -34,7 +34,7 @@ protected function setUp() try { $this->client->removeDir($this->dirname, true); } catch (EtcdException $e) { - + die; } $create_dir = $this->client->createDir($this->dirname); From c7f7d89c612098dc1b00cb75adcb4de1fe1da615 Mon Sep 17 00:00:00 2001 From: Brian Salvaggio Date: Thu, 28 Dec 2017 16:23:09 -0500 Subject: [PATCH 5/7] updated name to be all lowercase. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a94dd7f..14bfc15 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name" : "SR02/etcd", + "name" : "sr02/etcd", "type": "library", "description": "etcd client with minimal dependencies", "license" : "MIT", From 031a3c8b4cc0f0e025a7cb7f61429e0cae0b945d Mon Sep 17 00:00:00 2001 From: Brian Salvaggio Date: Thu, 28 Dec 2017 16:57:33 -0500 Subject: [PATCH 6/7] updated param in setEtcdUser and setEtcdPass --- src/Client.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Client.php b/src/Client.php index e736b49..ca2e8dd 100644 --- a/src/Client.php +++ b/src/Client.php @@ -154,22 +154,22 @@ public function setApiVersion($version) } /** - * @param string $etcd_user + * @param string $user * @return $this */ - public function setEtcdUser($etcd_user) + public function setEtcdUser($user) { - $this->etcd_user = $etcd_user; + $this->etcd_user = $user; return $this; } /** - * @param string $etcd_pass + * @param string $pass * @return $this */ - public function setEtcdPass($etcd_pass) + public function setEtcdPass($pass) { - $this->etcd_pass = $etcd_pass; + $this->etcd_pass = $pass; return $this; } From 9df0a9c48027d48d7d21219a8092b6b4653d8497 Mon Sep 17 00:00:00 2001 From: Brian Salvaggio Date: Fri, 29 Dec 2017 09:57:25 -0500 Subject: [PATCH 7/7] Updated readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 52a60f3..40b79a0 100644 --- a/README.md +++ b/README.md @@ -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');