Passed
Push — master ( 0676a7...01ab94 )
by Artem
11:54
created

NodeBalancerConfig   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 40
dl 0
loc 60
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __get() 0 6 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\NodeBalancers;
13
14
use Linode\Entity;
15
use Linode\NodeBalancers\Repository\NodeBalancerNodeRepository;
16
17
/**
18
 * A NodeBalancer config represents the configuration of this NodeBalancer on a
19
 * single port. For example, a NodeBalancer Config on port 80 would typically
20
 * represent how this NodeBalancer response to HTTP requests.
21
 *
22
 * NodeBalancer configs have a list of backends, called "nodes," that they forward
23
 * requests between based on their configuration.
24
 *
25
 * @property int                                 $id              This config's unique ID
26
 * @property int                                 $port            The port this Config is for. These values must be unique across configs on a
27
 *                                                                single NodeBalancer (you can't have two configs for port 80, for example). While
28
 *                                                                some ports imply some protocols, no enforcement is done and you may configure your
29
 *                                                                NodeBalancer however is useful to you. For example, while port 443 is generally
30
 *                                                                used for HTTPS, you do not need SSL configured to have a NodeBalancer listening on
31
 *                                                                port 443.
32
 * @property string                              $protocol        The protocol this port is configured to serve.
33
 *                                                                * If this is set to `https` you must include an `ssl_cert` and an `ssl_key`.
34
 * @property string                              $algorithm       What algorithm this NodeBalancer should use for routing traffic to backends.
35
 * @property string                              $stickiness      Controls how session stickiness is handled on this port.
36
 *                                                                * If set to `none` connections will always be assigned a backend based on the
37
 *                                                                algorithm configured.
38
 *                                                                * If set to `table` sessions from the same remote address will be routed to the
39
 *                                                                same
40
 *                                                                backend.
41
 *                                                                * For HTTP or HTTPS clients, `http_cookie` allows sessions to be
42
 *                                                                routed to the same backend based on a cookie set by the NodeBalancer.
43
 * @property string                              $check           The type of check to perform against backends to ensure they are serving requests.
44
 *                                                                This is used to determine if backends are up or down.
45
 *                                                                * If `none` no check is performed.
46
 *                                                                * `connection` requires only a connection to the backend to succeed.
47
 *                                                                * `http` and `http_body` rely on the backend serving HTTP, and that
48
 *                                                                the response returned matches what is expected.
49
 * @property int                                 $check_interval  How often, in seconds, to check that backends are up and serving requests.
50
 * @property int                                 $check_timeout   How long, in seconds, to wait for a check attempt before considering it failed.
51
 * @property int                                 $check_attempts  How many times to attempt a check before considering a backend to be down.
52
 * @property string                              $check_path      The URL path to check on each backend. If the backend does not respond to this
53
 *                                                                request it is considered to be down.
54
 * @property string                              $check_body      This value must be present in the response body of the check in order for it to
55
 *                                                                pass. If this value is not present in the response body of a check request, the
56
 *                                                                backend is considered to be down.
57
 * @property bool                                $check_passive   If true, any response from this backend with a `5xx` status code will be enough
58
 *                                                                for it to be considered unhealthy and taken out of rotation.
59
 * @property string                              $cipher_suite    What ciphers to use for SSL connections served by this NodeBalancer.
60
 *                                                                * `legacy` is considered insecure and should only be used if necessary.
61
 * @property string                              $ssl_commonname  The read-only common name automatically derived from the SSL certificate assigned
62
 *                                                                to this NodeBalancerConfig. Please refer to this field to verify that the
63
 *                                                                appropriate certificate is assigned to your NodeBalancerConfig.
64
 * @property string                              $ssl_fingerprint The read-only fingerprint automatically derived from the SSL certificate assigned
65
 *                                                                to this NodeBalancerConfig. Please refer to this field to verify that the
66
 *                                                                appropriate certificate is assigned to your NodeBalancerConfig.
67
 * @property null|string                         $ssl_cert        The PEM-formatted public SSL certificate (or the combined PEM-formatted SSL
68
 *                                                                certificate and Certificate Authority chain) that should be served on this
69
 *                                                                NodeBalancerConfig's port.
70
 *                                                                The contents of this field will not be shown in any responses that display
71
 *                                                                the NodeBalancerConfig. Instead, `<REDACTED>` will be printed where the field
72
 *                                                                appears.
73
 *                                                                The read-only `ssl_commonname` and `ssl_fingerprint` fields in a
74
 *                                                                NodeBalancerConfig
75
 *                                                                response are automatically derived from your certificate. Please refer to these
76
 *                                                                fields to
77
 *                                                                verify that the appropriate certificate was assigned to your NodeBalancerConfig.
78
 * @property null|string                         $ssl_key         The PEM-formatted private key for the SSL certificate set in the `ssl_cert` field.
79
 *                                                                The contents of this field will not be shown in any responses that display
80
 *                                                                the NodeBalancerConfig. Instead, `<REDACTED>` will be printed where the field
81
 *                                                                appears.
82
 *                                                                The read-only `ssl_commonname` and `ssl_fingerprint` fields in a
83
 *                                                                NodeBalancerConfig
84
 *                                                                response are automatically derived from your certificate. Please refer to these
85
 *                                                                fields to
86
 *                                                                verify that the appropriate certificate was assigned to your NodeBalancerConfig.
87
 * @property NodesStatus                         $nodes_status    A structure containing information about the health of the backends for this port.
88
 *                                                                This information is updated periodically as checks are performed against backends.
89
 * @property int                                 $nodebalancer_id The ID for the NodeBalancer this config belongs to.
90
 * @property NodeBalancerNodeRepositoryInterface $nodes           NodeBalancer nodes.
91
 */
