Skip to content

Commit e61f74d

Browse files
feat: add models, endpoints and tests for IPsec statuses
1 parent bd02830 commit e61f74d

7 files changed

Lines changed: 628 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace RESTAPI\Endpoints;
4+
5+
require_once 'RESTAPI/autoloader.inc';
6+
7+
use RESTAPI\Core\Endpoint;
8+
9+
/**
10+
* Defines an Endpoint for interacting with a single IPseChildcSAStatus Model object at
11+
* /api/v2/status/ipsec/child_sa.
12+
*/
13+
class StatusIPsecChildSAEndpoint extends Endpoint {
14+
public function __construct() {
15+
# Set Endpoint attributes
16+
$this->url = '/api/v2/status/ipsec/child_sa';
17+
$this->model_name = 'IPsecChildSAStatus';
18+
$this->request_method_options = ['GET'];
19+
20+
# Construct the parent Endpoint object
21+
parent::__construct();
22+
}
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace RESTAPI\Endpoints;
4+
5+
require_once 'RESTAPI/autoloader.inc';
6+
7+
use RESTAPI\Core\Endpoint;
8+
9+
/**
10+
* Defines an Endpoint for interacting with a single IPsecSAStatus Model object at
11+
* /api/v2/status/ipsec/sa.
12+
*/
13+
class StatusIPsecSAEndpoint extends Endpoint {
14+
public function __construct() {
15+
# Set Endpoint attributes
16+
$this->url = '/api/v2/status/ipsec/sas';
17+
$this->model_name = 'IPsecSAStatus';
18+
$this->request_method_options = ['GET'];
19+
20+
# Construct the parent Endpoint object
21+
parent::__construct();
22+
}
23+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace RESTAPI\Endpoints;
4+
5+
require_once 'RESTAPI/autoloader.inc';
6+
7+
use RESTAPI\Core\Endpoint;
8+
9+
/**
10+
* Defines an Endpoint for interacting with multiple IPsecSAStatus Model objects at
11+
* /api/v2/status/ipsec/sas.
12+
*/
13+
class StatusIPsecSAsEndpoint extends Endpoint {
14+
public function __construct() {
15+
# Set Endpoint attributes
16+
$this->url = '/api/v2/status/ipsec/sas';
17+
$this->model_name = 'IPsecSAStatus';
18+
$this->many = true;
19+
$this->request_method_options = ['GET'];
20+
21+
# Construct the parent Endpoint object
22+
parent::__construct();
23+
}
24+
}
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
<?php
2+
3+
namespace RESTAPI\Models;
4+
5+
use RESTAPI\Core\Model;
6+
use RESTAPI\Fields\BooleanField;
7+
use RESTAPI\Fields\IntegerField;
8+
use RESTAPI\Fields\NestedModelField;
9+
use RESTAPI\Fields\PortField;
10+
use RESTAPI\Fields\StringField;
11+
12+
/**
13+
* A Model that provides the status of IPsec child SAs.
14+
*/
15+
class IPsecChildSAStatus extends Model {
16+
public StringField $name;
17+
public IntegerField $uniqueid;
18+
public IntegerField $reqid;
19+
public StringField $state;
20+
public StringField $mode;
21+
public StringField $protocol;
22+
public BooleanField $encap;
23+
public StringField $spi_in;
24+
public StringField $spi_out;
25+
public StringField $encr_alg;
26+
public IntegerField $encr_keysize;
27+
public StringField $integ_alg;
28+
public StringField $dh_group;
29+
public IntegerField $bytes_in;
30+
public IntegerField $bytes_out;
31+
public IntegerField $packets_in;
32+
public IntegerField $packets_out;
33+
public IntegerField $use_in;
34+
public IntegerField $use_out;
35+
public IntegerField $rekey_time;
36+
public IntegerField $life_time;
37+
public IntegerField $install_time;
38+
public StringField $local_ts;
39+
public StringField $remote_ts;
40+
41+
public function __construct(mixed $id = null, mixed $parent_id = null, mixed $data = [], ...$options) {
42+
# Set model attributes
43+
$this->internal_callable = 'get_ipsec_child SA_statuses';
44+
$this->parent_model_class = 'IPsecSAStatus';
45+
$this->verbose_name = 'IPsec Child SA Status';
46+
$this->many = true;
47+
48+
# Set model fields
49+
$this->name = new StringField(
50+
default: '',
51+
read_only: true,
52+
help_text: 'The name of the connection ID for the child SA.',
53+
);
54+
$this->uniqueid = new IntegerField(default: 0, read_only: true, help_text: 'The unique ID of the child SA.');
55+
$this->reqid = new IntegerField(default: 0, read_only: true, help_text: 'The request ID of the child SA.');
56+
$this->state = new StringField(default: '', read_only: true, help_text: 'The current state of the child SA.');
57+
$this->mode = new StringField(default: '', read_only: true, help_text: 'The mode of the child SA.');
58+
$this->protocol = new StringField(default: '', read_only: true, help_text: 'The protocol of the child SA.');
59+
$this->encap = new BooleanField(
60+
default: false,
61+
read_only: true,
62+
indicates_true: 'yes',
63+
help_text: 'Whether encapsulation is used for the child SA.',
64+
);
65+
$this->spi_in = new StringField(
66+
default: '',
67+
read_only: true,
68+
internal_name: 'spi-in',
69+
help_text: 'The incoming SPI of the child SA.',
70+
);
71+
$this->spi_out = new StringField(
72+
default: '',
73+
read_only: true,
74+
internal_name: 'spi-out',
75+
help_text: 'The outgoing SPI of the child SA.',
76+
);
77+
$this->encr_alg = new StringField(
78+
default: '',
79+
read_only: true,
80+
internal_name: 'encr-alg',
81+
help_text: 'The encryption algorithm used by the child SA.',
82+
);
83+
$this->encr_keysize = new IntegerField(
84+
default: 0,
85+
read_only: true,
86+
internal_name: 'encr-keysize',
87+
help_text: 'The encryption key size used by the child SA.',
88+
);
89+
$this->integ_alg = new StringField(
90+
default: '',
91+
read_only: true,
92+
internal_name: 'integ-alg',
93+
help_text: 'The integrity algorithm used by the child SA.',
94+
);
95+
$this->dh_group = new StringField(
96+
default: '',
97+
read_only: true,
98+
internal_name: 'dh-group',
99+
help_text: 'The Diffie-Hellman group used by the child SA.',
100+
);
101+
$this->bytes_in = new IntegerField(
102+
default: 0,
103+
read_only: true,
104+
internal_name: 'bytes-in',
105+
help_text: 'The number of bytes received by the child SA.',
106+
);
107+
$this->bytes_out = new IntegerField(
108+
default: 0,
109+
read_only: true,
110+
internal_name: 'bytes-out',
111+
help_text: 'The number of bytes sent by the child SA.',
112+
);
113+
$this->packets_in = new IntegerField(
114+
default: 0,
115+
read_only: true,
116+
internal_name: 'packets-in',
117+
help_text: 'The number of packets received by the child SA.',
118+
);
119+
$this->packets_out = new IntegerField(
120+
default: 0,
121+
read_only: true,
122+
internal_name: 'packets-out',
123+
help_text: 'The number of packets sent by the child SA.',
124+
);
125+
$this->use_in = new IntegerField(
126+
default: 0,
127+
read_only: true,
128+
internal_name: 'use-in',
129+
help_text: 'The number of times the child SA has been used to receive data.',
130+
);
131+
$this->use_out = new IntegerField(
132+
default: 0,
133+
read_only: true,
134+
internal_name: 'use-out',
135+
help_text: 'The number of times the child SA has been used to send data.',
136+
);
137+
$this->rekey_time = new IntegerField(
138+
default: 0,
139+
read_only: true,
140+
internal_name: 'rekey-time',
141+
help_text: 'The time at which the child SA will be rekeyed.',
142+
);
143+
$this->life_time = new IntegerField(
144+
default: 0,
145+
read_only: true,
146+
internal_name: 'life-time',
147+
help_text: 'The time at which the child SA will expire.',
148+
);
149+
$this->install_time = new IntegerField(
150+
default: 0,
151+
read_only: true,
152+
internal_name: 'install-time',
153+
help_text: 'The time at which the child SA was installed.',
154+
);
155+
$this->local_ts = new StringField(
156+
default: '',
157+
read_only: true,
158+
many: true,
159+
delimiter: null,
160+
internal_name: 'local-ts',
161+
help_text: 'The local traffic selector of the child SA.',
162+
);
163+
$this->remote_ts = new StringField(
164+
default: '',
165+
read_only: true,
166+
many: true,
167+
delimiter: null,
168+
internal_name: 'remote-ts',
169+
help_text: 'The remote traffic selector of the child SA.',
170+
);
171+
172+
parent::__construct($id, $parent_id, $data, ...$options);
173+
}
174+
175+
/**
176+
* Obtains the status of IPsec child SAs. This is the internal callable that is used to obtain the internal data for
177+
* this model.
178+
* @return array The status of IPsec child SAs where each item is an associative array containing the status of an
179+
* IPsec child SA on the system.
180+
*/
181+
public function get_ipsec_sa_statuses(): array {
182+
return IPsecSAStatus::get_ipsec_sa_statuses()[$this->parent_id]['child-sas'];
183+
}
184+
}

0 commit comments

Comments
 (0)