Skip to content

Commit

Permalink
更新readme,优化输出结果
Browse files Browse the repository at this point in the history
  • Loading branch information
林以达 committed Sep 10, 2019
1 parent 878affa commit fb6a0af
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 165 deletions.
73 changes: 37 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ $this->consul->agent()->reload($reload);

// Enable Maintenance Mode
$maintenance = new Maintenance([
'enable' => 'true',
'enable' => true,
'reason' => 'whatever',
]);
$this->consul->agent()->maintenance($maintenance);
Expand Down Expand Up @@ -359,7 +359,7 @@ $this->consul->agent()->leave($leave);

// Force Leave and Shutdown
$forceLeave = new ForceLeave([
'node' => 'aaaaaaaaa'
'node' => 'consul'
]);
$this->consul->agent()->forceLeave($forceLeave);

Expand All @@ -374,7 +374,7 @@ $this->consul->agent()->token($token);
```php
// List Checks
$checks = new Checks([
'filter' => 'aaaa',
'filter' => '',
]);
$this->consul->agent()->checks($checks);

Expand Down Expand Up @@ -405,21 +405,21 @@ $this->consul->agent()->deRegister($deRegister);
// TTL Check Pass
$pass = new Pass([
'check_id' => 'Memory_utilization',
'note' => 'aaaaa',
'note' => 'consul',
]);
$this->consul->agent()->pass($pass);

// TTL Check Warn
$warn = new Warn([
'check_id' => 'Memory_utilization',
'note' => 'aaaaa',
'note' => 'consul',
]);
$this->consul->agent()->warn($warn);

// TTL Check Fail
$fail = new Fail([
'check_id' => 'Memory_utilization',
'note' => 'aaaaa',
'note' => 'consul',
]);
$this->consul->agent()->fail($fail);

Expand All @@ -441,20 +441,20 @@ $this->consul->agent()->services($services);

// Get Service Configuration
$service = new Service([
'service_id' => "register_consule"
'service_id' => "consul"
]);
$this->consul->agent()->service($service);

// Get local service health
$name = new Name([
'service_name' => 'register_consule',
'service_name' => 'consul',
'format' => 'text',
]);
$this->consul->agent()->name($name);

// Get local service health by its ID
$id = new ID([
'service_id' => 'register_consule',
'service_id' => 'consul',
'format' => 'text',
]);
$this->consul->agent()->id($id);
Expand Down Expand Up @@ -489,15 +489,15 @@ $this->consul->agent()->serviceRegister($register);

// Deregister Service
$deregister = new Service\DeRegister([
'service_id' => 'aaaaaa',
'service_id' => 'consul',
]);
$this->consul->agent()->serviceDeregister($deregister);

// Enable Maintenance Mode
$maintenance= new Service\Maintenance([
'service_id' => 'aaaaaa',
'service_id' => 'consul',
'enable' => true,
'reason' => 'bbbb'
'reason' => ''
]);
$this->consul->agent()->serviceMaintenance($maintenance);
```
Expand All @@ -517,7 +517,7 @@ $this->consul->agent()->roots($roots);

// Service Leaf Certificate
$leaf = new Leaf([
'service' => 'aaaa'
'service' => 'consul'
]);
$this->consul->agent()->leaf($leaf);
```
Expand Down Expand Up @@ -591,19 +591,20 @@ $this->consul->catalog()->dataCenters($datacenters);

// List Nodes
$nodes = new Nodes([
'node-meta' => 'a',
'dc' => 'b',
'near' => 'c',
'filter' => 'd',
'dc' => 'dc1',
'node-meta' => '',
'near' => '',
'filter' => '',
]);
$this->consul->catalog()->nodes($nodes);

// List Services
$nodes = new Nodes([
'node-meta' => 'a',
'dc' => 'b',
'near' => 'c',
'filter' => 'd',
$services = new Services([
'dc' => 'dc1',
'node-meta' => '',
]);
$this->consul->catalog()->services($services);
]);
$this->consul->catalog()->nodes($nodes);

Expand All @@ -617,30 +618,30 @@ $this->consul->catalog()->services($services);
// List Nodes for Connect-capable Service
$service = new Service([
'service' => 'consul',
'dc' => 'a',
'tag' => 'b',
'near' => 'c',
'node-meta' => 'd',
'filter' => 'e',
'dc' => 'dc1',
'tag' => '',
'near' => '',
'node-meta' => '',
'filter' => '',
]);
$this->consul->catalog()->service($service);

// List Services for Node
$connect = new Connect([
'service' => 'consul',
'dc' => 'a',
'tag' => 'b',
'near' => 'c',
'node-meta' => 'd',
'filter' => 'e',
'dc' => 'dc1',
'tag' => '',
'near' => '',
'node-meta' => '',
'filter' => '',
]);
$this->consul->catalog()->connect($connect);

// List Services for Node
$node = new Node([
'node' => '44e4656a94cd',
'dc' => 'a',
'filter' => 'b',
'node' => '2eb87046a6fe',
'dc' => 'dc1',
'filter' => '',
]);
$this->consul->catalog()->node($node);
```
Expand Down Expand Up @@ -719,8 +720,8 @@ $this->consul->connect()->listIntention($intentions);
$intentions = new Intentions([
'uuid' => 'b40faaf3-34aa-349f-3cf2-f5d720240662',
'description' => 'just a test description',
'SourceName' => 'aa',
'DestinationName' => 'bb',
'SourceName' => '',
'DestinationName' => '',
'Action' => 'allow'
]);
$this->consul->connect()->updateIntention($intentions);
Expand Down
31 changes: 8 additions & 23 deletions src/Agent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
namespace EasySwoole\Consul;

