Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update FirewallResource.php #114

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Models/Firewalls/Firewall.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
17 changes: 14 additions & 3 deletions src/Models/Firewalls/FirewallResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class FirewallResource
{
const TYPE_SERVER = 'server';
const TYPE_LABEL_SELECTOR = 'label_selector';

/**
* @var string
Expand All @@ -20,26 +21,36 @@ class FirewallResource
*/
public $server;

/**
* @var string|null
*/
public $selector;

/**
* FirewallResource constructor.
*
* @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];
} elseif ($this->type == self::TYPE_LABEL_SELECTOR && $this->selector !== null) {
$s['label_selector'] = ['selector' => $this->selector];
}

return $s;
Expand Down