Skip to content

Commit

Permalink
feat: add support for CAA record types in DNS update request and zone…
Browse files Browse the repository at this point in the history
… record set

- Added CAA record type support to DnsUpdateRecordSetRequest.
- Updated DnsUpdateRecordSetRequestRecordSet enum to include CAA.
- Extended schema definitions in Zone and ZoneRecordSet to accommodate CAA records.
- Updated Contributor schema to make description optional and reflect changes in constructor and output.
- Introduced new fields for notes and successor ID in the ExtensionDeprecation schema.
  • Loading branch information
mittwald-machine committed Jan 28, 2025
1 parent 80c5cf7 commit 002ea81
Show file tree
Hide file tree
Showing 10 changed files with 660 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use InvalidArgumentException;
use JsonSchema\Validator;
use Mittwald\ApiClient\Generated\V2\Schemas\Dns\CombinedACustom;
use Mittwald\ApiClient\Generated\V2\Schemas\Dns\RecordCAAComponent;
use Mittwald\ApiClient\Generated\V2\Schemas\Dns\RecordCNAMEComponent;
use Mittwald\ApiClient\Generated\V2\Schemas\Dns\RecordMXCustom;
use Mittwald\ApiClient\Generated\V2\Schemas\Dns\RecordSRVComponent;
Expand Down Expand Up @@ -34,6 +35,7 @@ class DnsUpdateRecordSetRequest
'txt',
'srv',
'cname',
'caa',
],
'type' => 'string',
],
Expand All @@ -57,6 +59,9 @@ class DnsUpdateRecordSetRequest
[
'$ref' => '#/components/schemas/de.mittwald.v1.dns.RecordCNAMEComponent',
],
[
'$ref' => '#/components/schemas/de.mittwald.v1.dns.RecordCAAComponent',
],
],
],
],
Expand All @@ -71,13 +76,13 @@ class DnsUpdateRecordSetRequest

private DnsUpdateRecordSetRequestRecordSet $recordSet;

private RecordUnset|CombinedACustom|RecordMXCustom|RecordTXTComponent|RecordSRVComponent|RecordCNAMEComponent $body;
private RecordUnset|CombinedACustom|RecordMXCustom|RecordTXTComponent|RecordSRVComponent|RecordCNAMEComponent|RecordCAAComponent $body;

private array $headers = [

];

public function __construct(string $dnsZoneId, DnsUpdateRecordSetRequestRecordSet $recordSet, CombinedACustom|RecordCNAMEComponent|RecordMXCustom|RecordSRVComponent|RecordTXTComponent|RecordUnset $body)
public function __construct(string $dnsZoneId, DnsUpdateRecordSetRequestRecordSet $recordSet, CombinedACustom|RecordCAAComponent|RecordCNAMEComponent|RecordMXCustom|RecordSRVComponent|RecordTXTComponent|RecordUnset $body)
{
$this->dnsZoneId = $dnsZoneId;
$this->recordSet = $recordSet;
Expand All @@ -94,7 +99,7 @@ public function getRecordSet(): DnsUpdateRecordSetRequestRecordSet
return $this->recordSet;
}

public function getBody(): CombinedACustom|RecordCNAMEComponent|RecordMXCustom|RecordSRVComponent|RecordTXTComponent|RecordUnset
public function getBody(): CombinedACustom|RecordCAAComponent|RecordCNAMEComponent|RecordMXCustom|RecordSRVComponent|RecordTXTComponent|RecordUnset
{
return $this->body;
}
Expand All @@ -121,7 +126,7 @@ public function withRecordSet(DnsUpdateRecordSetRequestRecordSet $recordSet): se
return $clone;
}

