1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
// --------------------------------------------------------------------- |
4
|
|
|
// |
5
|
|
|
// Copyright (C) 2018-2024 Artem Rodygin |
6
|
|
|
// |
7
|
|
|
// You should have received a copy of the MIT License along with |
8
|
|
|
// this file. If not, see <https://opensource.org/licenses/MIT>. |
9
|
|
|
// |
10
|
|
|
// --------------------------------------------------------------------- |
11
|
|
|
|
12
|
|
|
namespace Linode\Networking\Repository; |
13
|
|
|
|
14
|
|
|
use Linode\Entity; |
15
|
|
|
use Linode\Internal\AbstractRepository; |
16
|
|
|
use Linode\LinodeClient; |
17
|
|
|
use Linode\Networking\FirewallDevices; |
18
|
|
|
use Linode\Networking\FirewallDevicesRepositoryInterface; |
19
|
|
|
use Linode\Networking\FirewallRules; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @codeCoverageIgnore This class was autogenerated. |
23
|
|
|
*/ |
24
|
|
|
class FirewallDevicesRepository extends AbstractRepository implements FirewallDevicesRepositoryInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @param int $firewallId ID of the Firewall to access. |
28
|
|
|
*/ |
29
|
|
|
public function __construct(LinodeClient $client, protected int $firewallId) |
30
|
|
|
{ |
31
|
|
|
parent::__construct($client); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function createFirewallDevice(array $parameters = []): FirewallDevices |
35
|
|
|
{ |
36
|
|
|
$response = $this->client->post($this->getBaseUri(), $parameters); |
37
|
|
|
$contents = $response->getBody()->getContents(); |
38
|
|
|
$json = json_decode($contents, true); |
39
|
|
|
|
40
|
|
|
return new FirewallDevices($this->client, $json); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function deleteFirewallDevice(int $deviceId): void |
44
|
|
|
{ |
45
|
|
|
$this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $deviceId)); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function getFirewallRules(): FirewallRules |
49
|
|
|
{ |
50
|
|
|
$response = $this->client->get(sprintf('/networking/firewalls/%s/rules', $this->getBaseUri())); |
51
|
|
|
$contents = $response->getBody()->getContents(); |
52
|
|
|
$json = json_decode($contents, true); |
53
|
|
|
|
54
|
|
|
return new FirewallRules($this->client, $json); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function updateFirewallRules(array $parameters = []): FirewallRules |
58
|
|
|
{ |
59
|
|
|
$response = $this->client->put(sprintf('/networking/firewalls/%s/rules', $this->getBaseUri()), $parameters); |
60
|
|
|
$contents = $response->getBody()->getContents(); |
61
|
|
|
$json = json_decode($contents, true); |
62
|
|
|
|
63
|
|
|
return new FirewallRules($this->client, $json); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
protected function getBaseUri(): string |
67
|
|
|
{ |
68
|
|
|
return sprintf('/networking/firewalls/%s/devices', $this->firewallId); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
protected function getSupportedFields(): array |
72
|
|
|
{ |
73
|
|
|
return [ |
74
|
|
|
FirewallDevices::FIELD_ID, |
75
|
|
|
FirewallDevices::FIELD_CREATED, |
76
|
|
|
FirewallDevices::FIELD_UPDATED, |
77
|
|
|
FirewallDevices::FIELD_ENTITY, |
78
|
|
|
]; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
protected function jsonToEntity(array $json): Entity |
82
|
|
|
{ |
83
|
|
|
return new FirewallDevices($this->client, $json); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|