Skip to content

Commit

Permalink
Merge branch 'main' into feature/PPF-502
Browse files Browse the repository at this point in the history
  • Loading branch information
Anahkiasen authored Jun 6, 2024
2 parents 45d5cff + 4362ef1 commit a7a79db
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 20 deletions.
5 changes: 4 additions & 1 deletion app/Auth0/Auth0ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use App\Auth0\Repositories\EloquentAuth0ClientRepository;
use App\Domain\Integrations\Events\IntegrationBlocked;
use App\Domain\Integrations\Events\IntegrationCreated;
use App\Domain\Integrations\Events\IntegrationDeleted;
use App\Domain\Integrations\Events\IntegrationUnblocked;
use App\Domain\Integrations\Events\IntegrationUpdated;
use App\Domain\Integrations\Events\IntegrationUrlCreated;
Expand Down Expand Up @@ -97,17 +98,19 @@ public function register(): void
// May always be registered even if there are no configured tenants, because in that case the cluster SDK will
// just not have any tenant SDKs to loop over and so it simply won't do anything. But it won't crash either.
Event::listen(IntegrationCreated::class, [CreateClients::class, 'handle']);
Event::listen(CreateMissingClients::class, [CreateMissingClientsHandler::class, 'handle']);
Event::listen(IntegrationUpdated::class, [UpdateClients::class, 'handle']);
Event::listen(IntegrationBlocked::class, [BlockClients::class, 'handle']);
Event::listen(IntegrationUnblocked::class, [UnblockClients::class, 'handle']);
Event::listen(IntegrationDeleted::class, [BlockClients::class, 'handle']);

Event::listen(IntegrationUrlCreated::class, [UpdateClients::class, 'handle']);
Event::listen(IntegrationUrlUpdated::class, [UpdateClients::class, 'handle']);
Event::listen(IntegrationUrlDeleted::class, [UpdateClients::class, 'handle']);

Event::listen(UnblockClient::class, [UnblockClientHandler::class, 'handle']);
Event::listen(BlockClient::class, [BlockClientHandler::class, 'handle']);

Event::listen(CreateMissingClients::class, [CreateMissingClientsHandler::class, 'handle']);
}
}
}
11 changes: 6 additions & 5 deletions app/Auth0/Listeners/BlockClients.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Auth0\Auth0ClusterSDK;
use App\Auth0\Repositories\Auth0ClientRepository;
use App\Domain\Integrations\Events\IntegrationBlocked;
use App\Domain\Integrations\Events\IntegrationDeleted;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Psr\Log\LoggerInterface;
Expand All @@ -23,25 +24,25 @@ public function __construct(
) {
}

public function handle(IntegrationBlocked $integrationBlocked): void
public function handle(IntegrationBlocked|IntegrationDeleted $event): void
{
$auth0Clients = $this->auth0ClientRepository->getByIntegrationId($integrationBlocked->id);
$auth0Clients = $this->auth0ClientRepository->getByIntegrationId($event->id);

$this->clusterSDK->blockClients(...$auth0Clients);

$this->logger->info(
'Auth0 client(s) blocked',
[
'domain' => 'auth0',
'integration_id' => $integrationBlocked->id->toString(),
'integration_id' => $event->id->toString(),
]
);
}

public function failed(IntegrationBlocked $integrationBlocked, Throwable $throwable): void
public function failed(IntegrationBlocked|IntegrationDeleted $event, Throwable $throwable): void
{
$this->logger->error('Failed to block Auth0 client(s)', [
'integration_id' => $integrationBlocked->id->toString(),
'integration_id' => $event->id->toString(),
'exception' => $throwable,
]);
}
Expand Down
13 changes: 7 additions & 6 deletions app/UiTiDv1/Listeners/BlockConsumers.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\UiTiDv1\Listeners;

use App\Domain\Integrations\Events\IntegrationBlocked;
use App\Domain\Integrations\Events\IntegrationDeleted;
use App\Domain\Integrations\Repositories\IntegrationRepository;
use App\UiTiDv1\Repositories\UiTiDv1ConsumerRepository;
use App\UiTiDv1\UiTiDv1ClusterSDK;
Expand All @@ -25,26 +26,26 @@ public function __construct(
) {
}

public function handle(IntegrationBlocked $integrationBlocked): void
public function handle(IntegrationBlocked|IntegrationDeleted $event): void
{
$consumers = $this->consumerRepository->getByIntegrationId($integrationBlocked->id);
$consumers = $this->consumerRepository->getByIntegrationId($event->id);

$integration = $this->integrationRepository->getById($integrationBlocked->id);
$integration = $this->integrationRepository->getByIdWithTrashed($event->id);
$this->clusterSDK->blockConsumers($integration, ... $consumers);

$this->logger->info(
'UiTiD v1 consumer(s) blocked',
[
'domain' => 'uitid',
'integration_id' => $integrationBlocked->id->toString(),
'integration_id' => $event->id->toString(),
]
);
}

