Skip to content

Commit 7605578

Browse files
committed
ACL features + cleanup
- Added "replication" endpoint to ACLClient - Renamed "$queryOptions" and "$writeOptions" to "$options" - Added some tests for AgentClient - Misc cleanup
1 parent dcd16b0 commit 7605578

23 files changed

+556
-725
lines changed

phpunit.local.xml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,23 @@
1818
<env name="CONSUL_HTTP_SSL" value="0"/>
1919
</php>
2020

21-
<testsuite name="definition">
22-
<directory>./tests/Definition</directory>
23-
<directory>./tests/Usage</directory>
24-
</testsuite>
21+
<testsuites>
22+
<testsuite name="definition">
23+
<directory>./tests/Definition</directory>
24+
</testsuite>
25+
26+
<testsuite name="usage-config">
27+
<file>./tests/Usage/ConfigUsageTest.php</file>
28+
</testsuite>
29+
30+
<testsuite name="usage-kv">
31+
<file>./tests/usage/KV/KVClientCRUDTests.php</file>
32+
</testsuite>
33+
34+
<testsuite name="usage-agent">
35+
<file>./tests/Usage/Agent/AgentClientUsageTests.php</file>
36+
</testsuite>
37+
</testsuites>
2538

2639
<filter>
2740
<whitelist addUncoveredFilesFromWhitelist="true">

phpunit.xml.dist

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,20 @@
1818
<env name="CONSUL_HTTP_SSL" value="0"/>
1919
</php>
2020

21-
<testsuite name="definition">
22-
<directory>./tests/Definition</directory>
23-
<directory>./tests/Usage</directory>
24-
</testsuite>
21+
<testsuites>
22+
<testsuite name="definition">
23+
<directory>./tests/Definition</directory>
24+
</testsuite>
25+
26+
<testsuite name="usage-config">
27+
<file>./tests/Usage/ConfigUsageTest.php</file>
28+
</testsuite>
29+
30+
<testsuite name="usage-kv">
31+
<file>./tests/usage/KV/KVClientCRUDTests.php</file>
32+
33+
</testsuite>
34+
</testsuites>
2535

2636
<filter>
2737
<whitelist addUncoveredFilesFromWhitelist="true">

