-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #151 from bennetgallein/feat/tsig-keys
feat: implement TSIGKey API
- Loading branch information
Showing
10 changed files
with
714 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Exonet\Powerdns\Resources; | ||
|
||
class TSIGKey | ||
{ | ||
/** | ||
* The name of the key. | ||
* | ||
* @var string | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* The ID for this key, used in the TSIGkey URL endpoint. | ||
* | ||
* @var string | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* The algorithm of the TSIG key. | ||
* | ||
* @var string | ||
*/ | ||
private $algorithm; | ||
|
||
/** | ||
* The Base64 encoded secret key, empty when listing keys. MAY be empty when POSTing to have the server generate the key material. | ||
* | ||
* @var string | ||
*/ | ||
private $key; | ||
|
||
/** | ||
* Set to "TSIGKey". | ||
* | ||
* @var string | ||
*/ | ||
private $type = 'TSIGKey'; | ||
|
||
/** | ||
* Record constructor. | ||
* | ||
* @param string $content Optional content to set. | ||
*/ | ||
public function __construct(?array $content = null) | ||
{ | ||
if ($content) { | ||
$this->setName($content['name'] ?? ''); | ||
$this->setId($content['id'] ?? ''); | ||
$this->setAlgorithm($content['algorithm'] ?? ''); | ||
$this->setKey($content['key'] ?? ''); | ||
$this->setType('TSIGKey'); | ||
} | ||
} | ||
|
||
/** | ||
* Get set to "TSIGKey". | ||
* | ||
* @return string | ||
*/ | ||
public function getType() | ||
{ | ||
return $this->type; | ||
} | ||
|
||
/** | ||
* Get the Base64 encoded secret key, empty when listing keys. MAY be empty when POSTing to have the server generate the key material. | ||
* | ||
* @return string | ||
*/ | ||
public function getKey() | ||
{ | ||
return $this->key; | ||
} | ||
|
||
/** | ||
* Set the Base64 encoded secret key, empty when listing keys. MAY be empty when POSTing to have the server generate the key material. | ||
* | ||
* @param string $key The Base64 encoded secret key, empty when listing keys. MAY be empty when POSTing to have the server generate the key material | ||
* | ||
* @return self | ||
*/ | ||
public function setKey(string $key) | ||
{ | ||
$this->key = $key; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get the algorithm of the TSIG key. | ||
* | ||
* @return string | ||
*/ | ||
public function getAlgorithm() | ||
{ | ||
return $this->algorithm; | ||
} | ||
|
||
/** | ||
* Set the algorithm of the TSIG key. | ||
* | ||
* @param string $algorithm The algorithm of the TSIG key | ||
* | ||
* @return self | ||
*/ | ||
public function setAlgorithm(string $algorithm) | ||
{ | ||
$this->algorithm = $algorithm; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get the ID for this key, used in the TSIGkey URL endpoint. | ||
* | ||
* @return string | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* Set the ID for this key, used in the TSIGkey URL endpoint. | ||
* | ||
* @param string $id The ID for this key, used in the TSIGkey URL endpoint. | ||
* | ||
* @return self | ||
*/ | ||
public function setId(string $id) | ||
{ | ||
$this->id = $id; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get the name of the key. | ||
* | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* Set the name of the key. | ||
* | ||
* @param string $name The name of the key | ||
* | ||
* @return self | ||
*/ | ||
public function setName(string $name) | ||
{ | ||
$this->name = $name; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Exonet\Powerdns\Resources; | ||
|
||
use ArrayAccess; | ||
use ArrayIterator; | ||
use Closure; | ||
use IteratorAggregate; | ||
use ReturnTypeWillChange; | ||
|
||
class TSIGKeySet implements IteratorAggregate, ArrayAccess | ||
{ | ||
/** | ||
* @var TSIGKey[] Array containing resources. | ||
*/ | ||
private $tsigResources = []; | ||
|
||
/** | ||
* TSIGKeySet constructor. | ||
* | ||
* @param array|null $resourceRecords (Optional) The tsigkey resources to add. | ||
*/ | ||
public function __construct(?array $resourceRecords = null) | ||
{ | ||
if ($resourceRecords) { | ||
$this->tsigResources = $resourceRecords; | ||
} | ||
} | ||
|
||
/** | ||
* Add a single tsigkey resource to the existing collection. | ||
* | ||
* @param TSIGKey $metaResource The tsigkey resource to add. | ||
* | ||
* @return TSIGKeySet The current TSIGKeySet instance. | ||
*/ | ||
public function addResource(TSIGKey $metaResource): self | ||
{ | ||
$this->tsigResources[] = $metaResource; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get the number of tsigkey resources in this collection. | ||
* | ||
* @return int The number of tsigkey resources. | ||
*/ | ||
public function count(): int | ||
{ | ||
return count($this->tsigResources); | ||
} | ||
|
||
/** | ||
* Check if the current collection is not empty. | ||
* | ||
* @return bool True when there are tsigkey resources in this collection. | ||
*/ | ||
public function isNotEmpty(): bool | ||
{ | ||
return !$this->isEmpty(); | ||
} | ||
|
||
/** | ||
* Check if the current collection is empty. | ||
* | ||
* @return bool True when there are no tsigkey resources in this collection. | ||
*/ | ||
public function isEmpty(): bool | ||
{ | ||
return empty($this->tsigResources); | ||
} | ||
|
||
/** | ||
* Loop through the collection and call the given closure for each tsigkey resource. | ||
* | ||
* @param Closure $closure The closure to execute for each tsigkey resource. | ||
* | ||
* @return TSIGKeySet The current TSIGKeySet instance. | ||
*/ | ||
public function map(Closure $closure): self | ||
{ | ||
foreach ($this->tsigResources as $index => $resource) { | ||
$this->tsigResources[$index] = $closure($resource, $index); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Delete all tsigkey resources that are set in the current collection. | ||
* | ||
* @return bool True when the tsigkey resources are deleted. | ||
*/ | ||
public function delete(): bool | ||
{ | ||
foreach ($this->tsigResources as $resource) { | ||
$resource->delete(); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getIterator(): ArrayIterator | ||
{ | ||
return new ArrayIterator($this->tsigResources); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function offsetExists($offset): bool | ||
{ | ||
return isset($this->tsigResources[$offset]); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @return TSIGKey | ||
*/ | ||
#[ReturnTypeWillChange] | ||
public function offsetGet($offset) | ||
{ | ||
return $this->tsigResources[$offset]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function offsetSet($offset, $value): void | ||
{ | ||
$this->tsigResources[$offset] = $value; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function offsetUnset($offset): void | ||
{ | ||
unset($this->tsigResources[$offset]); | ||
} | ||
} |
Oops, something went wrong.