fix: connector creation

This commit is contained in:
Maël Gangloff
2024-08-06 00:35:05 +02:00
parent 6f3c780e42
commit da1ae4cb8e
4 changed files with 41 additions and 2 deletions

View File

@@ -7,6 +7,28 @@ use Ovh\Api;
readonly class OvhConnector implements ConnectorInterface
{
public const REQUIRED_ROUTES = [
[
'method' => 'GET',
'path' => '/order/cart',
], [
'method' => 'GET',
'path' => '/order/cart/*',
],
[
'method' => 'POST',
'path' => '/order/cart',
],
[
'method' => 'POST',
'path' => '/order/cart/*',
],
[
'method' => 'DELETE',
'path' => '/order/cart/*',
],
];
public function __construct(private array $authData)
{
}
@@ -139,6 +161,23 @@ readonly class OvhConnector implements ConnectorInterface
throw new \Exception("The status of these credentials is not valid ($status)");
}
foreach (self::REQUIRED_ROUTES as $requiredRoute) {
$ok = false;
foreach ($res['rules'] as $allowedRoute) {
if (
$requiredRoute['method'] === $allowedRoute['method']
&& fnmatch($allowedRoute['path'], $requiredRoute['path'])
) {
$ok = true;
}
}
if (!$ok) {
throw new \Exception('The credentials provided do not have enough permissions to purchase a domain name.');
}
}
return [
'appKey' => $appKey,
'appSecret' => $appSecret,