Skip to content

Commit

Permalink
add tenant limiter, move event subscription to webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Mar 16, 2024
1 parent 8900d34 commit 0abb57d
Show file tree
Hide file tree
Showing 128 changed files with 2,663 additions and 1,646 deletions.
5 changes: 5 additions & 0 deletions resources/container.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Fusio\Impl\Repository as ImplRepository;
use Fusio\Impl\Service\Action\Producer;
use Fusio\Impl\Service\Event\Dispatcher;
use Fusio\Impl\Service\Tenant\LimiterInterface;
use Fusio\Impl\Tenant\UnlimitedLimiter;
use Psr\Cache\CacheItemPoolInterface;
use Psr\SimpleCache\CacheInterface;
use PSX\Api;
Expand Down Expand Up @@ -96,6 +98,9 @@
$services->set(Framework\Loader\ContextFactory::class);
$services->alias(ContextFactoryInterface::class, Framework\Loader\ContextFactory::class);

$services->set(UnlimitedLimiter::class);
$services->alias(LimiterInterface::class, UnlimitedLimiter::class);

// psx
$services->set(Framework\Loader\RoutingParser\DatabaseParser::class);
$services->set(Framework\Loader\RoutingParser\CompositeParser::class);
Expand Down
8 changes: 4 additions & 4 deletions src/Authorization/UserContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ public static function newContext(int $userId, ?int $appId = null, ?string $tena
return new UserContext($userId, $appId, $_SERVER['REMOTE_ADDR'] ?? '127.0.0.1', $tenantId);
}

public static function newAnonymousContext(): self
public static function newAnonymousContext(?string $tenantId = null): self
{
return self::newContext(1, 1);
return self::newContext(1, 1, $tenantId);
}

public static function newCommandContext(): self
public static function newCommandContext(?string $tenantId = null): self
{
return self::newContext(1, 1);
return self::newContext(1, 1, $tenantId);
}

public static function newActionContext(ContextInterface $context): self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@
* limitations under the License.
*/

namespace Fusio\Impl\Backend\Action\Event\Subscription;
namespace Fusio\Impl\Backend\Action\Webhook;

use Fusio\Engine\Action\RuntimeInterface;
use Fusio\Engine\ActionAbstract;
use Fusio\Engine\ActionInterface;
use Fusio\Engine\ContextInterface;
use Fusio\Engine\ParametersInterface;
use Fusio\Engine\RequestInterface;
use Fusio\Impl\Authorization\UserContext;
use Fusio\Impl\Service\Event;
use Fusio\Model\Backend\EventSubscriptionCreate;
use Fusio\Impl\Service;
use Fusio\Model\Backend\WebhookCreate;
use PSX\Http\Environment\HttpResponse;

