Skip to content

Commit

Permalink
some bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dcarbone committed Feb 10, 2021
1 parent 3dea915 commit e90719c
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 81 deletions.
6 changes: 3 additions & 3 deletions src/ACL/ACLClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function Clone(string $id, ?WriteOptions $opts = null): ValuedWriteString
*/
public function Info(string $id, ?QueryOptions $opts = null): ACLEntriesResponse
{
$resp = $this->_doGet(\sprintf('v1/acl/info/%s', $id), $opts);
$resp = $this->_requireOK($this->_doGet(\sprintf('v1/acl/info/%s', $id), $opts));
$ret = new ACLEntriesResponse();
$this->_hydrateResponse($resp, $ret);
return $ret;
Expand All @@ -105,7 +105,7 @@ public function Info(string $id, ?QueryOptions $opts = null): ACLEntriesResponse
*/
public function List(?QueryOptions $opts = null): ACLEntriesResponse
{
$resp = $this->_doGet('v1/acl/list', $opts);
$resp = $this->_requireOK($this->_doGet('v1/acl/list', $opts));
$ret = new ACLEntriesResponse();
$this->_hydrateResponse($resp, $ret);
return $ret;
Expand All @@ -119,7 +119,7 @@ public function List(?QueryOptions $opts = null): ACLEntriesResponse
*/
public function Replication(?QueryOptions $opts = null): ACLReplicationStatusResponse
{
$resp = $this->_doGet('/v1/acl/replication', $opts);
$resp = $this->_requireOK($this->_doGet('/v1/acl/replication', $opts));
$ret = new ACLReplicationStatusResponse();
$this->_hydrateResponse($resp, $ret);
return $ret;
Expand Down
4 changes: 4 additions & 0 deletions src/AbstractModels.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ public function count(): int
*/
public function jsonSerialize(): array
{
if (0 === $this->_size) {
return [];
}

$out = [];
foreach ($this->_list as $i => $item) {
if (null === $item) {
Expand Down
6 changes: 3 additions & 3 deletions src/Agent/AgentClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function Self(bool $refresh = false): MapResponse
if (!$refresh && isset($this->_self)) {
return $this->_self;
}
$resp = $this->_doGet('v1/agent/self', null);
$resp = $this->_requireOK($this->_doGet('v1/agent/self', null));
$ret = new MapResponse();
$this->_hydrateResponse($resp, $ret);
if (null === $ret->Err) {
Expand Down Expand Up @@ -75,7 +75,7 @@ public function Host(): MapResponse
*/
public function Metrics(): MetricsInfoResponse
{
$resp = $this->_doGet('v1/agent/metrics', null);
$resp = $this->_requireOK($this->_doGet('v1/agent/metrics', null));
$ret = new MetricsInfoResponse();
$this->_hydrateResponse($resp, $ret);
return $ret;
Expand Down Expand Up @@ -265,7 +265,7 @@ public function Service(string $serviceID, ?QueryOptions $opts = null): AgentSer
*/
public function Members(): AgentMembersResponse
{
$resp = $this->_doGet('v1/agent/members', null);
$resp = $this->_requireOK($this->_doGet('v1/agent/members', null));
$ret = new AgentMembersResponse();
$this->_hydrateResponse($resp, $ret);
return $ret;
Expand Down
14 changes: 7 additions & 7 deletions src/Agent/AgentServiceCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class AgentServiceCheck extends AbstractModel
private const FIELD_TCP = 'TCP';
private const FIELD_STATUS = 'Status';
private const FIELD_NOTES = 'Notes';
private const FIELD_TLS_SKIP_VERIFY = 'TLSSKipVerify';
private const FIELD_TLS_SKIP_VERIFY = 'TLSSkipVerify';
private const FIELD_GRPC = 'GRPC';
private const FIELD_GRPC_USE_TLS = 'GRPCUseTLS';
private const FIELD_ALIAS_NODE = 'AliasNode';
Expand Down Expand Up @@ -117,7 +117,7 @@ class AgentServiceCheck extends AbstractModel
/** @var string */
public string $GRPC = '';
/** @var bool */
public bool $GRPCUseTL = false;
public bool $GRPCUseTLS = false;
/** @var string */
public string $AliasNode = '';
/** @var string */
Expand Down Expand Up @@ -421,18 +421,18 @@ public function setGRPC(string $GRPC): self
/**
* @return bool
*/
public function isGRPCUseTL(): bool
public function isGRPCUseTLS(): bool
{
return $this->GRPCUseTL;
return $this->GRPCUseTLS;
}

/**
* @param bool $GRPCUseTL
* @param bool $GRPCUseTLS
* @return \DCarbone\PHPConsulAPI\Agent\AgentServiceCheck
*/
public function setGRPCUseTL(bool $GRPCUseTL): self
public function setGRPCUseTLS(bool $GRPCUseTLS): self
{
$this->GRPCUseTL = $GRPCUseTL;
$this->GRPCUseTLS = $GRPCUseTLS;
return $this;
}

Expand Down
14 changes: 7 additions & 7 deletions src/Agent/AgentServiceRegistration.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class AgentServiceRegistration extends AbstractModel
],
self::FIELD_CHECKS => [
Hydration::FIELD_TYPE => Hydration::ARRAY,
Hydration::FIELD_CLASS => AgentServiceCheck::class,
Hydration::FIELD_CLASS => AgentServiceChecks::class,
Hydration::FIELD_ARRAY_TYPE => Hydration::OBJECT,
],
self::FIELD_PROXY => [
Expand Down Expand Up @@ -113,7 +113,7 @@ class AgentServiceRegistration extends AbstractModel
/** @var array */
public array $Meta = [];
/** @var \DCarbone\PHPConsulAPI\Agent\AgentWeights|null */
public ?AgentWeights $AgentWeights = null;
public ?AgentWeights $Weights = null;
/** @var \DCarbone\PHPConsulAPI\Agent\AgentServiceCheck|null */
public ?AgentServiceCheck $Check = null;
/** @var \DCarbone\PHPConsulAPI\Agent\AgentServiceChecks */
Expand Down Expand Up @@ -284,18 +284,18 @@ public function setMeta(array $Meta): self
/**
* @return \DCarbone\PHPConsulAPI\Agent\AgentWeights|null
*/
public function getAgentWeights(): ?AgentWeights
public function getWeights(): ?AgentWeights
{
return $this->AgentWeights;
return $this->Weights;
}

/**
* @param \DCarbone\PHPConsulAPI\Agent\AgentWeights|null $AgentWeights
* @param \DCarbone\PHPConsulAPI\Agent\AgentWeights|null $Weights
* @return \DCarbone\PHPConsulAPI\Agent\AgentServiceRegistration
*/
public function setAgentWeights(?AgentWeights $AgentWeights): self
public function setWeights(?AgentWeights $Weights): self
{
$this->AgentWeights = $AgentWeights;
$this->Weights = $Weights;
return $this;
}

Expand Down
12 changes: 6 additions & 6 deletions src/Catalog/CatalogClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function Deregister(CatalogDeregistration $catalogDeregistration, ?WriteO
*/
public function Datacenters(): ValuedStringsResponse
{
$resp = $this->_doGet('v1/catalog/datacenters', null);
$resp = $this->_requireOK($this->_doGet('v1/catalog/datacenters', null));
$ret = new ValuedStringsResponse();
$this->_hydrateResponse($resp, $ret);
return $ret;
Expand All @@ -74,7 +74,7 @@ public function Datacenters(): ValuedStringsResponse
*/
public function Nodes(?QueryOptions $opts = null): CatalogNodesResponse
{
$resp = $this->_doGet('v1/catalog/nodes', $opts);
$resp = $this->_requireOK($this->_doGet('v1/catalog/nodes', $opts));
$ret = new CatalogNodesResponse();
$this->_hydrateResponse($resp, $ret);
return $ret;
Expand All @@ -88,7 +88,7 @@ public function Nodes(?QueryOptions $opts = null): CatalogNodesResponse
*/
public function Services(?QueryOptions $opts = null): ValuedQueryStringsResponse
{
$resp = $this->_doGet('v1/catalog/services', $opts);
$resp = $this->_requireOK($this->_doGet('v1/catalog/services', $opts));
$ret = new ValuedQueryStringsResponse();
$this->_hydrateResponse($resp, $ret);
return $ret;
Expand All @@ -103,7 +103,7 @@ public function Services(?QueryOptions $opts = null): ValuedQueryStringsResponse
*/
public function NodeServicesList(string $node, ?QueryOptions $opts = null): CatalogNodeServicesListResponse
{
$resp = $this->_doGet(\sprintf('v1/catalog/node-services/%s', \urlencode($node)), $opts);
$resp = $this->_requireOK($this->_doGet(\sprintf('v1/catalog/node-services/%s', \urlencode($node)), $opts));
$ret = new CatalogNodeServicesListResponse();
$this->_hydrateResponse($resp, $ret);
return $ret;
Expand Down Expand Up @@ -153,7 +153,7 @@ public function Service(string $service, string $tag = '', ?QueryOptions $opts =
*/
public function Node(string $node, ?QueryOptions $opts = null): CatalogNodeResponse
{
$resp = $this->_doGet(\sprintf('v1/catalog/node/%s', $node), $opts);
$resp = $this->_requireOK($this->_doGet(\sprintf('v1/catalog/node/%s', $node), $opts));
$ret = new CatalogNodeResponse();
$this->_hydrateResponse($resp, $ret);
return $ret;
Expand All @@ -168,7 +168,7 @@ public function Node(string $node, ?QueryOptions $opts = null): CatalogNodeRespo
*/
public function GatewayServices(string $gateway, ?QueryOptions $opts = null): GatewayServicesResponse
{
$resp = $this->_doGet(\sprintf('v1/catalog/gateway-services/%s', \urlencode($gateway)), $opts);
$resp = $this->_requireOK($this->_doGet(\sprintf('v1/catalog/gateway-services/%s', \urlencode($gateway)), $opts));
$ret = new GatewayServicesResponse();
$this->_hydrateResponse($resp, $ret);
return $ret;
Expand Down
6 changes: 3 additions & 3 deletions src/Coordinate/CoordinateClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CoordinateClient extends AbstractClient
*/
public function Datacenters(): CoordinateDatacentersResponse
{
$resp = $this->_doGet('v1/coordinate/datacenters', null);
$resp = $this->_requireOK($this->_doGet('v1/coordinate/datacenters', null));
$ret = new CoordinateDatacentersResponse();
$this->_hydrateResponse($resp, $ret);
return $ret;
Expand All @@ -50,7 +50,7 @@ public function Datacenters(): CoordinateDatacentersResponse
*/
public function Nodes(?QueryOptions $opts = null): CoordinateEntriesResponse
{
$resp = $this->_doGet('v1/coordinate/nodes', $opts);
$resp = $this->_requireOK($this->_doGet('v1/coordinate/nodes', $opts));
$ret = new CoordinateEntriesResponse();
$this->_hydrateResponse($resp, $ret);
return $ret;
Expand All @@ -76,7 +76,7 @@ public function Update(CoordinateEntry $coordinateEntry, ?WriteOptions $opts = n
*/
public function Node(string $node, ?QueryOptions $opts = null): CoordinateEntriesResponse
{
$resp = $this->_doGet(\sprintf('v1/coordinate/node/%s', $node), $opts);
$resp = $this->_requireOK($this->_doGet(\sprintf('v1/coordinate/node/%s', $node), $opts));
$ret = new CoordinateEntriesResponse();
$this->_hydrateResponse($resp, $ret);
return $ret;
Expand Down
4 changes: 3 additions & 1 deletion src/Health/HealthClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,12 @@ public function State(string $state, ?QueryOptions $opts = null): HealthChecksRe
* @param string $path
* @param \DCarbone\PHPConsulAPI\QueryOptions|null $opts
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Exception
* @return \DCarbone\PHPConsulAPI\Health\HealthChecksResponse
*/
protected function _getHealthChecks(string $path, ?QueryOptions $opts): HealthChecksResponse
{
$resp = $this->_doGet($path, $opts);
$resp = $this->_requireOK($this->_doGet($path, $opts));
$ret = new HealthChecksResponse();
$this->_hydrateResponse($resp, $ret);
return $ret;
Expand All @@ -202,6 +203,7 @@ protected function _getHealthChecks(string $path, ?QueryOptions $opts): HealthCh
* @param \DCarbone\PHPConsulAPI\QueryOptions|null $opts
* @param string $healthType
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Exception
* @return \DCarbone\PHPConsulAPI\Health\ServiceEntriesResponse
*/
private function _getServiceEntries(
Expand Down
4 changes: 2 additions & 2 deletions src/KV/KVClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ public function Get(string $key, ?QueryOptions $opts = null): KVPairResponse

$code = $resp->Response->getStatusCode();

if (200 === $code) {
if (HTTP\StatusOK === $code) {
// success response
$dec = $this->_decodeBody($resp->Response->getBody());
if (null !== $dec->Err) {
$ret->Err = $dec->Err;
} else {
$ret->hydrateValue($dec->Decoded[0]);
}
} elseif (404 !== $code) {
} elseif (HTTP\StatusNotFound !== $code) {
$ret->Err = new Error(\sprintf('%s: %s', $code, $resp->Response->getReasonPhrase()));
}

Expand Down
30 changes: 17 additions & 13 deletions src/Operator/OperatorClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,27 @@ class OperatorClient extends AbstractClient
* @param \DCarbone\PHPConsulAPI\Operator\Area $area
* @param \DCarbone\PHPConsulAPI\WriteOptions|null $opts
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Exception
* @return \DCarbone\PHPConsulAPI\ValuedWriteStringResponse
*/
public function AreaCreate(Area $area, ?WriteOptions $opts = null): ValuedWriteStringResponse
{
return $this->_writeIDResponse($this->_doPost('v1/operator/area', $area, $opts));
return $this->_writeIDResponse($this->_requireOK($this->_doPost('v1/operator/area', $area, $opts)));
}

/**
* @param string $areaID
* @param \DCarbone\PHPConsulAPI\Operator\Area $area
* @param \DCarbone\PHPConsulAPI\WriteOptions|null $opts
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Exception
* @return \DCarbone\PHPConsulAPI\ValuedWriteStringResponse
*/
public function AreaUpdate(string $areaID, Area $area, ?WriteOptions $opts = null): ValuedWriteStringResponse
{
return $this->_writeIDResponse($this->_doPut(\sprintf('v1/operator/area/%s', $areaID), $area, $opts));
return $this->_writeIDResponse(
$this->_requireOK($this->_doPut(\sprintf('v1/operator/area/%s', $areaID), $area, $opts))
);
}

/**
Expand All @@ -64,7 +68,7 @@ public function AreaUpdate(string $areaID, Area $area, ?WriteOptions $opts = nul
*/
public function AreaGet(string $areaID, ?QueryOptions $opts = null): OperatorAreasResponse
{
$resp = $this->_doGet(\sprintf('v1/operator/area/%s', \urlencode($areaID)), $opts);
$resp = $this->_requireOK($this->_doGet(\sprintf('v1/operator/area/%s', \urlencode($areaID)), $opts));
$ret = new OperatorAreasResponse();
$this->_hydrateResponse($resp, $ret);
return $ret;
Expand All @@ -78,7 +82,7 @@ public function AreaGet(string $areaID, ?QueryOptions $opts = null): OperatorAre
*/
public function AreaList(?QueryOptions $opts = null): OperatorAreasResponse
{
$resp = $this->_doGet('v1/operator/area', $opts);
$resp = $this->_requireOK($this->_doGet('v1/operator/area', $opts));
$ret = new OperatorAreasResponse();
$this->_hydrateResponse($resp, $ret);
return $ret;
Expand All @@ -105,7 +109,7 @@ public function AreaDelete(string $areaID, ?WriteOptions $opts = null): WriteRes
*/
public function AreaJoin(string $areaID, array $addresses, ?WriteOptions $opts = null): OperatorAreaJoinResponse
{
$resp = $this->_doPut(\sprintf('v1/operator/area/%s/join', $areaID), $addresses, $opts);
$resp = $this->_requireOK($this->_doPut(\sprintf('v1/operator/area/%s/join', $areaID), $addresses, $opts));
$ret = new OperatorAreaJoinResponse();
$this->_hydrateResponse($resp, $ret);
return $ret;
Expand All @@ -120,7 +124,7 @@ public function AreaJoin(string $areaID, array $addresses, ?WriteOptions $opts =
*/
public function AreaMembers(string $areaID, ?QueryOptions $opts = null): OperatorSerfMembersResponse
{
$resp = $this->_doGet(\sprintf('v1/operator/area/%s/members', $areaID), $opts);
$resp = $this->_requireOK($this->_doGet(\sprintf('v1/operator/area/%s/members', $areaID), $opts));
$ret = new OperatorSerfMembersResponse();
$this->_hydrateResponse($resp, $ret);
return $ret;
Expand All @@ -134,7 +138,7 @@ public function AreaMembers(string $areaID, ?QueryOptions $opts = null): Operato
*/
public function AutopilotGetConfiguration(?QueryOptions $opts = null): OperatorAutopilotConfigurationResponse
{
$resp = $this->_doGet('v1/operator/autopilot/configuration', $opts);
$resp = $this->_requireOK($this->_doGet('v1/operator/autopilot/configuration', $opts));
$ret = new OperatorAutopilotConfigurationResponse();
$this->_hydrateResponse($resp, $ret);
return $ret;
Expand All @@ -148,7 +152,7 @@ public function AutopilotGetConfiguration(?QueryOptions $opts = null): OperatorA
*/
public function AutopilotSetConfiguration(AutopilotConfiguration $conf, ?WriteOptions $opts = null): ?Error
{
return $this->_doPut('v1/operator/autopilot/configuration', $conf, $opts)->Err;
return $this->_requireOK($this->_doPut('v1/operator/autopilot/configuration', $conf, $opts))->Err;
}

/**
Expand All @@ -162,7 +166,7 @@ public function AutopilotCASConfiguration(
AutopilotConfiguration $conf,
?WriteOptions $opts = null
): ValuedBoolResponse {
$resp = $this->_doPut('v1/operator/autopilot/configuration', $conf, $opts);
$resp = $this->_requireOK($this->_doPut('v1/operator/autopilot/configuration', $conf, $opts));
$ret = new ValuedBoolResponse();
$this->_hydrateResponse($resp, $ret);
return $ret;
Expand All @@ -176,7 +180,7 @@ public function AutopilotCASConfiguration(
*/
public function AutopilotServerHealth(?QueryOptions $opts = null): OperatorServerHealthsResponse
{
$resp = $this->_doGet('v1/operator/autopilot/health', $opts);
$resp = $this->_requireOK($this->_doGet('v1/operator/autopilot/health', $opts));
$ret = new OperatorServerHealthsResponse();
$this->_hydrateResponse($resp, $ret);
return $ret;
Expand All @@ -190,7 +194,7 @@ public function AutopilotServerHealth(?QueryOptions $opts = null): OperatorServe
*/
public function AutopilotState(?QueryOptions $opts = null): OperatorAutopilotStateResponse
{
$resp = $this->_doGet('v1/operator/autopilot/state', $opts);
$resp = $this->_requireOK($this->_doGet('v1/operator/autopilot/state', $opts));
$ret = new OperatorAutopilotStateResponse();
$this->_hydrateResponse($resp, $ret);
return $ret;
Expand All @@ -204,7 +208,7 @@ public function AutopilotState(?QueryOptions $opts = null): OperatorAutopilotSta
*/
public function RaftGetConfiguration(?QueryOptions $opts = null): OperatorRaftConfigurationResponse
{
$resp = $this->_doGet('v1/operator/raft/configuration', $opts);
$resp = $this->_requireOK($this->_doGet('v1/operator/raft/configuration', $opts));
$ret = new OperatorRaftConfigurationResponse();
$this->_hydrateResponse($resp, $ret);
return $ret;
Expand All @@ -227,8 +231,8 @@ public function RaftRemovePeerByAddress(string $address, ?WriteOptions $opts = n

/**
* @param \DCarbone\PHPConsulAPI\RequestResponse $resp
* @return \DCarbone\PHPConsulAPI\ValuedWriteStringResponse
* @throws \Exception
* @return \DCarbone\PHPConsulAPI\ValuedWriteStringResponse
*/
protected function _writeIDResponse(RequestResponse $resp): ValuedWriteStringResponse
{
Expand Down
Loading

0 comments on commit e90719c

Please sign in to comment.