Skip to content

Commit 675dfb7

Browse files
authored
Merge pull request #31 from CyberfusionNL/1.86
Version 1.86.0
2 parents 881f953 + ffaafc7 commit 675dfb7

File tree

5 files changed

+180
-2
lines changed

5 files changed

+180
-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.86.0]
10+
11+
### Added
12+
13+
- CMS theme install endpoint.
14+
- CMS user credentials update endpoint.
15+
916
## [1.85.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.162** version of the API.
5+
This client was built for and tested on the **1.164** 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.85.1';
23+
private const VERSION = '1.86.0';
2424
private const USER_AGENT = 'cyberfusion-cluster-api-client/' . self::VERSION;
2525

2626
private Configuration $configuration;

src/Endpoints/Cmses.php

+128
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Cyberfusion\ClusterApi\Models\CmsConfigurationConstant;
88
use Cyberfusion\ClusterApi\Models\CmsInstallation;
99
use Cyberfusion\ClusterApi\Models\CmsOption;
10+
use Cyberfusion\ClusterApi\Models\CmsUserCredentials;
1011
use Cyberfusion\ClusterApi\Models\TaskCollection;
1112
use Cyberfusion\ClusterApi\Request;
1213
use Cyberfusion\ClusterApi\Response;
@@ -405,4 +406,131 @@ public function regenerateSalts(int $id): Response
405406
'cms' => $cms,
406407
]);
407408
}
409+
410+
/**
411+
* @param int $id
412+
* @param string $name
413+
* @param string|null $version
414+
* @return Response
415+
* @throws RequestException
416+
*/
417+
public function installThemeFromRepository(int $id, string $name, string $version = null): Response
418+
{
419+
$request = (new Request())
420+
->setMethod(Request::METHOD_POST)
421+
->setUrl(sprintf('cmses/%d/themes', $id))
422+
->setBody([
423+
'name' => $name,
424+
'version' => $version,
425+
]);
426+
427+
$response = $this
428+
->client
429+
->request($request);
430+
if (!$response->isSuccess()) {
431+
return $response;
432+
}
433+
434+
// Retrieve the CMS again, so we log affected clusters and can return the CMS object
435+
$retrieveResponse = $this->get($id);
436+
if (!$retrieveResponse->isSuccess()) {
437+
return $retrieveResponse;
438+
}
439+
440+
$cms = $retrieveResponse->getData('cms');
441+
442+
// Log which cluster is affected by this change
443+
$this
444+
->client
445+
->addAffectedCluster($cms->getClusterId());
446+
447+
return $response->setData([
448+
'cms' => $cms,
449+
]);
450+
}
451+
452+
/**
453+
* @param int $id
454+
* @param string $url
455+
* @return Response
456+
* @throws RequestException
457+
*/
458+
public function installThemeFromUrl(int $id, string $url): Response
459+
{
460+
$request = (new Request())
461+
->setMethod(Request::METHOD_POST)
462+
->setUrl(sprintf('cmses/%d/themes', $id))
463+
->setBody([
464+
'url' => $url,
465+
]);
466+
467+
$response = $this
468+
->client
469+
->request($request);
470+
if (!$response->isSuccess()) {
471+
return $response;
472+
}
473+
474+
// Retrieve the CMS again, so we log affected clusters and can return the CMS object
475+
$retrieveResponse = $this->get($id);
476+
if (!$retrieveResponse->isSuccess()) {
477+
return $retrieveResponse;
478+
}
479+
480+
$cms = $retrieveResponse->getData('cms');
481+
482+
// Log which cluster is affected by this change
483+
$this
484+
->client
485+
->addAffectedCluster($cms->getClusterId());
486+
487+
return $response->setData([
488+
'cms' => $cms,
489+
]);
490+
}
491+
492+
/**
493+
* @param int $id
494+
* @param int $userId
495+
* @param CmsUserCredentials $cmsUserCredentials
496+
* @return Response
497+
* @throws RequestException
498+
*/
499+
public function updateUserCredentials(int $id, int $userId, CmsUserCredentials $cmsUserCredentials): Response
500+
{
501+
$this->validateRequired($cmsUserCredentials, 'update', [
502+
'password',
503+
]);
504+
505+
$request = (new Request())
506+
->setMethod(Request::METHOD_PATCH)
507+
->setUrl(sprintf('cmses/%d/users/%d/credentials', $id, $userId))
508+
->setBody($this->filterFields($cmsUserCredentials->toArray(), [
509+
'password',
510+
]));
511+
512+
$response = $this
513+
->client
514+
->request($request);
515+
if (!$response->isSuccess()) {
516+
return $response;
517+
}
518+
519+
// Retrieve the CMS again, so we log affected clusters and can return the CMS object
520+
$retrieveResponse = $this->get($id);
521+
if (!$retrieveResponse->isSuccess()) {
522+
return $retrieveResponse;
523+
}
524+
525+
$cms = $retrieveResponse->getData('cms');
526+
527+
// Log which cluster is affected by this change
528+
$this
529+
->client
530+
->addAffectedCluster($cms->getClusterId());
531+
532+
return $response->setData([
533+
'cms' => $cms,
534+
]);
535+
}
408536
}

src/Models/CmsUserCredentials.php

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Cyberfusion\ClusterApi\Models;
4+
5+
use Cyberfusion\ClusterApi\Contracts\Model;
6+
use Cyberfusion\ClusterApi\Support\Arr;
7+
use Cyberfusion\ClusterApi\Support\Validator;
8+
9+
class CmsUserCredentials extends ClusterModel implements Model
10+
{
11+
private string $password;
12+
13+
public function getPassword(): string
14+
{
15+
return $this->password;
16+
}
17+
18+
public function setPassword(string $password): self
19+
{
20+
Validator::value($password)
21+
->minLength(24)
22+
->maxLength(255)
23+
->pattern('^[ -~]+$')
24+
->validate();
25+
26+
$this->password = $password;
27+
28+
return $this;
29+
}
30+
31+
public function fromArray(array $data): self
32+
{
33+
return $this
34+
->setPassword(Arr::get($data, 'password'));
35+
}
36+
37+
public function toArray(): array
38+
{
39+
return [
40+
'password' => $this->getPassword(),
41+
];
42+
}
43+
}

0 commit comments

Comments
 (0)