/**
Expand All @@ -40,27 +38,27 @@
*/
class Create implements ActionInterface
{
private Event\Subscription $subscriptionService;
private Service\Webhook $webhookService;

public function __construct(Event\Subscription $subscriptionService)
public function __construct(Service\Webhook $webhookService)
{
$this->subscriptionService = $subscriptionService;
$this->webhookService = $webhookService;
}

public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed
{
$body = $request->getPayload();

assert($body instanceof EventSubscriptionCreate);
assert($body instanceof WebhookCreate);

$this->subscriptionService->create(
$this->webhookService->create(
$body,
UserContext::newActionContext($context)
);

return new HttpResponse(201, [], [
'success' => true,
'message' => 'Subscription successfully created',
'message' => 'Webhook successfully created',
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@
* limitations under the License.
*/

namespace Fusio\Impl\Consumer\Action\Event\Subscription;
namespace Fusio\Impl\Backend\Action\Webhook;

use Fusio\Engine\Action\RuntimeInterface;
use Fusio\Engine\ActionAbstract;
use Fusio\Engine\ActionInterface;
use Fusio\Engine\ContextInterface;
use Fusio\Engine\ParametersInterface;
use Fusio\Engine\RequestInterface;
use Fusio\Impl\Authorization\UserContext;
use Fusio\Impl\Service\Consumer\Subscription;
use Fusio\Impl\Service;

/**
* Delete
Expand All @@ -38,23 +36,23 @@
*/
class Delete implements ActionInterface
{
private Subscription $subscriptionService;
private Service\Webhook $webhookService;

public function __construct(Subscription $subscriptionService)
public function __construct(Service\Webhook $webhookService)
{
$this->subscriptionService = $subscriptionService;
$this->webhookService = $webhookService;
}

public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed
{
$this->subscriptionService->delete(
(int) $request->get('subscription_id'),
$this->webhookService->delete(
$request->get('webhook_id'),
UserContext::newActionContext($context)
);

return [
'success' => true,
'message' => 'Subscription successfully deleted',
'message' => 'Webhook successfully deleted',
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* limitations under the License.
*/

namespace Fusio\Impl\Backend\Action\Event\Subscription;
namespace Fusio\Impl\Backend\Action\Webhook;

use Fusio\Engine\Action\RuntimeInterface;
use Fusio\Engine\ActionAbstract;
Expand All @@ -39,22 +39,22 @@
*/
class Get implements ActionInterface
{
private View\Event\Subscription $view;
private View\Webhook $view;

public function __construct(View\Event\Subscription $view)
public function __construct(View\Webhook $view)
{
$this->view = $view;
}

public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed
{
$subscription = $this->view->getEntity(
(int) $request->get('subscription_id'),
$request->get('webhook_id'),
$context
);

if (empty($subscription)) {
throw new StatusCode\NotFoundException('Could not find subscription');
throw new StatusCode\NotFoundException('Could not find webhook');
}

return $subscription;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* limitations under the License.
*/

namespace Fusio\Impl\Backend\Action\Event\Subscription;
namespace Fusio\Impl\Backend\Action\Webhook;

use Fusio\Engine\Action\RuntimeInterface;
use Fusio\Engine\ActionAbstract;
Expand All @@ -39,9 +39,9 @@
*/
class GetAll implements ActionInterface
{
private View\Event\Subscription $view;
private View\Webhook $view;

public function __construct(View\Event\Subscription $view)
public function __construct(View\Webhook $view)
{
$this->view = $view;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@
* limitations under the License.
*/

namespace Fusio\Impl\Backend\Action\Event\Subscription;
namespace Fusio\Impl\Backend\Action\Webhook;

use Fusio\Engine\Action\RuntimeInterface;
use Fusio\Engine\ActionAbstract;
use Fusio\Engine\ActionInterface;
use Fusio\Engine\ContextInterface;
use Fusio\Engine\ParametersInterface;
use Fusio\Engine\RequestInterface;
use Fusio\Impl\Authorization\UserContext;
use Fusio\Impl\Service\Event;
use Fusio\Model\Backend\EventSubscriptionUpdate;
use Fusio\Impl\Service;
use Fusio\Model\Backend\WebhookUpdate;

/**
* Update
Expand All @@ -39,28 +37,28 @@
*/
class Update implements ActionInterface
{
private Event\Subscription $subscriptionService;
private Service\Webhook $webhookService;

public function __construct(Event\Subscription $subscriptionService)
public function __construct(Service\Webhook $webhookService)
{
$this->subscriptionService = $subscriptionService;
$this->webhookService = $webhookService;
}

public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed
{
$body = $request->getPayload();

assert($body instanceof EventSubscriptionUpdate);
assert($body instanceof WebhookUpdate);

$this->subscriptionService->update(
(int) $request->get('subscription_id'),
$this->webhookService->update(
$request->get('webhook_id'),
$body,
UserContext::newActionContext($context)
);

return [
'success' => true,
'message' => 'Subscription successfully updated',
'message' => 'Webhook successfully updated',
];
}
}
127 changes: 0 additions & 127 deletions src/Backend/View/Event/Subscription.php

This file was deleted.

Loading

0 comments on commit 0abb57d

Please sign in to comment.