feat: add HTTP 451 error code if needed

This commit is contained in:
Maël Gangloff 2024-08-06 22:11:57 +02:00
parent e393bcf0af
commit 504e609579
No known key found for this signature in database
GPG Key ID: 11FDC81C24A7F629
2 changed files with 14 additions and 7 deletions

View File

@ -6,6 +6,7 @@ use App\Entity\Domain;
use Symfony\Component\HttpClient\HttpOptions;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
@ -102,13 +103,16 @@ readonly class GandiConnector implements ConnectorInterface
if (!is_string($token) || empty($token)
|| (array_key_exists('sharingId', $authData) && !is_string($authData['sharingId']))
|| true !== $acceptConditions
|| true !== $ownerLegalAge
|| true !== $waiveRetractationPeriod
) {
throw new BadRequestHttpException('Bad authData schema');
}
if (true !== $acceptConditions
|| true !== $ownerLegalAge
|| true !== $waiveRetractationPeriod) {
throw new HttpException(451, 'The user has not given explicit consent', null, ['Link' => '<https://www.gandi.net/en/contracts/terms-of-service>; rel="blocked-by"']);
}
$response = $client->request('GET', '/v5/organization/user-info', (new HttpOptions())
->setAuthBearer($token)
->setHeader('Accept', 'application/json')

View File

@ -4,6 +4,7 @@ namespace App\Config\Connector;
use App\Entity\Domain;
use Ovh\Api;
use Symfony\Component\HttpKernel\Exception\HttpException;
readonly class OvhConnector implements ConnectorInterface
{
@ -136,14 +137,16 @@ readonly class OvhConnector implements ConnectorInterface
|| !is_string($apiEndpoint) || empty($apiEndpoint)
|| !is_string($ovhSubsidiary) || empty($ovhSubsidiary)
|| !is_string($pricingMode) || empty($pricingMode)
|| true !== $acceptConditions
|| true !== $ownerLegalAge
|| true !== $waiveRetractationPeriod
) {
throw new \Exception('Bad authData schema');
}
if (true !== $acceptConditions
|| true !== $ownerLegalAge
|| true !== $waiveRetractationPeriod) {
throw new HttpException(451, 'The user has not given explicit consent', null, ['Link' => '<https://www.ovhcloud.com/fr/terms-and-conditions/contracts/>; rel="blocked-by"']);
}
$conn = new Api(
$appKey,
$appSecret,