Skip to content

Commit 97abb25

Browse files
authored
Merge pull request #27 from CyberfusionNL/feature/1.83.0
Update to API version 1.158.0
2 parents 1b316f8 + 50c95d6 commit 97abb25

7 files changed

+307
-2
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66
this package and not the cluster API. See the changelog of the [cluster API](https://cluster-api.cyberfusion.nl/redoc#section/Changelog)
77
for detailed information.
88

9+
## [1.83.0]
10+
11+
### Added
12+
13+
- Add `certificate_id` to Domain Routers.
14+
- Add `MailHostnames` endpoints.
15+
916
## [1.82.1]
1017

1118
### Fixed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Client for the [Cyberfusion Cluster API](https://cluster-api.cyberfusion.nl/).
44

5-
This client was built for and tested on the **1.157** version of the API.
5+
This client was built for and tested on the **1.158** version of the API.
66

77
## Support
88

src/Client.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Client implements ClientContract
2020
{
2121
private const CONNECT_TIMEOUT = 60;
2222
private const TIMEOUT = 180;
23-
private const VERSION = '1.82.1';
23+
private const VERSION = '1.83.0';
2424
private const USER_AGENT = 'cyberfusion-cluster-api-client/' . self::VERSION;
2525

2626
private Configuration $configuration;

src/Endpoints/DomainRouters.php

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public function update(DomainRouter $domainRouter): Response
6767
'virtual_host_id',
6868
'url_redirect_id',
6969
'node_id',
70+
'certificate_id',
7071
'force_ssl',
7172
'id',
7273
'cluster_id',

src/Endpoints/MailHostnames.php

+177
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
<?php
2+
3+
namespace Cyberfusion\ClusterApi\Endpoints;
4+
5+
use Cyberfusion\ClusterApi\Exceptions\RequestException;
6+
use Cyberfusion\ClusterApi\Models\MailHostname;
7+
use Cyberfusion\ClusterApi\Request;
8+
use Cyberfusion\ClusterApi\Response;
9+
use Cyberfusion\ClusterApi\Support\ListFilter;
10+
11+
class MailHostnames extends Endpoint
12+
{
13+
/**
14+
* @param ListFilter|null $filter
15+
* @return Response
16+
* @throws RequestException
17+
*/
18+
public function list(ListFilter $filter = null): Response
19+
{
20+
if (is_null($filter)) {
21+
$filter = new ListFilter();
22+
}
23+
24+
$request = (new Request())
25+
->setMethod(Request::METHOD_GET)
26+
->setUrl(sprintf('mail-hostnames?%s', $filter->toQuery()));
27+
28+
$response = $this
29+
->client
30+
->request($request);
31+
if (!$response->isSuccess()) {
32+
return $response;
33+
}
34+
35+
return $response->setData([
36+
'mailHostnames' => array_map(
37+
function (array $data) {
38+
return (new MailHostname())->fromArray($data);
39+
},
40+
$response->getData()
41+
),
42+
]);
43+
}
44+
45+
/**
46+
* @param int $id
47+
* @return Response
48+
* @throws RequestException
49+
*/
50+
public function get(int $id): Response
51+
{
52+
$request = (new Request())
53+
->setMethod(Request::METHOD_GET)
54+
->setUrl(sprintf('mail-hostnames/%d', $id));
55+
56+
$response = $this
57+
->client
58+
->request($request);
59+
if (!$response->isSuccess()) {
60+
return $response;
61+
}
62+
63+
return $response->setData([
64+
'mailHostname' => (new MailHostname())->fromArray($response->getData()),
65+
]);
66+
}
67+
68+
/**
69+
* @param MailHostname $mailHostname
70+
* @return Response
71+
* @throws RequestException
72+
*/
73+
public function create(MailHostname $mailHostname): Response
74+
{
75+
$this->validateRequired($mailHostname, 'create', [
76+
'domain',
77+
'cluster_id',
78+
]);
79+
80+
$request = (new Request())
81+
->setMethod(Request::METHOD_POST)
82+
->setUrl('mail-hostnames')
83+
->setBody($this->filterFields($mailHostname->toArray(), [
84+
'domain',
85+
'certificate_id',
86+
'cluster_id',
87+
]));
88+
89+
$response = $this
90+
->client
91+
->request($request);
92+
if (!$response->isSuccess()) {
93+
return $response;
94+
}
95+
96+
$mailHostname = (new MailHostname())->fromArray($response->getData());
97+
98+
// Log which cluster is affected by this change
99+
$this
100+
->client
101+
->addAffectedCluster($mailHostname->getClusterId());
102+
103+
return $response->setData([
104+
'mailHostname' => $mailHostname,
105+
]);
106+
}
107+
108+
/**
109+
* @param MailHostname $mailHostname
110+
* @return Response
111+
* @throws RequestException
112+
*/
113+
public function update(MailHostname $mailHostname): Response
114+
{
115+
$this->validateRequired($mailHostname, 'update', [
116+
'domain',
117+
'cluster_id',
118+
'id',
119+
]);
120+
121+
$request = (new Request())
122+
->setMethod(Request::METHOD_PUT)
123+
->setUrl(sprintf('mail-hostnames/%d', $mailHostname->getId()))
124+
->setBody($this->filterFields($mailHostname->toArray(), [
125+
'domain',
126+
'certificate_id',
127+
'cluster_id',
128+
'id',
129+
]));
130+
131+
$response = $this
132+
->client
133+
->request($request);
134+
if (!$response->isSuccess()) {
135+
return $response;
136+
}
137+
138+
$mailHostname = (new MailHostname())->fromArray($response->getData());
139+
140+
// Log which cluster is affected by this change
141+
$this
142+
->client
143+
->addAffectedCluster($mailHostname->getClusterId());
144+
145+
return $response->setData([
146+
'mailHostname' => $mailHostname,
147+
]);
148+
}
149+
150+
/**
151+
* @param int $id
152+
* @return Response
153+
* @throws RequestException
154+
*/
155+
public function delete(int $id): Response
156+
{
157+
// Log the affected cluster by retrieving the model first
158+
$result = $this->get($id);
159+
if ($result->isSuccess()) {
160+
$clusterId = $result
161+
->getData('mailHostname')
162+
->getClusterId();
163+
164+
$this
165+
->client
166+
->addAffectedCluster($clusterId);
167+
}
168+
169+
$request = (new Request())
170+
->setMethod(Request::METHOD_DELETE)
171+
->setUrl(sprintf('mail-hostnames/%d', $id));
172+
173+
return $this
174+
->client
175+
->request($request);
176+
}
177+
}

src/Models/DomainRouter.php

+15
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class DomainRouter extends ClusterModel implements Model
1212
private ?int $virtualHostId = null;
1313
private ?int $urlRedirectId = null;
1414
private ?int $nodeId = null;
15+
private ?int $certificateId = null;
1516
private int $id;
1617
private int $clusterId;
1718
private ?string $createdAt = null;
@@ -77,6 +78,18 @@ public function setNodeId(?int $nodeId): self
7778
return $this;
7879
}
7980

81+
public function getCertificateId(): ?int
82+
{
83+
return $this->certificateId;
84+
}
85+
86+
public function setCertificateId(?int $certificateId): self
87+
{
88+
$this->certificateId = $certificateId;
89+
90+
return $this;
91+
}
92+
8093
public function getId(): int
8194
{
8295
return $this->id;
@@ -133,6 +146,7 @@ public function fromArray(array $data): self
133146
->setVirtualHostId(Arr::get($data, 'virtual_host_id'))
134147
->setUrlRedirectId(Arr::get($data, 'url_redirect_id'))
135148
->setNodeId(Arr::get($data, 'node_id'))
149+
->setCertificateId(Arr::get($data, 'certificate_id'))
136150
->setId(Arr::get($data, 'id'))
137151
->setClusterId(Arr::get($data, 'cluster_id'))
138152
->setCreatedAt(Arr::get($data, 'created_at'))
@@ -147,6 +161,7 @@ public function toArray(): array
147161
'virtual_host_id' => $this->getVirtualHostId(),
148162
'url_redirect_id' => $this->getUrlRedirectId(),
149163
'node_id' => $this->getNodeId(),
164+
'certificate_id' => $this->getCertificateId(),
150165
'id' => $this->getId(),
151166
'cluster_id' => $this->getClusterId(),
152167
'created_at' => $this->getCreatedAt(),

src/Models/MailHostname.php

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
3+
namespace Cyberfusion\ClusterApi\Models;
4+
5+
use Cyberfusion\ClusterApi\Contracts\Model;
6+
use Cyberfusion\ClusterApi\Support\Arr;
7+
8+
class MailHostname extends ClusterModel implements Model
9+
{
10+
private string $domain;
11+
private int $clusterId;
12+
private ?int $certificateId = null;
13+
private ?int $id = null;
14+
private ?string $createdAt = null;
15+
private ?string $updatedAt = null;
16+
17+
public function getDomain(): string
18+
{
19+
return $this->domain;
20+
}
21+
22+
public function setDomain(string $domain): self
23+
{
24+
$this->domain = $domain;
25+
return $this;
26+
}
27+
28+
public function getClusterId(): int
29+
{
30+
return $this->clusterId;
31+
}
32+
33+
public function setClusterId(int $clusterId): self
34+
{
35+
$this->clusterId = $clusterId;
36+
return $this;
37+
}
38+
39+
public function getCertificateId(): ?int
40+
{
41+
return $this->certificateId;
42+
}
43+
44+
public function setCertificateId(?int $certificateId): self
45+
{
46+
$this->certificateId = $certificateId;
47+
return $this;
48+
}
49+
50+
public function getId(): ?int
51+
{
52+
return $this->id;
53+
}
54+
55+
public function setId(?int $id): self
56+
{
57+
$this->id = $id;
58+
return $this;
59+
}
60+
61+
public function getCreatedAt(): ?string
62+
{
63+
return $this->createdAt;
64+
}
65+
66+
public function setCreatedAt(?string $createdAt): self
67+
{
68+
$this->createdAt = $createdAt;
69+
return $this;
70+
}
71+
72+
public function getUpdatedAt(): ?string
73+
{
74+
return $this->updatedAt;
75+
}
76+
77+
public function setUpdatedAt(?string $updatedAt): self
78+
{
79+
$this->updatedAt = $updatedAt;
80+
return $this;
81+
}
82+
83+
public function fromArray(array $data): self
84+
{
85+
return $this
86+
->setDomain(Arr::get($data, 'domain'))
87+
->setClusterId(Arr::get($data, 'cluster_id'))
88+
->setCertificateId(Arr::get($data, 'certificate_id'))
89+
->setId(Arr::get($data, 'id'))
90+
->setCreatedAt(Arr::get($data, 'created_at'))
91+
->setUpdatedAt(Arr::get($data, 'updated_at'));
92+
}
93+
94+
public function toArray(): array
95+
{
96+
return [
97+
'domain' => $this->getDomain(),
98+
'cluster_id' => $this->getClusterId(),
99+
'certificate_id' => $this->getCertificateId(),
100+
'id' => $this->getId(),
101+
'created_at' => $this->getCreatedAt(),
102+
'updated_at' => $this->getUpdatedAt(),
103+
];
104+
}
105+
}

0 commit comments

Comments
 (0)