-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into bugfix/acp-4499-mes…
…sage-broker-conditional-channels-handling
- Loading branch information
Showing
12 changed files
with
498 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/Spryker/Glue/AppKernel/Plugin/GlueApplication/AppConfigForTenantValidatorPlugin.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace Spryker\Glue\AppKernel\Plugin\GlueApplication; | ||
|
||
use Generated\Shared\Transfer\GlueRequestTransfer; | ||
use Generated\Shared\Transfer\GlueRequestValidationTransfer; | ||
use Spryker\Glue\GlueApplicationExtension\Dependency\Plugin\RequestValidatorPluginInterface; | ||
use Spryker\Glue\Kernel\AbstractPlugin; | ||
|
||
/** | ||
* @method \Spryker\Glue\AppKernel\AppKernelFactory getFactory() | ||
*/ | ||
class AppConfigForTenantValidatorPlugin extends AbstractPlugin implements RequestValidatorPluginInterface | ||
{ | ||
public function validate(GlueRequestTransfer $glueRequestTransfer): GlueRequestValidationTransfer | ||
{ | ||
return $this->getFactory()->createAppConfigForTenantValidator()->validate($glueRequestTransfer); | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
src/Spryker/Glue/AppKernel/Validator/AppConfigForTenantValidator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace Spryker\Glue\AppKernel\Validator; | ||
|
||
use Generated\Shared\Transfer\AppConfigCriteriaTransfer; | ||
use Generated\Shared\Transfer\GlueErrorTransfer; | ||
use Generated\Shared\Transfer\GlueRequestTransfer; | ||
use Generated\Shared\Transfer\GlueRequestValidationTransfer; | ||
use Spryker\Glue\AppKernel\AppKernelConfig; | ||
use Spryker\Glue\AppKernel\Dependency\Facade\AppKernelToAppKernelFacadeInterface; | ||
use Spryker\Shared\Log\LoggerTrait; | ||
use Spryker\Zed\AppKernel\AppKernelConfig as AppKernelAppKernelConfig; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Throwable; | ||
|
||
class AppConfigForTenantValidator | ||
{ | ||
use LoggerTrait; | ||
|
||
public function __construct(protected AppKernelToAppKernelFacadeInterface $appKernelToAppKernelFacade, protected AppKernelConfig $appKernelConfig) | ||
{ | ||
} | ||
|
||
public function validate(GlueRequestTransfer $glueRequestTransfer): GlueRequestValidationTransfer | ||
{ | ||
$glueRequestValidationTransfer = new GlueRequestValidationTransfer(); | ||
$glueRequestValidationTransfer->setIsValid(true); | ||
|
||
if ($this->isPathExcludedFromValidation($glueRequestTransfer)) { | ||
return $glueRequestValidationTransfer; | ||
} | ||
|
||
$tenantIdentifier = $this->getTenantIdentifier($glueRequestTransfer); | ||
|
||
$appConfigCriteriaTransfer = new AppConfigCriteriaTransfer(); | ||
$appConfigCriteriaTransfer->setTenantIdentifier($tenantIdentifier); | ||
|
||
try { | ||
$appConfigTransfer = $this->appKernelToAppKernelFacade->getConfig($appConfigCriteriaTransfer); | ||
if ($appConfigTransfer->getStatus() === AppKernelAppKernelConfig::APP_STATUS_DISCONNECTED) { | ||
$glueErrorTransfer = new GlueErrorTransfer(); | ||
$glueErrorTransfer->setMessage('Tenant is disconnected.'); | ||
|
||
$glueRequestValidationTransfer | ||
->setIsValid(false) | ||
->setStatus(Response::HTTP_FORBIDDEN) | ||
->addError($glueErrorTransfer); | ||
} | ||
} catch (Throwable $throwable) { | ||
$this->getLogger()->error( | ||
$throwable->getMessage(), | ||
$glueRequestTransfer->toArray(), | ||
); | ||
|
||
$glueErrorTransfer = new GlueErrorTransfer(); | ||
$glueErrorTransfer | ||
->setMessage($throwable->getMessage()); | ||
|
||
$glueRequestValidationTransfer | ||
->setIsValid(false) | ||
->addError($glueErrorTransfer) | ||
->setStatus(Response::HTTP_INTERNAL_SERVER_ERROR); | ||
|
||
return $glueRequestValidationTransfer; | ||
} | ||
|
||
return $glueRequestValidationTransfer; | ||
} | ||
|
||
protected function isPathExcludedFromValidation(GlueRequestTransfer $glueRequestTransfer): bool | ||
{ | ||
return in_array($glueRequestTransfer->getPath(), $this->appKernelConfig->getAppConfigRequestValidationExcludedPaths()); | ||
} | ||
|
||
protected function getTenantIdentifier(GlueRequestTransfer $glueRequestTransfer): ?string | ||
{ | ||
$meta = $glueRequestTransfer->getMeta(); | ||
|
||
if (!isset($meta['x-tenant-identifier'])) { | ||
return null; | ||
} | ||
|
||
$tenantIdentifier = $meta['x-tenant-identifier']; | ||
|
||
if (is_array($tenantIdentifier)) { | ||
return $tenantIdentifier[0]; | ||
} | ||
|
||
return $tenantIdentifier; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.