src/ACL/ACLClient.php

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@
2828
class ACLClient extends AbstractClient {
2929
/**
3030
* @param \DCarbone\PHPConsulAPI\ACL\ACLEntry $acl
31-
* @param \DCarbone\PHPConsulAPI\WriteOptions|null $writeOptions
31+
* @param \DCarbone\PHPConsulAPI\WriteOptions|null $options
3232
* @return array(
3333
* @type string ACL ID
3434
* @type \DCarbone\PHPConsulAPI\WriteMeta write meta data
3535
* @type \DCarbone\PHPConsulAPI\Error|null error, if any
3636
* )
3737
*/
38-
public function create(ACLEntry $acl, WriteOptions $writeOptions = null) {
39-
$r = new Request('put', 'v1/acl/create', $this->c, $acl);
40-
$r->setWriteOptions($writeOptions);
38+
public function create(ACLEntry $acl, WriteOptions $options = null) {
39+
$r = new Request('PUT', 'v1/acl/create', $this->c, $acl);
40+
$r->setWriteOptions($options);
4141

4242
/** @var \Psr\Http\Message\ResponseInterface $response */
4343
list($duration, $response, $err) = $this->requireOK($this->doRequest($r));
@@ -57,15 +57,15 @@ public function create(ACLEntry $acl, WriteOptions $writeOptions = null) {
5757

5858
/**
5959
* @param \DCarbone\PHPConsulAPI\ACL\ACLEntry $acl
60-
* @param \DCarbone\PHPConsulAPI\WriteOptions|null $writeOptions
60+
* @param \DCarbone\PHPConsulAPI\WriteOptions|null $options
6161
* @return array(
6262
* @type \DCarbone\PHPConsulAPI\WriteMeta
6363
* @type \DCarbone\PHPConsulAPI\Error|null error, if any
6464
* )
6565
*/
66-
public function update(ACLEntry $acl, WriteOptions $writeOptions = null) {
66+
public function update(ACLEntry $acl, WriteOptions $options = null) {
6767
$r = new Request('PUT', 'v1/acl/update', $this->c, $acl);
68-
$r->setWriteOptions($writeOptions);
68+
$r->setWriteOptions($options);
6969

7070
list($duration, $_, $err) = $this->requireOK($this->doRequest($r));
7171

@@ -78,15 +78,15 @@ public function update(ACLEntry $acl, WriteOptions $writeOptions = null) {
7878

7979
/**
8080
* @param string $id
81-
* @param \DCarbone\PHPConsulAPI\WriteOptions|null $writeOptions
81+
* @param \DCarbone\PHPConsulAPI\WriteOptions|null $options
8282
* @return array(
8383
* @type \DCarbone\PHPConsulAPI\WriteMeta write meta data
8484
* @type \DCarbone\PHPConsulAPI\Error|null error, if any
8585
* )
8686
*/
87-
public function destroy($id, WriteOptions $writeOptions = null) {
87+
public function destroy($id, WriteOptions $options = null) {
8888
$r = new Request('PUT', sprintf('v1/acl/destroy/%s', $id), $this->c);
89-
$r->setWriteOptions($writeOptions);
89+
$r->setWriteOptions($options);
9090

9191
list($duration, $_, $err) = $this->requireOK($this->doRequest($r));
9292

@@ -99,16 +99,16 @@ public function destroy($id, WriteOptions $writeOptions = null) {
9999

100100
/**
101101
* @param string $id
102-
* @param \DCarbone\PHPConsulAPI\WriteOptions|null $writeOptions
102+
* @param \DCarbone\PHPConsulAPI\WriteOptions|null $options
103103
* @return array(
104104
* @type string cloned ACL id
105105
* @type \DCarbone\PHPConsulAPI\WriteMeta write meta data
106106
* @type \DCarbone\PHPConsulAPI\Error|null error, if any
107107
* )
108108
*/
109-
public function cloneACL($id, WriteOptions $writeOptions = null) {
109+
public function cloneACL($id, WriteOptions $options = null) {
110110
$r = new Request('PUT', sprintf('v1/acl/clone/%s', $id), $this->c);
111-
$r->setWriteOptions($writeOptions);
111+
$r->setWriteOptions($options);
112112

113113
/** @var \Psr\Http\Message\ResponseInterface $response */
114114
list($duration, $response, $err) = $this->requireOK($this->doRequest($r));
@@ -128,16 +128,16 @@ public function cloneACL($id, WriteOptions $writeOptions = null) {
128128

129129
/**
130130
* @param string $id
131-
* @param \DCarbone\PHPConsulAPI\QueryOptions|null $queryOptions
131+
* @param \DCarbone\PHPConsulAPI\QueryOptions|null $options
132132
* @return array(
133133
* @type \DCarbone\PHPConsulAPI\ACL\ACLEntry[]|null list of ACL entries corresponding to that ID, or null on error
134134
* @type \DCarbone\PHPConsulAPI\QueryMeta query meta data
135135
* @type \DCarbone\PHPConsulAPI\Error|null error, if any
136136
* )
137137
*/
138-
public function info($id, QueryOptions $queryOptions = null) {
138+
public function info($id, QueryOptions $options = null) {
139139
$r = new Request('GET', sprintf('v1/acl/info/%s', $id), $this->c);
140-
$r->setQueryOptions($queryOptions);
140+
$r->setQueryOptions($options);
141141

142142
/** @var \Psr\Http\Message\ResponseInterface $response */
143143
list($duration, $response, $err) = $this->requireOK($this->doRequest($r));
@@ -161,16 +161,16 @@ public function info($id, QueryOptions $queryOptions = null) {
161161
}
162162

163163
/**
164-
* @param \DCarbone\PHPConsulAPI\QueryOptions|null $queryOptions
164+
* @param \DCarbone\PHPConsulAPI\QueryOptions|null $options
165165
* @return array(
166166
* @type \DCarbone\PHPConsulAPI\ACL\ACLEntry[] acl entries or null on error
167167
* @type \DCarbone\PHPConsulAPI\QueryMeta query meta data
168168
* @type \DCarbone\PHPConsulAPI\Error|null error, if any
169169
* )
170170
*/
171-
public function listACLs(QueryOptions $queryOptions = null) {
171+
public function listACLs(QueryOptions $options = null) {
172172
$r = new Request('GET', 'v1/acl/list', $this->c);
173-
$r->setQueryOptions($queryOptions);
173+
$r->setQueryOptions($options);
174174

175175
/** @var \Psr\Http\Message\ResponseInterface $response */
176176
list($duration, $response, $err) = $this->requireOK($this->doRequest($r));
@@ -180,7 +180,6 @@ public function listACLs(QueryOptions $queryOptions = null) {
180180

181181
$qm = $this->buildQueryMeta($duration, $response, $r->getUri());
182182

183-
184183
list($data, $err) = $this->decodeBody($response->getBody());
185184
if (null !== $err) {
186185
return [null, $qm, $err];
@@ -193,4 +192,32 @@ public function listACLs(QueryOptions $queryOptions = null) {
193192

194193
return [$entries, $qm, null];
195194
}
195+
196+
/**
197+
* @param \DCarbone\PHPConsulAPI\QueryOptions|null $options
198+
* @return array(
199+
* @type \DCarbone\PHPConsulAPI\ACL\ACLReplicationStatus current replication status
200+
* @type \DCarbone\PHPConsulAPI\QueryMeta
201+
* @type \DCarbone\PHPConsulAPI\Error
202+
* )
203+
*/
204+
public function replication(QueryOptions $options = null) {
205+
$r = new Request('GET', '/v1/acl/replication', $this->c);
206+
$r->setQueryOptions($options);
207+
208+
/** @var \Psr\Http\Message\ResponseInterface $response */
209+
list($duration, $response, $err) = $this->requireOK($this->doRequest($r));
210+
if (null !== $err) {
211+
return [null, null, $err];
212+
}
213+
214+
$qm = $this->buildQueryMeta($duration, $response, $r->getUri());
215+
216+
list($data, $err) = $this->decodeBody($response->getBody());
217+
if (null !== $err) {
218+
return [null, $qm, $err];
219+
}
220+
221+
return [new ACLReplicationStatus($data), $qm, null];
222+
}
196223
}

src/ACL/ACLReplicationStatus.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php namespace DCarbone\PHPConsulAPI\ACL;
2+
3+
/*
4+
Copyright 2016-2017 Daniel Carbone ([email protected])
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
use DCarbone\PHPConsulAPI\AbstractModel;
20+
21+
/**
22+
* Class ACLReplicationStatus
23+
* @package DCarbone\PHPConsulAPI\ACL
24+
*/
25+
class ACLReplicationStatus extends AbstractModel {
26+
/** @var bool */
27+
public $Enabled = false;
28+
/** @var bool */
29+
public $Running = false;
30+
/** @var string */
31+
public $SourceDatacenter = '';
32+
/** @var int */
33+
public $ReplicatedIndex = 0;
34+
/** @var null|string */
35+
public $LastSuccess = null;
36+
/** @var null|string */
37+
public $LastError = null;
38+
39+
/**
40+
* @return bool
41+
*/
42+
public function isEnabled() {
43+
return $this->Enabled;
44+
}
45+
46+
/**
47+
* @return bool
48+
*/
49+
public function isRunning() {
50+
return $this->Running;
51+
}
52+
53+
/**
54+
* @return string
55+
*/
56+
public function getSourceDatacenter() {
57+
return $this->SourceDatacenter;
58+
}
59+
60+
/**
61+
* @return int
62+
*/
63+
public function getReplicatedIndex() {
64+
return $this->ReplicatedIndex;
65+
}
66+
67+
/**
68+
* @return null|string
69+
*/
70+
public function getLastSuccess() {
71+
return $this->LastSuccess;
72+
}
73+
74+
/**
75+
* @return null|string
76+
*/
77+
public function getLastError() {
78+
return $this->LastError;
79+
}
80+
}

src/AbstractModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
abstract class AbstractModel implements \JsonSerializable {
2424

2525
/**
26-
* AbstractObjectModel constructor.
26+
* AbstractModel constructor.
2727
*
2828
* Convenience method to help set scalar types. Any extending class must have a constructor that builds any
2929
* array / object properties it may have.

0 commit comments

Comments
 (0)