public function failed(IntegrationBlocked $integrationBlocked, Throwable $throwable): void
public function failed(IntegrationBlocked|IntegrationDeleted $event, Throwable $throwable): void
{
$this->logger->error('Failed to block UiTiD v1 consumer(s)', [
'integration_id' => $integrationBlocked->id->toString(),
'integration_id' => $event->id->toString(),
'exception' => $throwable,
]);
}
Expand Down
5 changes: 4 additions & 1 deletion app/UiTiDv1/UiTiDv1ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Domain\Integrations\Events\IntegrationBlocked;
use App\Domain\Integrations\Events\IntegrationCreated;
use App\Domain\Integrations\Events\IntegrationDeleted;
use App\Domain\Integrations\Events\IntegrationUnblocked;
use App\Domain\Integrations\Events\IntegrationUpdated;
use App\UiTiDv1\Jobs\UnblockConsumer;
Expand Down Expand Up @@ -75,13 +76,15 @@ public function register(): void
// May always be registered even if there are no configured environments, because in that case the cluster SDK
// will just not have any environment SDKs to loop over and so it simply won't do anything. But it won't crash either.
Event::listen(IntegrationCreated::class, [CreateConsumers::class, 'handle']);
Event::listen(CreateMissingConsumers::class, [CreateMissingConsumersHandler::class, 'handle']);
Event::listen(IntegrationUpdated::class, [UpdateConsumers::class, 'handle']);
Event::listen(IntegrationBlocked::class, [BlockConsumers::class, 'handle']);
Event::listen(IntegrationUnblocked::class, [UnblockConsumers::class, 'handle']);
Event::listen(IntegrationDeleted::class, [BlockConsumers::class, 'handle']);

Event::listen(UnblockConsumer::class, [UnblockConsumerHandler::class, 'handle']);
Event::listen(BlockConsumer::class, [BlockConsumerHandler::class, 'handle']);

Event::listen(CreateMissingConsumers::class, [CreateMissingConsumersHandler::class, 'handle']);
}
}
}
15 changes: 12 additions & 3 deletions tests/Auth0/Listeners/BlockClientsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
use App\Auth0\Listeners\BlockClients;
use App\Auth0\Repositories\Auth0ClientRepository;
use App\Domain\Integrations\Events\IntegrationBlocked;
use App\Domain\Integrations\Events\IntegrationDeleted;
use App\Json;
use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Psr\Http\Client\ClientInterface;
Expand Down Expand Up @@ -44,9 +46,16 @@ protected function setUp(): void
);
}

public function test_it_blocks_clients(): void
public static function integrationEventsProvider(): \Generator
{
$integrationId = Uuid::uuid4();
yield 'Integration blocked' => [new IntegrationBlocked(Uuid::uuid4())];
yield 'Integration deleted' => [new IntegrationDeleted(Uuid::uuid4())];
}

#[dataProvider('integrationEventsProvider')]
public function test_it_blocks_clients(IntegrationBlocked|IntegrationDeleted $event): void
{
$integrationId = $event->id;

$clients = [
new Auth0Client(Uuid::uuid4(), $integrationId, 'client-id-1', 'client-secret-1', Auth0Tenant::Acceptance),
Expand Down Expand Up @@ -83,6 +92,6 @@ public function test_it_blocks_clients(): void
}
);

$this->blockClients->handle(new IntegrationBlocked($integrationId));
$this->blockClients->handle($event);
}
}
17 changes: 13 additions & 4 deletions tests/UiTiDv1/Listeners/BlockConsumersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
namespace Tests\UiTiDv1\Listeners;

use App\Domain\Integrations\Events\IntegrationBlocked;
use App\Domain\Integrations\Events\IntegrationDeleted;
use App\Domain\Integrations\Repositories\IntegrationRepository;
use App\UiTiDv1\Listeners\BlockConsumers;
use App\UiTiDv1\Repositories\UiTiDv1ConsumerRepository;
use App\UiTiDv1\UiTiDv1Consumer;
use App\UiTiDv1\UiTiDv1Environment;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -43,9 +45,16 @@ protected function setUp(): void
);
}

public function test_it_blocks_consumers(): void
public static function integrationEventsProvider(): \Generator
{
$integrationId = Uuid::uuid4();
yield 'Integration blocked' => [new IntegrationBlocked(Uuid::uuid4())];
yield 'Integration deleted' => [new IntegrationDeleted(Uuid::uuid4())];
}

#[dataProvider('integrationEventsProvider')]
public function test_it_blocks_consumers(IntegrationBlocked|IntegrationDeleted $event): void
{
$integrationId = $event->id;

$consumers = [
new UiTiDv1Consumer(
Expand Down Expand Up @@ -83,7 +92,7 @@ public function test_it_blocks_consumers(): void
->willReturn($consumers);

$this->integrationRepository->expects($this->once())
->method('getById')
->method('getByIdWithTrashed')
->willReturn($this->givenThereIsAnIntegration($integrationId));

$this->httpClient->expects($this->exactly(3))
Expand Down Expand Up @@ -122,6 +131,6 @@ public function test_it_blocks_consumers(): void
}
);

$this->blockConsumers->handle(new IntegrationBlocked($integrationId));
$this->blockConsumers->handle($event);
}
}

0 comments on commit a7a79db

Please sign in to comment.