Firewall::__get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 1
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;
13
14
use Linode\Entity;
15
use Linode\Networking\Repository\FirewallDevicesRepository;
16
17
/**
18
 * A resource that controls incoming and outgoing network traffic to a compute
19
 * service. Only one enabled Firewall can be attached to a particular service at any
20
 * given time. Create a Firewall Device to assign a Firewall to a service. Currently,
21
 * Firewalls can assigned to Linode compute instances and NodeBalancers.
22
 *
23
 * @property int                                $id      The Firewall's unique ID.
24
 * @property string                             $label   The Firewall's label, for display purposes only.
25
 *                                                       Firewall labels have the following constraints:
26
 *                                                       * Must begin and end with an alphanumeric character.
27
 *                                                       * May only consist of alphanumeric characters, hyphens (`-`), underscores (`_`)
28
 *                                                       or periods (`.`).
29
 *                                                       * Cannot have two hyphens (`--`), underscores (`__`) or periods (`..`) in a row.
30
 *                                                       * Must be between 3 and 32 characters.
31
 *                                                       * Must be unique.
32
 * @property string                             $status  The status of this Firewall.
33
 *                                                       * When a Firewall is first created its status is `enabled`.
34
 *                                                       * Use the Update Firewall endpoint to set a Firewall's status to `enabled` or
35
 *                                                       `disabled`.
36
 *                                                       * Use the Delete Firewall endpoint to delete a Firewall.
37
 * @property string                             $created When this Firewall was created.
38
 * @property string                             $updated When this Firewall was last updated.
39
 * @property FirewallRules                      $rules   The inbound and outbound access rules to apply to the Firewall.
40
 *                                                       A Firewall may have up to 25 rules across its inbound and outbound rulesets.
41
 *                                                       Multiple rules are applied in order. If two rules conflict, the first rule takes
42
 *                                                       precedence. For example, if the first rule accepts inbound traffic from an
43
 *                                                       address, and the second rule drops inbound traffic the same address, the first
44
 *                                                       rule applies and inbound traffic from that address is accepted.
45
 * @property string[]                           $tags    An array of tags applied to this object. Tags are for organizational purposes
46
 *                                                       only.
47
 * @property FirewallDevicesRepositoryInterface $devices Firewall devices.
48
 */
49
class Firewall extends Entity
50
{
51
    // Available fields.
52
    public const FIELD_ID      = 'id';
53
    public const FIELD_LABEL   = 'label';
54
    public const FIELD_STATUS  = 'status';
55
    public const FIELD_CREATED = 'created';
56
    public const FIELD_UPDATED = 'updated';
57
    public const FIELD_RULES   = 'rules';
58
    public const FIELD_TAGS    = 'tags';
59
60
    // Extra fields for POST/PUT requests.
61
    public const FIELD_DEVICES  = 'devices';
62
    public const FIELD_INBOUND  = 'inbound';
63
    public const FIELD_OUTBOUND = 'outbound';
64
65
    // `FIELD_STATUS` values.
66
    public const STATUS_ENABLED  = 'enabled';
67
    public const STATUS_DISABLED = 'disabled';
68
    public const STATUS_DELETED  = 'deleted';
69
70
    /**
71
     * @codeCoverageIgnore This method was autogenerated.
72
     */
73
    public function __get(string $name): mixed
74
    {
75
        return match ($name) {
76
            self::FIELD_RULES   => new FirewallRules($this->client, $this->data[$name]),
77
            self::FIELD_DEVICES => new FirewallDevicesRepository($this->client, $this->id),
78
            default             => parent::__get($name),
79
        };
80
    }
81
}
82