public function withBody(CombinedACustom|RecordCNAMEComponent|RecordMXCustom|RecordSRVComponent|RecordTXTComponent|RecordUnset $body): self
public function withBody(CombinedACustom|RecordCAAComponent|RecordCNAMEComponent|RecordMXCustom|RecordSRVComponent|RecordTXTComponent|RecordUnset $body): self
{
$clone = clone $this;
$clone->body = $body;
Expand Down Expand Up @@ -153,6 +158,7 @@ public static function buildFromInput(array|object $input, bool $validate = true
RecordTXTComponent::validateInput($input->{'body'}, true) => RecordTXTComponent::buildFromInput($input->{'body'}, validate: $validate),
RecordSRVComponent::validateInput($input->{'body'}, true) => RecordSRVComponent::buildFromInput($input->{'body'}, validate: $validate),
RecordCNAMEComponent::validateInput($input->{'body'}, true) => RecordCNAMEComponent::buildFromInput($input->{'body'}, validate: $validate),
RecordCAAComponent::validateInput($input->{'body'}, true) => RecordCAAComponent::buildFromInput($input->{'body'}, validate: $validate),
default => throw new InvalidArgumentException("could not build property 'body' from JSON"),
};

Expand All @@ -172,7 +178,7 @@ public function toJson(): array
$output['dnsZoneId'] = $this->dnsZoneId;
$output['recordSet'] = ($this->recordSet)->value;
$output['body'] = match (true) {
($this->body) instanceof RecordUnset, ($this->body) instanceof CombinedACustom, ($this->body) instanceof RecordMXCustom, ($this->body) instanceof RecordTXTComponent, ($this->body) instanceof RecordSRVComponent, ($this->body) instanceof RecordCNAMEComponent => $this->body->toJson(),
($this->body) instanceof RecordUnset, ($this->body) instanceof CombinedACustom, ($this->body) instanceof RecordMXCustom, ($this->body) instanceof RecordTXTComponent, ($this->body) instanceof RecordSRVComponent, ($this->body) instanceof RecordCNAMEComponent, ($this->body) instanceof RecordCAAComponent => $this->body->toJson(),
};

return $output;
Expand Down Expand Up @@ -205,7 +211,7 @@ public static function validateInput(array|object $input, bool $return = false):
public function __clone()
{
$this->body = match (true) {
($this->body) instanceof RecordUnset, ($this->body) instanceof CombinedACustom, ($this->body) instanceof RecordMXCustom, ($this->body) instanceof RecordTXTComponent, ($this->body) instanceof RecordSRVComponent, ($this->body) instanceof RecordCNAMEComponent => $this->body,
($this->body) instanceof RecordUnset, ($this->body) instanceof CombinedACustom, ($this->body) instanceof RecordMXCustom, ($this->body) instanceof RecordTXTComponent, ($this->body) instanceof RecordSRVComponent, ($this->body) instanceof RecordCNAMEComponent, ($this->body) instanceof RecordCAAComponent => $this->body,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ enum DnsUpdateRecordSetRequestRecordSet: string
case txt = 'txt';
case srv = 'srv';
case cname = 'cname';
case caa = 'caa';
}
158 changes: 158 additions & 0 deletions src/Generated/V2/Schemas/Dns/RecordCAAComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<?php

declare(strict_types=1);

namespace Mittwald\ApiClient\Generated\V2\Schemas\Dns;

use InvalidArgumentException;
use JsonSchema\Validator;

/**
* Auto-generated class for de.mittwald.v1.dns.RecordCAAComponent.
*
* DO NOT EDIT; this class was generated by the mittwald/api-client-builder package
* (https://github.com/mittwald/api-client-php-builder). Please make any changes
* there.
*
* @generated
* @see https://github.com/mittwald/api-client-php-builder
*/
class RecordCAAComponent
{
/**
* Schema used to validate input for creating instances of this class
*/
private static array $schema = [
'additionalProperties' => false,
'properties' => [
'records' => [
'items' => [
'$ref' => '#/components/schemas/de.mittwald.v1.dns.RecordCAARecord',
],
'minItems' => 1,
'type' => 'array',
],
'settings' => [
'$ref' => '#/components/schemas/de.mittwald.v1.dns.RecordSettings',
],
],
'required' => [
'records',
'settings',
],
'type' => 'object',
];

/**
* @var RecordCAARecord[]
*/
private array $records;

private RecordSettings $settings;

/**
* @param RecordCAARecord[] $records
*/
public function __construct(array $records, RecordSettings $settings)
{
$this->records = $records;
$this->settings = $settings;
}

/**
* @return RecordCAARecord[]
*/
public function getRecords(): array
{
return $this->records;
}

public function getSettings(): RecordSettings
{
return $this->settings;
}

/**
* @param RecordCAARecord[] $records
*/
public function withRecords(array $records): self
{
$clone = clone $this;
$clone->records = $records;

return $clone;
}

public function withSettings(RecordSettings $settings): self
{
$clone = clone $this;
$clone->settings = $settings;

return $clone;
}

/**
* Builds a new instance from an input array
*
* @param array|object $input Input data
* @param bool $validate Set this to false to skip validation; use at own risk
* @return RecordCAAComponent Created instance
* @throws InvalidArgumentException
*/
public static function buildFromInput(array|object $input, bool $validate = true): RecordCAAComponent
{
$input = is_array($input) ? Validator::arrayToObjectRecursive($input) : $input;
if ($validate) {
static::validateInput($input);
}

$records = array_map(fn (array|object $i): RecordCAARecord => RecordCAARecord::buildFromInput($i, validate: $validate), $input->{'records'});
$settings = RecordSettings::buildFromInput($input->{'settings'}, validate: $validate);

$obj = new self($records, $settings);

return $obj;
}

/**
* Converts this object back to a simple array that can be JSON-serialized
*
* @return array Converted array
*/
public function toJson(): array
{
$output = [];
$output['records'] = array_map(fn (RecordCAARecord $i): array => $i->toJson(), $this->records);
$output['settings'] = $this->settings->toJson();

return $output;
}

/**
* Validates an input array
*
* @param array|object $input Input data
* @param bool $return Return instead of throwing errors
* @return bool Validation result
* @throws InvalidArgumentException
*/
public static function validateInput(array|object $input, bool $return = false): bool
{
$validator = new \Mittwald\ApiClient\Validator\Validator();
$input = is_array($input) ? Validator::arrayToObjectRecursive($input) : $input;
$validator->validate($input, self::$schema);

if (!$validator->isValid() && !$return) {
$errors = array_map(function (array $e): string {
return $e["property"] . ": " . $e["message"];
}, $validator->getErrors());
throw new InvalidArgumentException(join(", ", $errors));
}

return $validator->isValid();
}

public function __clone()
{
}
}
Loading

0 comments on commit 002ea81

Please sign in to comment.