From 00c0f0065238a97273e9ecdec8332353e8da81e8 Mon Sep 17 00:00:00 2001 From: Bashar Bhuiyan <13801112+bashar94@users.noreply.github.com> Date: Tue, 5 Mar 2024 11:51:00 +0600 Subject: [PATCH 1/5] Update FirewallResource.php The firewallResource class has 2 types, only the 'server' type was included previously, adding the 'label_selector' type --- src/Models/Firewalls/FirewallResource.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Models/Firewalls/FirewallResource.php b/src/Models/Firewalls/FirewallResource.php index ea27848..cd850c6 100644 --- a/src/Models/Firewalls/FirewallResource.php +++ b/src/Models/Firewalls/FirewallResource.php @@ -10,6 +10,7 @@ class FirewallResource { const TYPE_SERVER = 'server'; + const TYPE_LABEL_SELECTOR = 'label_selector'; /** * @var string @@ -20,26 +21,37 @@ class FirewallResource */ public $server; + /** + * @var string|null + */ + public $selector; + /** * FirewallResource constructor. * - * @param string $type - * @param Server|null $server + * @param string $type + * @param Server|null $server + * @param string|null $selector */ - public function __construct(string $type, ?Server $server) + public function __construct(string $type, ?Server $server = null, ?string $selector = null) { $this->type = $type; $this->server = $server; + $this->selector = $selector; } + /** - * @return string[] + * @return array */ public function toRequestSchema(): array { $s = ['type' => $this->type]; - if ($this->type == self::TYPE_SERVER) { + + if ($this->type == self::TYPE_SERVER && $this->server !== null) { $s['server'] = ['id' => $this->server->id]; + } else if ($this->type == self::TYPE_LABEL_SELECTOR && $this->selector !== null) { + $s['label_selector'] = ['selector' => $this->selector]; } return $s; From bff0efd5cd2b5652c219774b04683c5b5fe8120f Mon Sep 17 00:00:00 2001 From: Bashar Bhuiyan <13801112+bashar94@users.noreply.github.com> Date: Tue, 5 Mar 2024 11:58:02 +0600 Subject: [PATCH 2/5] Update FirewallResource.php Maintained the spacing --- src/Models/Firewalls/FirewallResource.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Models/Firewalls/FirewallResource.php b/src/Models/Firewalls/FirewallResource.php index cd850c6..864853b 100644 --- a/src/Models/Firewalls/FirewallResource.php +++ b/src/Models/Firewalls/FirewallResource.php @@ -21,7 +21,7 @@ class FirewallResource */ public $server; - /** + /** * @var string|null */ public $selector; @@ -29,9 +29,9 @@ class FirewallResource /** * FirewallResource constructor. * - * @param string $type - * @param Server|null $server - * @param string|null $selector + * @param string $type + * @param Server|null $server + * @param string|null $selector */ public function __construct(string $type, ?Server $server = null, ?string $selector = null) { @@ -50,7 +50,7 @@ public function toRequestSchema(): array if ($this->type == self::TYPE_SERVER && $this->server !== null) { $s['server'] = ['id' => $this->server->id]; - } else if ($this->type == self::TYPE_LABEL_SELECTOR && $this->selector !== null) { + } elseif ($this->type == self::TYPE_LABEL_SELECTOR && $this->selector !== null) { $s['label_selector'] = ['selector' => $this->selector]; } From fcfd2dc392dc5120b55da950de81bbe296189937 Mon Sep 17 00:00:00 2001 From: Bashar Bhuiyan <13801112+bashar94@users.noreply.github.com> Date: Tue, 5 Mar 2024 12:01:05 +0600 Subject: [PATCH 3/5] Update FirewallResource.php Maintained space --- src/Models/Firewalls/FirewallResource.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Models/Firewalls/FirewallResource.php b/src/Models/Firewalls/FirewallResource.php index 864853b..0d65019 100644 --- a/src/Models/Firewalls/FirewallResource.php +++ b/src/Models/Firewalls/FirewallResource.php @@ -40,7 +40,6 @@ public function __construct(string $type, ?Server $server = null, ?string $selec $this->selector = $selector; } - /** * @return array */ From 3e731bb525e0a31b6ed2bd61ba9a66221b53d54e Mon Sep 17 00:00:00 2001 From: Bashar Bhuiyan <13801112+bashar94@users.noreply.github.com> Date: Tue, 5 Mar 2024 15:17:54 +0600 Subject: [PATCH 4/5] Update Firewall.php Added 'label_selector' FirewallResource type in Firewall.php --- src/Models/Firewalls/Firewall.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Models/Firewalls/Firewall.php b/src/Models/Firewalls/Firewall.php index 50c4e1e..aacb481 100644 --- a/src/Models/Firewalls/Firewall.php +++ b/src/Models/Firewalls/Firewall.php @@ -122,8 +122,10 @@ public static function parse($input): ?self } foreach ($input->applied_to as $a) { - if ($a->type === 'server') { + if ($a->type === FirewallResource::TYPE_SERVER) { $appliedTo[] = new FirewallResource($a->type, new Server($a->server->id)); + }elseif ($a->type == FirewallResource::TYPE_LABEL_SELECTOR) { + $appliedTo[] = new FirewallResource($a->type, null, $a->label_selector->selector); } } From 17a12904226795a644849412a748ebdae7a39c37 Mon Sep 17 00:00:00 2001 From: Bashar Bhuiyan <13801112+bashar94@users.noreply.github.com> Date: Tue, 5 Mar 2024 15:20:32 +0600 Subject: [PATCH 5/5] Update Firewall.php updated style --- src/Models/Firewalls/Firewall.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Models/Firewalls/Firewall.php b/src/Models/Firewalls/Firewall.php index aacb481..6e5fbb9 100644 --- a/src/Models/Firewalls/Firewall.php +++ b/src/Models/Firewalls/Firewall.php @@ -124,7 +124,7 @@ public static function parse($input): ?self foreach ($input->applied_to as $a) { if ($a->type === FirewallResource::TYPE_SERVER) { $appliedTo[] = new FirewallResource($a->type, new Server($a->server->id)); - }elseif ($a->type == FirewallResource::TYPE_LABEL_SELECTOR) { + } elseif ($a->type == FirewallResource::TYPE_LABEL_SELECTOR) { $appliedTo[] = new FirewallResource($a->type, null, $a->label_selector->selector); } }