use EasySwoole\Consul\Exception\MissingRequiredParamsException;
use EasySwoole\Consul\Exception\WrongRequiredParamsException;
use EasySwoole\Consul\Exception\Exception;
use EasySwoole\Consul\Exception\InvalidRequiredParamsException;
use EasySwoole\Consul\Request\Agent\Check\Deregister;
use EasySwoole\Consul\Request\Agent\Check\Fail;
use EasySwoole\Consul\Request\Agent\Check\Pass;
Expand All @@ -14,7 +13,6 @@
use EasySwoole\Consul\Request\Agent\Connect\Authorize;
use EasySwoole\Consul\Request\Agent\Connect\Ca\Leaf;
use EasySwoole\Consul\Request\Agent\Connect\Ca\Roots;
use EasySwoole\Consul\Request\Agent\Connect\Proxy;
use EasySwoole\Consul\Request\Agent\ForceLeave;
use EasySwoole\Consul\Request\Agent\Health\Service\ID;
use EasySwoole\Consul\Request\Agent\Health\Service\Name;
Expand Down Expand Up @@ -73,7 +71,7 @@ public function maintenance(Maintenance $maintenance)
if (empty($maintenance->getEnable())) {
throw new MissingRequiredParamsException('Missing the required param: enable.');
}
$this->putJSON($maintenance);
$this->putJSON($maintenance , false);
}

/**
Expand Down Expand Up @@ -145,7 +143,7 @@ public function forceLeave(ForceLeave $forceLeave)
* Update ACL Tokens
* @param Token $token
* @throws MissingRequiredParamsException
* @throws WrongRequiredParamsException
* @throws InvalidRequiredParamsException
* @throws \EasySwoole\HttpClient\Exception\InvalidUrl
*/
public function token(Token $token)
Expand All @@ -164,7 +162,7 @@ public function token(Token $token)
throw new MissingRequiredParamsException('Missing the required param: action');
}
if (! in_array(strtolower(trim($token->getAction())), $actionArr)) {
throw new WrongRequiredParamsException('Wrong required param: action');
throw new InvalidRequiredParamsException('Wrong required param: action');
}
$token->setUrl(sprintf($token->getUrl(), $token->getAction()));
$token->setAction('');
Expand Down Expand Up @@ -192,6 +190,9 @@ public function register(Register $register)
if (empty($register->getName())) {
throw new MissingRequiredParamsException('Missing the required param: Name.');
}
if (empty($register->getTTL())) {
throw new MissingRequiredParamsException('Missing the required param: TTL.');
}
$this->putJSON($register);
}

Expand Down Expand Up @@ -374,7 +375,7 @@ public function serviceMaintenance(Service\Maintenance $maintenance)
if (empty($maintenance->getServiceID())) {
throw new MissingRequiredParamsException('Missing the required param: service_id.');
}
if (empty($maintenance->getEnable())) {
if ($maintenance->getEnable() === '' || $maintenance->getEnable() === null) {
throw new MissingRequiredParamsException('Missing the required param: enable.');
}
$maintenance->setUrl(sprintf($maintenance->getUrl(), $maintenance->getServiceID()));
Expand Down Expand Up @@ -427,20 +428,4 @@ public function leaf(Leaf $leaf)
$leaf->setService('');
$this->getJson($leaf);
}

/**
* Managed Proxy Configuration (Deprecated)
* @param Proxy $proxy
* @throws MissingRequiredParamsException
* @throws \EasySwoole\HttpClient\Exception\InvalidUrl
*/
public function proxy(Proxy $proxy)
{
if (empty($proxy->getId())) {
throw new MissingRequiredParamsException('Missing the required param: ID.');
}
$proxy->setUrl(sprintf($proxy->getUrl(), $proxy->getId()));
$proxy->setId('');
$this->getJson($proxy);
}
}
Loading

0 comments on commit fb6a0af

Please sign in to comment.