Archive repository
Bug: T228244
Change-Id: I01f4dce7e062fb4e17a0558f6aee26954c1d3b46
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index 015bec1..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-composer.lock
-vendor
-/.phpunit.result.cache
diff --git a/.phpcs.xml b/.phpcs.xml
deleted file mode 100644
index a840940..0000000
--- a/.phpcs.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-<?xml version="1.0"?>
-<ruleset>
- <rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki">
- <exclude name="MediaWiki.Commenting.MissingCovers.MissingCovers" />
- </rule>
- <file>.</file>
- <arg name="extensions" value="php"/>
- <arg name="encoding" value="UTF-8"/>
-</ruleset>
diff --git a/ARCHIVED b/ARCHIVED
new file mode 100644
index 0000000..95000a9
--- /dev/null
+++ b/ARCHIVED
@@ -0,0 +1,2 @@
+This repository has been archived. See <https://phabricator.wikimedia.org/T228244>
+for details.
diff --git a/COPYING b/COPYING
deleted file mode 100644
index d159169..0000000
--- a/COPYING
+++ /dev/null
@@ -1,339 +0,0 @@
- GNU GENERAL PUBLIC LICENSE
- Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users. This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it. (Some other Free Software Foundation software is covered by
-the GNU Lesser General Public License instead.) You can apply it to
-your programs, too.
-
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
- To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have. You must make sure that they, too, receive or can get the
-source code. And you must show them these terms so they know their
-rights.
-
- We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
- Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software. If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
- Finally, any free program is threatened constantly by software
-patents. We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary. To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- GNU GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License. The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language. (Hereinafter, translation is included without limitation in
-the term "modification".) Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
- 1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
- 2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) You must cause the modified files to carry prominent notices
- stating that you changed the files and the date of any change.
-
- b) You must cause any work that you distribute or publish, that in
- whole or in part contains or is derived from the Program or any
- part thereof, to be licensed as a whole at no charge to all third
- parties under the terms of this License.
-
- c) If the modified program normally reads commands interactively
- when run, you must cause it, when started running for such
- interactive use in the most ordinary way, to print or display an
- announcement including an appropriate copyright notice and a
- notice that there is no warranty (or else, saying that you provide
- a warranty) and that users may redistribute the program under
- these conditions, and telling the user how to view a copy of this
- License. (Exception: if the Program itself is interactive but
- does not normally print such an announcement, your work based on
- the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
- a) Accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of Sections
- 1 and 2 above on a medium customarily used for software interchange; or,
-
- b) Accompany it with a written offer, valid for at least three
- years, to give any third party, for a charge no more than your
- cost of physically performing source distribution, a complete
- machine-readable copy of the corresponding source code, to be
- distributed under the terms of Sections 1 and 2 above on a medium
- customarily used for software interchange; or,
-
- c) Accompany it with the information you received as to the offer
- to distribute corresponding source code. (This alternative is
- allowed only for noncommercial distribution and only if you
- received the program in object code or executable form with such
- an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it. For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable. However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License. Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
- 5. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Program or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
- 6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
- 7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all. For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded. In such case, this License incorporates
-the limitation as if written in the body of this License.
-
- 9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation. If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
- 10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission. For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this. Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
- NO WARRANTY
-
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
- To do so, attach the following notices to the program. It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
- <one line to give the program's name and a brief idea of what it does.>
- Copyright (C) <year> <name of author>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
- Gnomovision version 69, Copyright (C) year name of author
- Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- This is free software, and you are welcome to redistribute it
- under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License. Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary. Here is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
- `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
- <signature of Ty Coon>, 1 April 1989
- Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs. If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library. If this is what you want to do, use the GNU Lesser General
-Public License instead of this License.
diff --git a/README.md b/README.md
deleted file mode 100644
index 2b933ee..0000000
--- a/README.md
+++ /dev/null
@@ -1,109 +0,0 @@
-# Etcd PHP Client
-
-[](https://travis-ci.org/activecollab/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).
-
-## Installating etcd
-
-To install etcd, follow instructions that etcd team posts on Releases page of the project:
-
-[https://github.com/coreos/etcd/releases/](https://github.com/coreos/etcd/releases/)
-
-## Installing ActiveCollab/etcd
-
-Easiest way is to install it using composer:
-
-```json
-{
- "require" : {
- "activecollab/etcd": "^1.0"
- }
-}
-```
-
-## Using Client
-
-```php
-use use ActiveCollab\Etcd\Client as EtcdClient;
-
-$client = new EtcdClient('http://127.0.0.1:4001');
-
-// Get, set, update, remove key
-if (!$client->exists('/key/name')) {
- $client->set('/key/name', 'value');
-}
-$client->set('/key/name', 'value', 10); // Set TTL
-print $client->get('/key/name');
-
-$client->update('/key/name', 'new value');
-
-$client->remove('/key/name');
-
-// Working with dirs
-if (!$client->dirExists('/dir/path')) {
- $client->createDir('/dir/path');
-}
-$client->updateDir('/dir/path', 10); // Set TTL
-$client->removeDir('/dir/path');
-
-// Get dir info
-$client->dirInfo('/dir/path');
-
-// List subdirectories
-$client->listDirs('/dir/path');
-
-// Return key value map for a given dir
-$client->getKeyValueMap('/dir/path')
-```
-
-## Sandbox Path
-
-If you configure sandbox path in the client instance, all keys will be prefixed with that path:
-
-```php
-$client = new EtcdClient('http://127.0.0.1:4001');
-$client->setSandboxPath('/my/namespace');
-
-$client->set('/key/name', 'value'); // will set /my/namespace/key/name
-print $client->get('/key/name'); // will print /my/namespace/key/name
-```
-
-One more conenient method that client offers is option to call several commands in a specific sanbox, and have client revert back to the previous sandbox path when done:
-
-```php
-$client = new EtcdClient('http://127.0.0.1:4001');
-$client->setSandboxPath('/my/namespace');
-
-// Path relative to the current sandbox path
-$client->sandboxed('./different/namespace', function(EtcdClient &$c) {
- $c->set('new_key', 123); // Sets /my/namespace/different/namespace/new_key
-});
-
-// Absolute path
-$client->sandboxed('/different/namespace', function(EtcdClient &$c) {
- $c->set('new_key', 123); // Sets /different/namespace/new_key
-});
-
-print $client->getSandboxPath(); // Prints '/my/namespace'
-```
-
-## SSL
-
-Client can be configured not to verify SSL peer:
-
-```php
-$client = (new Client('https://127.0.0.1:4001'))->verifySslPeer(false);
-```
-
-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.
diff --git a/composer.json b/composer.json
deleted file mode 100644
index 284eb4d..0000000
--- a/composer.json
+++ /dev/null
@@ -1,53 +0,0 @@
-{
- "name": "wikimedia/etcd",
- "description": "PHP client for etcd, a distributed configuration system",
- "license": "GPL-2.0-or-later",
- "keywords": [
- "etcd",
- "client",
- "configuration"
- ],
- "homepage": "https://www.mediawiki.org/wiki/etcd",
- "authors": [
- {
- "name": "Cong Peijun",
- "email": "p.cong@linkorb.com"
- },
- {
- "name": "Ilija Studen",
- "email": "ilija.studen@activecollab.com"
- },
- {
- "name": "Kunal Mehta"
- }
- ],
- "require": {
- "php": ">=7.4.3",
- "ext-curl": "*"
- },
- "require-dev": {
- "mediawiki/mediawiki-codesniffer": "41.0.0",
- "mediawiki/minus-x": "1.1.1",
- "php-parallel-lint/php-console-highlighter": "1.0.0",
- "php-parallel-lint/php-parallel-lint": "1.3.2",
- "phpunit/phpunit": "9.5.28"
- },
- "scripts": {
- "test": [
- "parallel-lint . --exclude vendor",
- "@phpcs",
- "minus-x check ."
- ],
- "fix": [
- "minus-x fix .",
- "phpcbf"
- ],
- "phpcs": "phpcs -sp --cache"
- },
- "autoload": {
- "psr-4": {
- "ActiveCollab\\Etcd\\": "src",
- "ActiveCollab\\Etcd\\Test\\": "test/src"
- }
- }
-}
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
deleted file mode 100644
index a88bba7..0000000
--- a/phpunit.xml.dist
+++ /dev/null
@@ -1,13 +0,0 @@
-<?xml version="1.0"?>
-<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
- <coverage includeUncoveredFiles="true">
- <include>
- <directory suffix=".php">./src</directory>
- </include>
- </coverage>
- <testsuites>
- <testsuite name="etcd tests">
- <directory>./test</directory>
- </testsuite>
- </testsuites>
-</phpunit>
diff --git a/src/Client.php b/src/Client.php
deleted file mode 100644
index 17fffda..0000000
--- a/src/Client.php
+++ /dev/null
@@ -1,644 +0,0 @@
-<?php
-
-namespace ActiveCollab\Etcd;
-
-use ActiveCollab\Etcd\Exception\EtcdException;
-use ActiveCollab\Etcd\Exception\KeyExistsException;
-use ActiveCollab\Etcd\Exception\KeyNotFoundException;
-use RecursiveArrayIterator;
-
-/**
- * @package ActiveCollab\Etcd
- */
-class Client implements ClientInterface {
- /**
- * @var string
- */
- private $server;
-
- /**
- * @var bool
- */
- private $is_https = false;
-
- /**
- * @var string
- */
- private $api_version;
-
- /**
- * @var string
- */
- private $root = '/';
-
- /**
- * @var bool
- */
- private $verify_ssl_peer = true;
-
- /**
- * @var string
- */
- private $custom_ca_file;
-
- /**
- * @param string $server
- * @param string $api_version
- */
- public function __construct( $server = 'http://127.0.0.1:2379', $api_version = 'v2' ) {
- $this->setServer( $server );
- $this->setApiVersion( $api_version );
- }
-
- /**
- * @return string
- */
- public function getServer() {
- return $this->server;
- }
-
- /**
- * @param string $server
- * @return $this
- */
- public function &setServer( $server ) {
- if ( filter_var( $server, FILTER_VALIDATE_URL ) ) {
- $server = rtrim( $server, '/' );
-
- if ( $server ) {
- $this->server = $server;
- $this->is_https = strtolower( parse_url( $this->server )['scheme'] ) == 'https';
- }
-
- return $this;
- } else {
- throw new \InvalidArgumentException( "Value '$server' is not a valid server URL" );
- }
- }
-
- /**
- * @return bool
- */
- public function getVerifySslPeer() {
- return $this->verify_ssl_peer;
- }
-
- /**
- * @return string
- */
- public function getCustomCaFile() {
- return $this->custom_ca_file;
- }
-
- /**
- * Configure SSL connection parameters
- *
- * @param bool|true $verify_ssl_peer
- * @param string|null $custom_ca_file
- * @return $this
- */
- public function &verifySslPeer( $verify_ssl_peer = true, $custom_ca_file = null ) {
- if ( $custom_ca_file ) {
- if ( !is_file( $custom_ca_file ) ) {
- throw new \InvalidArgumentException( 'Custom CA file does not exist' );
- }
-
- if ( !$verify_ssl_peer ) {
- throw new \LogicException( 'Custom CA file shoult not be set if SSL peer is not verified' );
- }
- }
-
- $this->verify_ssl_peer = (bool)$verify_ssl_peer;
- $this->custom_ca_file = $custom_ca_file;
-
- return $this;
- }
-
- /**
- * @return string
- */
- public function getApiVersion() {
- return $this->api_version;
- }
-
- /**
- * @param string $version
- * @return $this
- */
- public function &setApiVersion( $version ) {
- $this->api_version = $version;
-
- return $this;
- }
-
- /**
- * @return string
- */
- public function getSandboxPath() {
- return $this->root;
- }
-
- /**
- * Set the default root directory. the default is `/`
- * If the root is others e.g. /linkorb when you set new key,
- * or set dir, all of the key is under the root
- * e.g.
- * <code>
- * $client->setRoot('/linkorb');
- * $client->set('key1, 'value1');
- * // the new key is /linkorb/key1
- * </code>
- *
- * @param string $root
- * @return Client
- */
- public function &setSandboxPath( $root ) {
- if ( substr( $root, 0, 1 ) !== '/' ) {
- $root = '/' . $root;
- }
-
- $this->root = rtrim( $root, '/' );
-
- return $this;
- }
-
- /**
- * Build key space operations
- *
- * @param string $key
- * @return string
- */
- public function getKeyPath( $key ) {
- if ( substr( $key, 0, 1 ) !== '/' ) {
- $key = '/' . $key;
- }
-
- return rtrim( '/' . $this->api_version . '/keys' . $this->root, '/' ) . $key;
- }
-
- /**
- * Return full key URI
- *
- * @param string $key
- * @return string
- */
- public function getKeyUrl( $key ) {
- return $this->server . $this->getKeyPath( $key );
- }
-
- /**
- * @return array
- */
- public function geVersion() {
- return $this->httpGet( $this->server . '/version' );
- }
-
- /**
- * @inheritDoc
- */
- public function exists( $key ) {
- try {
- $response = $this->httpGet( $this->getKeyUrl( $key ) );
-
- return !empty( $response['node'] ) && array_key_exists( 'value', $response['node'] );
- } catch ( KeyNotFoundException $e ) {
- return false;
- }
- }
-
- /**
- * @inheritDoc
- */
- public function dirExists( $key ) {
- try {
- return !empty( $this->httpGet( $this->getKeyUrl( $key ) )['node']['dir'] );
- } catch ( KeyNotFoundException $e ) {
- return false;
- }
- }
-
- /**
- * @inheritDoc
- */
- public function set( $key, $value, $ttl = null, $condition = [] ) {
- $data = [ 'value' => $value ];
-
- if ( $ttl ) {
- $data['ttl'] = $ttl;
- }
-
- return $this->httpPut( $this->getKeyUrl( $key ), $data, $condition );
- }
-
- /**
- * Retrieve the value of a key
- *
- * @param string $key
- * @param array|null $flags the extra query params
- * @return array
- * @throws KeyNotFoundException
- * @throws EtcdException
- */
- public function getNode( $key, array $flags = null ) {
- $query = [];
- if ( $flags ) {
- $query = [ 'query' => $flags ];
- }
-
- $response = $this->httpGet( $this->getKeyUrl( $key ), $query );
-
- if ( empty( $response['node'] ) ) {
- throw new EtcdException( 'Node field expected in response' );
- } else {
- return $response['node'];
- }
- }
-
- /**
- * Retrieve the value of a key
- *
- * @param string $key
- * @param array|null $flags the extra query params
- * @return string the value of the key.
- * @throws KeyNotFoundException
- */
- public function get( $key, array $flags = null ) {
- try {
- $node = $this->getNode( $key, $flags );
-
- return $node['value'];
- } catch ( KeyNotFoundException $ex ) {
- throw $ex;
- }
- }
-
- /**
- * Create a new key with a given value
- *
- * @param string $key
- * @param string $value
- * @param int $ttl
- * @return array $body
- * @throws KeyExistsException
- */
- public function create( $key, $value, $ttl = 0 ) {
- return $this->set( $key, $value, $ttl, [ 'prevExist' => 'false' ] );
- }
-
- /**
- * make a new directory
- *
- * @param string $key
- * @param int $ttl
- * @return array $body
- * @throws KeyExistsException
- */
- public function createDir( $key, $ttl = 0 ) {
- $data = [ 'dir' => 'true' ];
-
- if ( $ttl ) {
- $data['ttl'] = $ttl;
- }
-
- return $this->httpPut( $this->getKeyUrl( $key ), $data, [ 'prevExist' => 'false' ] );
- }
-
- /**
- * Update an existing key with a given value.
- *
- * @param string $key
- * @param string $value
- * @param int $ttl
- * @param array $condition The extra condition for updating
- * @return array $body
- * @throws KeyNotFoundException
- */
- public function update( $key, $value, $ttl = 0, $condition = [] ) {
- $extra = [ 'prevExist' => 'true' ];
-
- if ( $condition ) {
- $extra = array_merge( $extra, $condition );
- }
-
- return $this->set( $key, $value, $ttl, $extra );
- }
-
- /**
- * Update directory
- *
- * @param string $key
- * @param int $ttl
- * @return array
- * @throws EtcdException
- */
- public function updateDir( $key, $ttl ) {
- if ( !$ttl ) {
- throw new EtcdException( 'TTL is required', 204 );
- }
-
- return $this->httpPut( $this->getKeyUrl( $key ), [ 'ttl' => (int)$ttl ], [
- 'dir' => 'true',
- 'prevExist' => 'true',
- ] );
- }
-
- /**
- * remove a key
- *
- * @param string $key
- * @return array
- * @throws EtcdException
- */
- public function remove( $key ) {
- return $this->httpDelete( $this->getKeyUrl( $key ) );
- }
-
- /**
- * Removes the key if it is directory
- *
- * @param string $key
- * @param bool $recursive
- * @return mixed
- * @throws EtcdException
- */
- public function removeDir( $key, $recursive = false ) {
- $query = [ 'dir' => 'true' ];
-
- if ( $recursive === true ) {
- $query['recursive'] = 'true';
- }
-
- return $this->httpDelete( $this->server . $this->getKeyPath( $key ), $query );
- }
-
- /**
- * Retrieve a directory
- *
- * @param string $key
- * @param bool $recursive
- * @return mixed
- * @throws KeyNotFoundException
- */
- public function dirInfo( $key = '/', $recursive = false ) {
- $query = [];
- if ( $recursive === true ) {
- $query['recursive'] = 'true';
- }
-
- return $this->httpGet( $this->getKeyUrl( $key ), $query );
- }
-
- /**
- * Retrieve a directories key
- *
- * @param string $key
- * @param bool $recursive
- * @return array
- * @throws EtcdException
- */
- public function listSubdirs( $key = '/', $recursive = false ) {
- try {
- $data = $this->dirInfo( $key, $recursive );
- } catch ( EtcdException $e ) {
- throw $e;
- }
-
- $iterator = new RecursiveArrayIterator( $data );
-
- return $this->traversalDir( $iterator );
- }
-
- /**
- * @var array
- */
- private $dirs = [];
-
- /**
- * @var array
- */
- private $values = [];
-
- /**
- * Traversal the directory to get the keys.
- *
- * @param RecursiveArrayIterator $iterator
- * @return array
- */
- private function traversalDir( RecursiveArrayIterator $iterator ) {
- $key = '';
- while ( $iterator->valid() ) {
- if ( $iterator->hasChildren() ) {
- $this->traversalDir( $iterator->getChildren() );
- } else {
- if ( $iterator->key() == 'key' && ( $iterator->current() != '/' ) ) {
- $this->dirs[] = $key = $iterator->current();
- }
-
- if ( $iterator->key() == 'value' ) {
- $this->values[ $key ] = $iterator->current();
- }
- }
- $iterator->next();
- }
-
- return $this->dirs;
- }
-
- /**
- * Get all key-value pair that the key is not directory.
- *
- * @param string $root
- * @param bool $recursive
- * @param string|null $key
- * @return array
- */
- public function getKeyValueMap( $root = '/', $recursive = true, $key = null ) {
- $this->listSubdirs( $root, $recursive );
- if ( isset( $this->values[ $key ] ) ) {
- return $this->values[ $key ];
- }
-
- return $this->values;
- }
-
- /**
- * @inheritDoc
- */
- public function sandboxed( $sandbox_path, callable $callback ) {
- $current_sandbox_path = $this->getSandboxPath();
-
- if ( $sandbox_path != $current_sandbox_path ) {
- if ( mb_substr( $sandbox_path, 0, 2 ) == './' ) {
- $this->setSandboxPath( $current_sandbox_path . mb_substr( $sandbox_path, 1 ) );
- } else {
- $this->setSandboxPath( $sandbox_path );
- }
- }
-
- $client = $this;
- call_user_func_array( $callback, [ &$client ] );
-
- if ( $sandbox_path != $current_sandbox_path ) {
- $this->setSandboxPath( $current_sandbox_path );
- }
- }
-
- // ---------------------------------------------------
- // Make requests
- // ---------------------------------------------------
-
- /**
- * Make a GET request
- *
- * @param string $url
- * @param array $query_arguments
- * @return array
- */
- private function httpGet( $url, $query_arguments = [] ) {
- if ( !empty( $query_arguments ) ) {
- $url .= '?' . http_build_query( $query_arguments );
- }
-
- return $this->executeCurlRequest( $this->getCurlHandle( $url ), $url );
- }
-
- /**
- * Make a POST request
- *
- * @param string $url
- * @param array $payload
- * @param array $query_arguments
- * @return array|mixed
- * @throws EtcdException
- */
- private function httpPost( $url, $payload = [], $query_arguments = [] ) {
- if ( !empty( $query_arguments ) ) {
- $url .= '?' . http_build_query( $query_arguments );
- }
-
- $curl = $this->getCurlHandle( $url );
-
- curl_setopt( $curl, CURLOPT_CUSTOMREQUEST, 'POST' );
- curl_setopt( $curl, CURLOPT_HTTPHEADER, [ 'Content-Type: application/x-www-form-urlencoded' ] );
- curl_setopt( $curl, CURLOPT_POSTFIELDS, http_build_query( $payload ) );
-
- return $this->executeCurlRequest( $curl, $url );
- }
-
- /**
- * Make a PUT request
- *
- * @param string $url
- * @param array $payload
- * @param array $query_arguments
- * @return array|mixed
- * @throws EtcdException
- */
- private function httpPut( $url, $payload = [], $query_arguments = [] ) {
- if ( !empty( $query_arguments ) ) {
- $url .= '?' . http_build_query( $query_arguments );
- }
-
- $curl = $this->getCurlHandle( $url );
-
- curl_setopt( $curl, CURLOPT_CUSTOMREQUEST, 'PUT' );
- curl_setopt( $curl, CURLOPT_HTTPHEADER, [ 'Content-Type: application/x-www-form-urlencoded' ] );
- curl_setopt( $curl, CURLOPT_POSTFIELDS, http_build_query( $payload ) );
-
- return $this->executeCurlRequest( $curl, $url );
- }
-
- /**
- * Make a DELETE request
- *
- * @param string $url
- * @param array $query_arguments
- * @return array|mixed
- * @throws EtcdException
- */
- private function httpDelete( $url, $query_arguments = [] ) {
- if ( !empty( $query_arguments ) ) {
- $url .= '?' . http_build_query( $query_arguments );
- }
-
- $curl = $this->getCurlHandle( $url );
-
- curl_setopt( $curl, CURLOPT_CUSTOMREQUEST, 'DELETE' );
-
- return $this->executeCurlRequest( $curl, $url );
- }
-
- /**
- * Initialize curl handle
- *
- * @param string $url
- * @return resource
- */
- private function getCurlHandle( $url ) {
- $curl = curl_init( $url );
- if ( $curl ) {
- curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 15 );
- curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
- curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );
-
- if ( $this->is_https && $this->verify_ssl_peer ) {
- curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, true );
- curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, 2 );
-
- if ( $this->custom_ca_file ) {
- curl_setopt( $curl, CURLOPT_CAINFO, $this->custom_ca_file );
- }
- } else {
- curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, false );
- curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, false );
- }
-
- return $curl;
- } else {
- throw new \RuntimeException( "Can't create curl handle" );
- }
- }
-
- /**
- * @param resource $curl
- * @param string $url
- * @param bool|true $decode_etcd_json
- * @return array|mixed
- * @throws EtcdException
- */
- private function executeCurlRequest( $curl, $url, $decode_etcd_json = true ) {
- $response = curl_exec( $curl );
- $error_code = curl_errno( $curl );
- if ( $error_code ) {
- $error = curl_error( $curl );
-
- curl_close( $curl );
- throw new \RuntimeException( "$url request failed. Reason: $error", $error_code );
- } else {
- curl_close( $curl );
-
- if ( $decode_etcd_json ) {
- $response = json_decode( $response, true );
-
- if ( isset( $response['errorCode'] ) && $response['errorCode'] ) {
- $message = $response['message'];
-
- if ( isset( $response['cause'] ) && $response['cause'] ) {
- $message .= '. Cause: ' . $response['cause'];
- }
-
- switch ( $response['errorCode'] ) {
- case 100:
- throw new KeyNotFoundException( $message );
- case 105:
- throw new KeyExistsException( $message );
- default:
- throw new EtcdException( $message );
- }
- }
- }
-
- return $response;
- }
- }
-}
diff --git a/src/ClientInterface.php b/src/ClientInterface.php
deleted file mode 100644
index b182039..0000000
--- a/src/ClientInterface.php
+++ /dev/null
@@ -1,243 +0,0 @@
-<?php
-
-namespace ActiveCollab\Etcd;
-
-use ActiveCollab\Etcd\Exception\EtcdException;
-use ActiveCollab\Etcd\Exception\KeyExistsException;
-use ActiveCollab\Etcd\Exception\KeyNotFoundException;
-
-/**
- * @package ActiveCollab\Etcd
- */
-interface ClientInterface {
- /**
- * @return string
- */
- public function getServer();
-
- /**
- * @param string $server
- * @return $this
- */
- public function &setServer( $server );
-
- /**
- * @return bool
- */
- public function getVerifySslPeer();
-
- /**
- * @return string
- */
- public function getCustomCaFile();
-
- /**
- * Configure SSL connection parameters
- *
- * @param bool|true $verify_ssl_peer
- * @param string|null $custom_ca_file
- * @return $this
- */
- public function &verifySslPeer( $verify_ssl_peer = true, $custom_ca_file = null );
-
- /**
- * @return string
- */
- public function getApiVersion();
-
- /**
- * @param string $version
- * @return $this
- */
- public function &setApiVersion( $version );
-
- /**
- * @return string
- */
- public function getSandboxPath();
-
- /**
- * Set the default root directory. the default is `/`
- * If the root is others e.g. /linkorb when you set new key,
- * or set dir, all of the key is under the root
- * e.g.
- * <code>
- * $client->setRoot('/linkorb');
- * $client->set('key1, 'value1');
- * // the new key is /linkorb/key1
- * </code>
- *
- * @param string $root
- * @return Client
- */
- public function &setSandboxPath( $root );
-
- /**
- * Build key space operations
- *
- * @param string $key
- * @return string
- */
- public function getKeyPath( $key );
-
- /**
- * Return full key URI
- *
- * @param string $key
- * @return string
- */
- public function getKeyUrl( $key );
-
- /**
- * @return array
- */
- public function geVersion();
-
- /**
- * Return true if key exists
- *
- * @param string $key
- * @return bool
- */
- public function exists( $key );
-
- /**
- * Return true if directory exists
- *
- * @param string $key
- * @return bool
- */
- public function dirExists( $key );
-
- /**
- * Set the value of a key
- *
- * @param string $key
- * @param string $value
- * @param int|null $ttl
- * @param array $condition
- * @return array
- */
- public function set( $key, $value, $ttl = null, $condition = [] );
-
- /**
- * Retrieve the value of a key
- *
- * @param string $key
- * @param array|null $flags
- * @return array
- * @throws KeyNotFoundException
- * @throws EtcdException
- */
- public function getNode( $key, array $flags = null );
-
- /**
- * Retrieve the value of a key
- *
- * @param string $key
- * @param array|null $flags the extra query params
- * @return string the value of the key.
- * @throws KeyNotFoundException
- */
- public function get( $key, array $flags = null );
-
- /**
- * Create a new key with a given value
- *
- * @param string $key
- * @param string $value
- * @param int $ttl
- * @return array $body
- * @throws KeyExistsException
- */
- public function create( $key, $value, $ttl = 0 );
-
- /**
- * make a new directory
- *
- * @param string $key
- * @param int $ttl
- * @return array $body
- * @throws KeyExistsException
- */
- public function createDir( $key, $ttl = 0 );
-
- /**
- * Update an existing key with a given value.
- *
- * @param string $key
- * @param string $value
- * @param int $ttl
- * @param array $condition The extra condition for updating
- * @return array $body
- * @throws KeyNotFoundException
- */
- public function update( $key, $value, $ttl = 0, $condition = [] );
-
- /**
- * Update directory
- *
- * @param string $key
- * @param int $ttl
- * @return array
- * @throws EtcdException
- */
- public function updateDir( $key, $ttl );
-
- /**
- * remove a key
- *
- * @param string $key
- * @return array
- * @throws EtcdException
- */
- public function remove( $key );
-
- /**
- * Removes the key if it is directory
- *
- * @param string $key
- * @param bool $recursive
- * @return mixed
- * @throws EtcdException
- */
- public function removeDir( $key, $recursive = false );
-
- /**
- * Retrieve a directory
- *
- * @param string $key
- * @param bool $recursive
- * @return mixed
- * @throws KeyNotFoundException
- */
- public function dirInfo( $key = '/', $recursive = false );
-
- /**
- * Retrieve a directories key
- *
- * @param string $key
- * @param bool $recursive
- * @return array
- * @throws EtcdException
- */
- public function listSubdirs( $key = '/', $recursive = false );
-
- /**
- * Get all key-value pair that the key is not directory.
- *
- * @param string $root
- * @param bool $recursive
- * @param string|null $key
- * @return array
- */
- public function getKeyValueMap( $root = '/', $recursive = true, $key = null );
-
- /**
- * Run a sandboxed set of commands.
- *
- * @param string $sandbox_path
- * @param callable $callback
- */
- public function sandboxed( $sandbox_path, callable $callback );
-}
diff --git a/src/Exception/EtcdException.php b/src/Exception/EtcdException.php
deleted file mode 100644
index d03fe4c..0000000
--- a/src/Exception/EtcdException.php
+++ /dev/null
@@ -1,11 +0,0 @@
-<?php
-
-namespace ActiveCollab\Etcd\Exception;
-
-use Exception;
-
-/**
- * @author Cong Peijun <p.cong@linkorb.com>
- */
-class EtcdException extends Exception implements ExceptionInterface {
-}
diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php
deleted file mode 100644
index 5cc121c..0000000
--- a/src/Exception/ExceptionInterface.php
+++ /dev/null
@@ -1,9 +0,0 @@
-<?php
-
-namespace ActiveCollab\Etcd\Exception;
-
-/**
- * @package ActiveCollab\Etcd\Exception
- */
-interface ExceptionInterface {
-}
diff --git a/src/Exception/KeyExistsException.php b/src/Exception/KeyExistsException.php
deleted file mode 100644
index f145740..0000000
--- a/src/Exception/KeyExistsException.php
+++ /dev/null
@@ -1,9 +0,0 @@
-<?php
-
-namespace ActiveCollab\Etcd\Exception;
-
-/**
- * @author Cong Peijun <p.cong@linkorb.com>
- */
-class KeyExistsException extends EtcdException implements ExceptionInterface {
-}
diff --git a/src/Exception/KeyNotFoundException.php b/src/Exception/KeyNotFoundException.php
deleted file mode 100644
index cfbe27c..0000000
--- a/src/Exception/KeyNotFoundException.php
+++ /dev/null
@@ -1,9 +0,0 @@
-<?php
-
-namespace ActiveCollab\Etcd\Exception;
-
-/**
- * @author Cong Peijun <p.cong@linkorb.com>
- */
-class KeyNotFoundException extends EtcdException implements ExceptionInterface {
-}
diff --git a/test/bin/build_etcd.sh b/test/bin/build_etcd.sh
deleted file mode 100644
index f768ebe..0000000
--- a/test/bin/build_etcd.sh
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/bash
-
-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
-export GOROOT=$PWD/go
-#export GOPATH=$PWD/go
-export PATH=$GOPATH/bin:$PATH
-go get golang.org/x/tools/cmd/cove
-go get golang.org/x/tools/cmd/vet
-cd etcd && ./build
-
-# Start etcd
-./bin/etcd > /dev/null 2>&1 &
\ No newline at end of file
diff --git a/test/src/ClientTest.php b/test/src/ClientTest.php
deleted file mode 100644
index 49b0d65..0000000
--- a/test/src/ClientTest.php
+++ /dev/null
@@ -1,205 +0,0 @@
-<?php
-
-namespace ActiveCollab\Etcd\Tests\Etcd;
-
-use ActiveCollab\Etcd\Client;
-use ActiveCollab\Etcd\ClientInterface;
-use ActiveCollab\Etcd\Exception\EtcdException;
-
-/**
- * @package ActiveCollab\Etcd\Tests\Etcd
- */
-class ClientTest extends \PHPUnit\Framework\TestCase {
- /**
- * @var Client
- */
- protected $client;
-
- /**
- * @var string
- */
- private $dirname = '/phpunit_test';
-
- /**
- * @inheritDoc
- */
- protected function setUp(): void {
- $this->client = new Client();
-
- $this->client->setSandboxPath( '/' );
-
- try {
- $this->client->removeDir( $this->dirname, true );
- } catch ( EtcdException $e ) {
- }
-
- $create_dir = $this->client->createDir( $this->dirname );
-
- $this->assertIsArray( $create_dir );
- $this->assertEquals( 'create', $create_dir['action'] );
- $this->assertIsArray( $create_dir['node'] );
- $this->assertTrue( $create_dir['node']['dir'] );
-
- $this->client->setSandboxPath( $this->dirname );
- }
-
- /**
- * @inheritDoc
- */
- protected function tearDown(): void {
- try {
- $this->client->removeDir( $this->dirname, true );
- } catch ( EtcdException $e ) {
- }
- }
-
- public function testExists() {
- $this->assertFalse( $this->client->exists( '/testgetvalue' ) );
- $this->client->set( '/testgetvalue', 'getvalue' );
- $this->assertTrue( $this->client->exists( '/testgetvalue' ) );
- }
-
- public function testExistsOnlyChecksForValues() {
- $this->assertFalse( $this->client->exists( '/testgetvalue' ) );
- $this->client->createDir( '/testgetvalue' );
- $this->assertFalse( $this->client->exists( '/testgetvalue' ) );
- }
-
- public function testDirExists() {
- $this->assertFalse( $this->client->dirExists( '/testdir' ) );
- $this->client->createDir( '/testdir' );
- $this->assertTrue( $this->client->dirExists( '/testdir' ) );
- }
-
- public function testDirExistsChecksForDirs() {
- $this->assertFalse( $this->client->dirExists( '/testdir' ) );
- $this->client->set( '/testdir', 'getvalue' );
- $this->assertFalse( $this->client->dirExists( '/testdir' ) );
- }
-
- public function testGet() {
- $this->client->set( '/testgetvalue', 'getvalue' );
- $value = $this->client->get( '/testgetvalue' );
- $this->assertEquals( 'getvalue', $value );
- }
-
- public function testSet() {
- $this->client->set( '/testset', 'setvalue' );
- $this->assertEquals( 'setvalue', $this->client->get( '/testset' ) );
- }
-
- public function testSetWithTtl() {
- $ttl = 10;
-
- $this->client->set( 'testttl', 'ttlvalue', $ttl );
- $this->assertLessThanOrEqual( $ttl, $this->client->getNode( 'testttl' )['ttl'] );
- }
-
- public function testCreate() {
- $this->client->create( 'testmk', 'mkvalue' );
- $this->assertEquals( 'mkvalue', $this->client->get( 'testmk' ) );
- $this->expectException( \ActiveCollab\Etcd\Exception\KeyExistsException::class );
- $this->client->create( 'testmk', 'mkvalue' );
- }
-
- public function testCreateDir() {
- $this->client->createDir( 'testmkdir' );
- $this->expectException( \ActiveCollab\Etcd\Exception\KeyExistsException::class );
- $this->client->createDir( 'testmkdir' );
- }
-
- public function testUpdate() {
- $key = '/testupdate_key';
- $value1 = 'value1';
- $value2 = 'value2';
- $this->expectException( \ActiveCollab\Etcd\Exception\KeyNotFoundException::class );
- $this->client->update( $key, $value1 );
-
- $this->client->set( $key, $value2 );
- $value = $this->client->get( $key );
- $this->assertEquals( 'value2', $value );
- }
-
- public function testUpdatedir() {
- $dirname = '/test_updatedir';
-
- $this->client->createDir( $dirname );
- $this->client->updateDir( $dirname, 10 );
-
- $dir = $this->client->dirInfo( $dirname );
- $this->assertLessThanOrEqual( 10, $dir['node']['ttl'] );
- }
-
- public function testRemove() {
- $this->expectException( \ActiveCollab\Etcd\Exception\EtcdException::class );
- $this->client->remove( '/rmkey' );
- }
-
- public function testRemoveDir() {
- $this->client->createDir( 'testrmdir' );
- $this->client->removeDir( 'testrmdir', true );
- $this->expectException( \ActiveCollab\Etcd\Exception\EtcdException::class );
- $this->client->removeDir( 'testrmdir' );
- }
-
- public function testListDir() {
- $data = $this->client->dirInfo();
-
- $this->assertEquals( $this->dirname, $data['node']['key'] );
- $this->assertTrue( $data['node']['dir'] == 1 );
- }
-
- public function testListSubdirs() {
- $dirs = $this->client->listSubdirs();
- $this->assertContains( $this->dirname, $dirs );
- }
-
- public function testGetKeysValueMap() {
- $this->client->set( '/a/aa', 'a_a' );
- $this->client->set( '/a/ab', 'a_b' );
- $this->client->set( '/a/b/ab', 'aa_b' );
-
- $values = $this->client->getKeyValueMap( '/', false );
- $this->assertFalse( isset( $values[$this->dirname . '/a/aa'] ) );
-
- $values = $this->client->getKeyValueMap();
- $this->assertTrue( isset( $values[$this->dirname . '/a/aa'] ) );
- $this->assertEquals( 'a_a', $values[$this->dirname . '/a/aa'] );
- $this->assertContains( 'aa_b', $values );
- }
-
- public function testGetNode() {
- $key = 'node_key';
- $setdata = $this->client->set( $key, 'node_value' );
- $node = $this->client->getNode( $key );
- $this->assertJsonStringEqualsJsonString( json_encode( $node ), json_encode( $setdata['node'] ) );
- }
-
- /**
- * Test sandboxed call with absolute path
- */
- public function testSandboxedCall() {
- $this->assertFalse( $this->client->exists( 'sub/value' ) );
-
- $this->client->sandboxed( '/phpunit_test/sub', static function ( ClientInterface &$c ) {
- $c->set( 'value', 123 );
- } );
-
- $this->assertTrue( $this->client->exists( 'sub/value' ) );
- $this->assertSame( '123', $this->client->get( 'sub/value' ) );
- }
-
- /**
- * Test sandboxed call with relative path
- */
- public function testRelativeSandboxedCall() {
- $this->assertFalse( $this->client->exists( 'sub/value' ) );
-
- $this->client->sandboxed( './sub', static function ( ClientInterface &$c ) {
- $c->set( 'value', 123 );
- } );
-
- $this->assertTrue( $this->client->exists( 'sub/value' ) );
- $this->assertSame( '123', $this->client->get( 'sub/value' ) );
- }
-}
diff --git a/test/src/SettingsTest.php b/test/src/SettingsTest.php
deleted file mode 100644
index d4d02eb..0000000
--- a/test/src/SettingsTest.php
+++ /dev/null
@@ -1,140 +0,0 @@
-<?php
-
-namespace ActiveCollab\Etcd\Tests\Etcd;
-
-use ActiveCollab\Etcd\Client;
-
-/**
- * @package ActiveCollab\Etcd\Tests\Etcd
- */
-class SettingsTest extends \PHPUnit\Framework\TestCase {
- /**
- * Test default server value
- */
- public function testDefaultServer() {
- $this->assertEquals( 'http://127.0.0.1:2379', ( new Client() )->getServer() );
- }
-
- /**
- * Test set server
- */
- public function testSetServer() {
- $this->assertEquals(
- 'http://localhost:2379',
- ( new Client() )->setServer( 'http://localhost:2379/' )->getServer()
- );
- }
-
- public function testSetInvalidServerUrlException() {
- $this->expectException( \InvalidArgumentException::class );
- new Client( 'invalid server url' );
- }
-
- /**
- * Test automatic detection of HTTPS
- */
- public function testHttpsDetection() {
- $reflection = new \ReflectionClass( Client::class );
- $is_https_property = $reflection->getProperty( 'is_https' );
- $is_https_property->setAccessible( true );
-
- $this->assertFalse( $is_https_property->getValue( new Client( 'http://127.0.0.1:2379' ) ) );
- $this->assertTrue( $is_https_property->getValue( new Client( 'https://127.0.0.1:2379' ) ) );
- }
-
- /**
- * Test verify SSL peer can be
- */
- public function testVerifySslPeerCanBeSet() {
- $this->assertTrue( ( new Client() )->getVerifySslPeer() );
- $this->assertFalse( ( new Client() )->verifySslPeer( false )->getVerifySslPeer() );
- }
-
- public function testExceptionOnMissingCustomCaFile() {
- $this->expectException( \InvalidArgumentException::class );
- ( new Client() )->verifySslPeer( true, 'not a file' );
- }
-
- /**
- * Test custom CA file can be set
- */
- public function testCustomCaFileCanBeSet() {
- $this->assertEquals(
- __FILE__,
- ( new Client() )->verifySslPeer( true, __FILE__ )->getCustomCaFile()
- );
- }
-
- public function testExceptionOnCustomCaFileWhenPeerIsNotVeified() {
- $this->expectException( \LogicException::class );
- ( new Client() )->verifySslPeer( false, __FILE__ )->getCustomCaFile();
- }
-
- /**
- * Test default sandbox path value
- */
- public function testDefaultSandboxPath() {
- $this->assertEquals( '/', ( new Client() )->getSandboxPath() );
- }
-
- /**
- * Test if sandbox path path is properly set
- */
- public function testSetSandboxPath() {
- $this->assertEquals( '/root', ( new Client() )->setSandboxPath( 'root' )->getSandboxPath() );
- $this->assertEquals( '/root', ( new Client() )->setSandboxPath( 'root/' )->getSandboxPath() );
- $this->assertEquals( '/root', ( new Client() )->setSandboxPath( '/root/' )->getSandboxPath() );
- $this->assertEquals(
- '/a/bit/deeper/path',
- ( new Client() )->setSandboxPath( '/a/bit/deeper/path/' )->getSandboxPath()
- );
- }
-
- /**
- * Test default API version
- */
- public function testDefaultApiVersion() {
- $this->assertEquals( 'v2', ( new Client() )->getApiVersion() );
- }
-
- /**
- * Test set API version
- */
- public function testSetApiVersion() {
- $this->assertEquals( 'v7', ( new Client() )->setApiVersion( 'v7' )->getApiVersion() );
- }
-
- /**
- * Test if API version is used in key path
- */
- public function testApiVersionIsUsedInKeyPath() {
- $this->assertEquals( '/v2/keys/path/to/key', ( new Client() )->getKeyPath( 'path/to/key' ) );
- $this->assertEquals(
- '/v7/keys/path/to/key', ( new Client() )->setApiVersion( 'v7' )->getKeyPath( 'path/to/key' )
- );
- }
-
- /**
- * Test if sandbox path is used in key path
- */
- public function testSandboxPathIsUsedInKeyPath() {
- $this->assertEquals( '/v2/keys/path/to/key', ( new Client() )->getKeyPath( 'path/to/key' ) );
- $this->assertEquals(
- '/v2/keys/root/is/cool/path/to/key',
- ( new Client() )->setSandboxPath( 'root/is/cool' )->getKeyPath( 'path/to/key' )
- );
- }
-
- /**
- * Test how things fit together
- */
- public function testGetKeyUrl() {
- $client = ( new Client( 'http://localhost:2379', 'v7' ) )->setSandboxPath( 'awesome/root' );
- $this->assertInstanceOf( Client::class, $client );
-
- $this->assertEquals(
- 'http://localhost:2379/v7/keys/awesome/root/path/to/key',
- $client->getKeyUrl( 'path/to/key' )
- );
- }
-}
diff --git a/test/src/VersionTest.php b/test/src/VersionTest.php
deleted file mode 100644
index 0fc1ac1..0000000
--- a/test/src/VersionTest.php
+++ /dev/null
@@ -1,21 +0,0 @@
-<?php
-
-namespace ActiveCollab\Etcd\Tests\Etcd;
-
-use ActiveCollab\Etcd\Client;
-
-/**
- * @package ActiveCollab\Etcd\Tests\Etcd
- */
-class VersionTest extends \PHPUnit\Framework\TestCase {
- /**
- * @covers LinkORB\Component\Etcd\Client::doRequest
- */
- public function testGetVersion() {
- $version = ( new Client() )->geVersion();
-
- $this->assertIsArray( $version );
- $this->assertArrayHasKey( 'etcdserver', $version );
- $this->assertArrayHasKey( 'etcdcluster', $version );
- }
-}