|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the CwdPowerDNS Client |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2018 cwd.at GmbH <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Cwd\PowerDNSClient\Model; |
|
15
|
|
|
|
|
16
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
17
|
|
|
use Symfony\Component\Validator\Context\ExecutionContextInterface; |
|
18
|
|
|
|
|
19
|
|
|
class Metadata |
|
20
|
|
|
{ |
|
21
|
|
|
// https://doc.powerdns.com/md/httpapi/api_spec/#zone-metadata |
|
22
|
|
|
const UPDATE_FORBIDDEN = [ |
|
23
|
|
|
'NSEC3PARAM', |
|
24
|
|
|
'NSEC3NARROW', |
|
25
|
|
|
'PRESIGNED', |
|
26
|
|
|
'LUA-AXFR-SCRIPT', |
|
27
|
|
|
]; |
|
28
|
|
|
|
|
29
|
|
|
// https://doc.powerdns.com/authoritative/domainmetadata.html |
|
30
|
|
|
const VALID_KINDs = [ |
|
31
|
|
|
'ALLOW-AXFR-FROM', |
|
32
|
|
|
'API-RECTIFY', |
|
33
|
|
|
'AXFR-SOURCE', |
|
34
|
|
|
'ALLOW-DNSUPDATE-FROM', |
|
35
|
|
|
'TSIG-ALLOW-DNSUPDATE', |
|
36
|
|
|
'FORWARD-DNSUPDATE', |
|
37
|
|
|
'SOA-EDIT-DNSUPDATE', |
|
38
|
|
|
'NOTIFY-DNSUPDATE', |
|
39
|
|
|
'ALSO-NOTIFY', |
|
40
|
|
|
'AXFR-MASTER-TSIG', |
|
41
|
|
|
'GSS-ALLOW-AXFR-PRINCIPAL', |
|
42
|
|
|
'GSS-ACCEPTOR-PRINCIPAL', |
|
43
|
|
|
'IXFR', |
|
44
|
|
|
'LUA-AXFR-SCRIPT', |
|
45
|
|
|
'NSEC3NARROW', |
|
46
|
|
|
'NSEC3PARAM', |
|
47
|
|
|
'PRESIGNED', |
|
48
|
|
|
'PUBLISH-CDNSKEY', |
|
49
|
|
|
'PUBLISH-CDS', |
|
50
|
|
|
'SOA-EDIT', |
|
51
|
|
|
'SOA-EDIT-API', |
|
52
|
|
|
'TSIG-ALLOW-AXFR', |
|
53
|
|
|
'TSIG-ALLOW-DNSUPDATE', |
|
54
|
|
|
]; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @var string |
|
58
|
|
|
* @Assert\NotBlank(groups={"CREATE", "UPDATE"}) |
|
59
|
|
|
*/ |
|
60
|
|
|
private $kind; |
|
61
|
|
|
|
|
62
|
|
|
/** @var string[] */ |
|
63
|
|
|
private $metadata = []; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return string |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getKind(): string |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->kind; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param string $kind |
|
75
|
|
|
* |
|
76
|
|
|
* @return Metadata |
|
77
|
|
|
*/ |
|
78
|
|
|
public function setKind(string $kind): Metadata |
|
79
|
|
|
{ |
|
80
|
|
|
$this->kind = $kind; |
|
81
|
|
|
|
|
82
|
|
|
return $this; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @return string[] |
|
87
|
|
|
*/ |
|
88
|
|
|
public function getMetadata(): array |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->metadata; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @param string[] $metadata |
|
95
|
|
|
* |
|
96
|
|
|
* @return Metadata |
|
97
|
|
|
*/ |
|
98
|
|
|
public function setMetadata(array $metadata): Metadata |
|
99
|
|
|
{ |
|
100
|
|
|
$this->metadata = $metadata; |
|
101
|
|
|
|
|
102
|
|
|
return $this; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @param ExecutionContextInterface $context |
|
107
|
|
|
* @param $payload |
|
108
|
|
|
* @Assert\Callback(groups={"CREATE", "UPDATE"}) |
|
109
|
|
|
*/ |
|
110
|
|
|
public function validateKinds(ExecutionContextInterface $context, $payload) |
|
|
|
|
|
|
111
|
|
|
{ |
|
112
|
|
|
if (in_array($this->getKind(), self::VALID_KINDs)) { |
|
113
|
|
|
return; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
if (0 === strpos(strtoupper($this->getKind()), 'X-')) { |
|
117
|
|
|
return; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
$context->buildViolation(sprintf('Kind "%s" not in valid kinds or does not start with "X-"', $this->getKind())) |
|
121
|
|
|
->atPath('kind') |
|
122
|
|
|
->addViolation(); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @param ExecutionContextInterface $context |
|
127
|
|
|
* @param $payload |
|
128
|
|
|
* @Assert\Callback(groups={"UPDATE"}) |
|
129
|
|
|
*/ |
|
130
|
|
|
public function validateForbidden(ExecutionContextInterface $context, $payload) |
|
|
|
|
|
|
131
|
|
|
{ |
|
132
|
|
|
if (in_array($this->getKind(), self::UPDATE_FORBIDDEN)) { |
|
133
|
|
|
$context->buildViolation(sprintf('Kind "%s" cant be updated', $this->getKind())) |
|
134
|
|
|
->atPath('kind') |
|
135
|
|
|
->addViolation(); |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.