-
Notifications
You must be signed in to change notification settings - Fork 5
/
FirewallRuleResource.php
73 lines (66 loc) 路 2.06 KB
/
FirewallRuleResource.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
namespace Infra\Resource;
use Graphael\TypeRegistryInterface;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use Graph\Graph;
class FirewallRuleResource extends AbstractResource
{
public function getHosts()
{
return $this->infra->getHosts($this->spec['hosts'] ?? []);
}
public function getHostsAsString()
{
$hosts = $this->spec['hosts'] ?? null;
if (is_array($hosts)) {
$hosts = implode(', ', $hosts);
}
return $hosts;
}
public function getRemoteHostsAsString()
{
$hosts = $this->spec['remoteHosts'] ?? null;
if (is_array($hosts)) {
$hosts = implode(', ', $hosts);
}
return $hosts;
}
public function getTemplate()
{
return $this->spec['template'] ?? null;
}
public function getRemoteHosts()
{
return $this->infra->getHosts($this->spec['remoteHosts'] ?? []);
}
public static function getConfig(Graph $graph)
{
return [
'name' => 'FirewallRule',
'fields' => [
'name' => Type::id(),
'description' => [
'type' => Type::string(),
'description' => 'Description',
],
'labels' => [
'type' => Type::listOf($graph->getType('Label')),
'description' => 'Returns all labels',
],
'template' => [
'type' => Type::string(),
'description' => 'iptables template',
],
'hosts' => [
'type' => Type::listOf($graph->getType('Host')),
'description' => 'Returns all hosts where this firewall rule is active',
],
'remoteHosts' => [
'type' => Type::listOf($graph->getType('Host')),
'description' => 'Returns all remote hosts that this firewall rule refers to',
],
],
];
}
}