92
class NodeBalancerConfig extends Entity
93
{
94
    // Available fields.
95
    public const FIELD_ID              = 'id';
96
    public const FIELD_PORT            = 'port';
97
    public const FIELD_PROTOCOL        = 'protocol';
98
    public const FIELD_ALGORITHM       = 'algorithm';
99
    public const FIELD_STICKINESS      = 'stickiness';
100
    public const FIELD_CHECK           = 'check';
101
    public const FIELD_CHECK_INTERVAL  = 'check_interval';
102
    public const FIELD_CHECK_TIMEOUT   = 'check_timeout';
103
    public const FIELD_CHECK_ATTEMPTS  = 'check_attempts';
104
    public const FIELD_CHECK_PATH      = 'check_path';
105
    public const FIELD_CHECK_BODY      = 'check_body';
106
    public const FIELD_CHECK_PASSIVE   = 'check_passive';
107
    public const FIELD_CIPHER_SUITE    = 'cipher_suite';
108
    public const FIELD_SSL_COMMONNAME  = 'ssl_commonname';
109
    public const FIELD_SSL_FINGERPRINT = 'ssl_fingerprint';
110
    public const FIELD_SSL_CERT        = 'ssl_cert';
111
    public const FIELD_SSL_KEY         = 'ssl_key';
112
    public const FIELD_NODES_STATUS    = 'nodes_status';
113
    public const FIELD_NODEBALANCER_ID = 'nodebalancer_id';
114
115
    // Extra fields for POST/PUT requests.
116
    public const FIELD_NODES = 'nodes';
117
118
    // `FIELD_PROTOCOL` values.
119
    public const PROTOCOL_HTTP  = 'http';
120
    public const PROTOCOL_HTTPS = 'https';
121
    public const PROTOCOL_TCP   = 'tcp';
122
123
    // `FIELD_ALGORITHM` values.
124
    public const ALGORITHM_ROUNDROBIN = 'roundrobin';
125
    public const ALGORITHM_LEASTCONN  = 'leastconn';
126
    public const ALGORITHM_SOURCE     = 'source';
127
128
    // `FIELD_STICKINESS` values.
129
    public const STICKINESS_NONE        = 'none';
130
    public const STICKINESS_TABLE       = 'table';
131
    public const STICKINESS_HTTP_COOKIE = 'http_cookie';
132
133
    // `FIELD_CHECK` values.
134
    public const CHECK_NONE       = 'none';
135
    public const CHECK_CONNECTION = 'connection';
136
    public const CHECK_HTTP       = 'http';
137
    public const CHECK_HTTP_BODY  = 'http_body';
138
139
    // `FIELD_CIPHER_SUITE` values.
140
    public const CIPHER_SUITE_RECOMMENDED = 'recommended';
141
    public const CIPHER_SUITE_LEGACY      = 'legacy';
142
143
    /**
144
     * @codeCoverageIgnore This method was autogenerated.
145
     */
146
    public function __get(string $name): mixed
147
    {
148
        return match ($name) {
149
            self::FIELD_NODES_STATUS => new NodesStatus($this->client, $this->data[$name]),
150
            self::FIELD_NODES        => new NodeBalancerNodeRepository($this->client, $this->nodebalancer_id, $this->id),
151
            default                  => parent::__get($name),
152
        };
153
    }
154
}
155