Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
9 / 9
CRAP
100.00% covered (success)
100.00%
1 / 1
FirewallService
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
9 / 9
9
100.00% covered (success)
100.00%
1 / 1
 getFirewallGroups
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFirewallGroup
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createFirewallGroup
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 updateFirewallGroup
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 deleteFirewallGroup
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFirewallRules
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFirewallRule
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createFirewallRule
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 deleteFirewallRule
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Vultr\VultrPhp\Services\Firewall;
6
7use Vultr\VultrPhp\Services\VultrService;
8use Vultr\VultrPhp\Util\ListOptions;
9
10/**
11 * Firewall service handler, for firewall endpoints.
12 *
13 * @see https://www.vultr.com/api/#tag/firewall
14 */
15class FirewallService extends VultrService
16{
17    /**
18     * List firewall groups.
19     *
20     * @see https://www.vultr.com/api/#operation/list-firewall-groups
21     * @param $options - ListOptions|null - Interact via reference.
22     * @throws FirewallException
23     * @return array
24     */
25    public function getFirewallGroups(?ListOptions &$options = null) : array
26    {
27        return $this->getListObjects('firewalls', new FirewallGroup(), $options);
28    }
29
30    /**
31     * Retrieve a specific firewall group
32     *
33     * @see https://www.vultr.com/api/#operation/get-firewall-group
34     * @param $group_id - string - Example: cb676a46-66fd-4dfb-b839-443f2e6c0b60
35     * @throws FirewallException
36     * @return FirewallGroup
37     */
38    public function getFirewallGroup(string $group_id) : FirewallGroup
39    {
40        return $this->getObject('firewalls/'.$group_id, new FirewallGroup());
41    }
42
43    /**
44     * Create a firewall group
45     *
46     * @see https://www.vultr.com/api/#operation/create-firewall-group
47     * @param $description - string
48     * @throws FirewallException
49     * @return FirewallGroup
50     */
51    public function createFirewallGroup(string $description) : FirewallGroup
52    {
53        return $this->createObject('firewalls', new FirewallGroup(), ['description' => $description]);
54    }
55
56    /**
57     * Update information for a friewall group
58     *
59     * @see https://www.vultr.com/api/#operation/update-firewall-group
60     * @param $group - FirewallGroup
61     * @throws FirewallException
62     * @return void
63     */
64    public function updateFirewallGroup(FirewallGroup $group) : void
65    {
66        $this->patchObject('firewalls/'.$group->getId(), $group);
67    }
68
69    /**
70     * Delete a firewall group on the account.
71     *
72     * @see https://www.vultr.com/api/#operation/delete-firewall-group
73     * @param $group_id - string - Example: cb676a46-66fd-4dfb-b839-443f2e6c0b60
74     * @throws FirewallException
75     * @return void
76     */
77    public function deleteFirewallGroup(string $group_id) : void
78    {
79        $this->deleteObject('firewalls/'.$group_id, new FirewallGroup());
80    }
81
82    /**
83     * Get firewall rules for the firewall group
84     *
85     * @see https://www.vultr.com/api/#operation/list-firewall-group-rules
86     * @param $group_id - string - Example cb676a46-66fd-4dfb-b839-443f2e6c0b60
87     * @param $options - ListOptions|null - Interact via reference.
88     * @throws FirewallException
89     * @return array
90     */
91    public function getFirewallRules(string $group_id, ?ListOptions &$options = null) : array
92    {
93        return $this->getListObjects('firewalls/'.$group_id.'/rules', new FirewallRule(), $options);
94    }
95
96    /**
97     * Get a specific firewall rule from the firewall group
98     *
99     * @see https://www.vultr.com/api/#operation/get-firewall-group-rule
100     * @param $group_id - string - Example cb676a46-66fd-4dfb-b839-443f2e6c0b60
101     * @param $rule_id - int
102     * @throws FirewallException
103     * @return FirewallRule
104     */
105    public function getFirewallRule(string $group_id, int $rule_id) : FirewallRule
106    {
107        return $this->getObject('firewalls/'.$group_id.'/rules/'.$rule_id, new FirewallRule());
108    }
109
110    /**
111     * Create a firewall rule for the firewall group
112     *
113     * @see https://www.vultr.com/api/#operation/post-firewalls-firewall-group-id-rules
114     * @param $group_id - string - Example cb676a46-66fd-4dfb-b839-443f2e6c0b60
115     * @param $rule - FirewallRule
116     * @throws FirewallException
117     * @return FirewallRule
118     */
119    public function createFirewallRule(string $group_id, FirewallRule $rule) : FirewallRule
120    {
121        return $this->createObject('firewalls/'.$group_id.'/rules', new FirewallRule(), $rule->getInitializedProps());
122    }
123
124    /**
125     * Delete a firewall rule from the firewall group
126     *
127     * @see https://www.vultr.com/api/#operation/delete-firewall-group-rule
128     * @param $group_id - string - Example cb676a46-66fd-4dfb-b839-443f2e6c0b60
129     * @param $rule_id - int
130     * @throws FirewallException
131     * @return void
132     */
133    public function deleteFirewallRule(string $group_id, int $rule_id) : void
134    {
135        $this->deleteObject('firewalls/'.$group_id.'/rules/'.$rule_id, new FirewallRule());
136    }
137
138    /**
139     * There is no Update firewall rule. There was never a point in adding an endpoint in the api for it.
140    public function updateFirewallRule(string $group_id, FirewallRule $rule) : void
141    {
142
143    }
144    */
145}