Passed
Push — master ( bfa63a...41a424 )
by Artem
01:47
created

FirewallRuleConfig::__get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
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
16
/**
17
 * One of a Firewall's inbound or outbound access rules. The `ports` property can be
18
 * used to allow traffic on a comma-separated list of different ports.
19
 *
20
 * @property string                $protocol    The type of network traffic to allow.
21
 * @property string                $ports       A string representing the port or ports on which traffic will be allowed:
22
 *                                              - The string may be a single port, a range of ports, or a comma-separated list
23
 *                                              of single ports and port ranges. A space is permitted following each comma.
24
 *                                              - A range of ports is inclusive of the start and end values for the range. The
25
 *                                              end value of the range must be greater than the start value.
26
 *                                              - Ports must be within 1 and 65535, and may not contain any leading zeroes. For
27
 *                                              example, port "080" is not allowed.
28
 *                                              - Ports may not be specified if a rule's protocol is `ICMP`. At least one port
29
 *                                              must be specified if a rule's protocol is `TCP` or `UDP`.
30
 *                                              - The ports string can have up to 15 *pieces*, where a single port is treated
31
 *                                              as one piece, and a port range is treated as two pieces. For example,
32
 *                                              the string "22-24, 80, 443" has four pieces.
33
 * @property FirewallRuleAddresses $addresses   Allowed IPv4 or IPv6 addresses. A Rule can have up to 255 addresses or networks
34
 *                                              listed across its IPv4 and IPv6 arrays. A network and a single IP are treated as
35
 *                                              equivalent when accounting for this limit.
36
 * @property string                $action      Controls whether traffic is accepted or dropped by this rule. Overrides the
37
 *                                              Firewall's `inbound_policy` if this is an inbound rule, or the `outbound_policy`
38
 *                                              if this is an outbound rule.
39
 * @property string                $label       Used to identify this rule. For display purposes only.
40
 * @property string                $description Used to describe this rule. For display purposes only.
41
 */
42
class FirewallRuleConfig extends Entity
43
{
44
    // Available fields.
45
    public const FIELD_PROTOCOL    = 'protocol';
46
    public const FIELD_PORTS       = 'ports';
47
    public const FIELD_ADDRESSES   = 'addresses';
48
    public const FIELD_ACTION      = 'action';
49
    public const FIELD_LABEL       = 'label';
50
    public const FIELD_DESCRIPTION = 'description';
51
52
    // `FIELD_PROTOCOL` values.
53
    public const PROTOCOL_TCP  = 'TCP';
54
    public const PROTOCOL_UDP  = 'UDP';
55
    public const PROTOCOL_ICMP = 'ICMP';
56
57
    // `FIELD_ACTION` values.
58
    public const ACTION_ACCEPT = 'ACCEPT';
59
    public const ACTION_DROP   = 'DROP';
60
61
    /**
62
     * @codeCoverageIgnore This method was autogenerated.
63
     */
64
    public function __get(string $name): mixed
65
    {
66
        return match ($name) {
67
            self::FIELD_ADDRESSES => new FirewallRuleAddresses($this->client, $this->data[$name]),
68
            default               => parent::__get($name),
69
        };
70
    }
71
}
72