-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CC-33738 Audit Logs with CloudWatch. (#10986)
CC-33738 Audit Logs with CloudWatch
- Loading branch information
1 parent
5038003
commit 98f224b
Showing
10 changed files
with
437 additions
and
0 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?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\Yves\Customer; | ||
|
||
use Spryker\Yves\Kernel\AbstractBundleDependencyProvider; | ||
use Spryker\Yves\Kernel\Container; | ||
|
||
/** | ||
* @method \Spryker\Yves\Customer\CustomerConfig getConfig() | ||
*/ | ||
class CustomerDependencyProvider extends AbstractBundleDependencyProvider | ||
{ | ||
/** | ||
* @uses \Spryker\Yves\Http\Plugin\Application\HttpApplicationPlugin::SERVICE_REQUEST_STACK | ||
* | ||
* @var string | ||
*/ | ||
public const SERVICE_REQUEST_STACK = 'request_stack'; | ||
|
||
/** | ||
* @param \Spryker\Yves\Kernel\Container $container | ||
* | ||
* @return \Spryker\Yves\Kernel\Container | ||
*/ | ||
public function provideDependencies(Container $container): Container | ||
{ | ||
$container = $this->addRequestStackService($container); | ||
|
||
return $container; | ||
} | ||
|
||
/** | ||
* @param \Spryker\Yves\Kernel\Container $container | ||
* | ||
* @return \Spryker\Yves\Kernel\Container | ||
*/ | ||
protected function addRequestStackService(Container $container): Container | ||
{ | ||
$container->set(static::SERVICE_REQUEST_STACK, function (Container $container) { | ||
return $container->getApplicationService(static::SERVICE_REQUEST_STACK); | ||
}); | ||
|
||
return $container; | ||
} | ||
} |
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,32 @@ | ||
<?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\Yves\Customer; | ||
|
||
use Spryker\Yves\Customer\Processor\CurrentCustomerDataRequestLogProcessor; | ||
use Spryker\Yves\Customer\Processor\CurrentCustomerDataRequestLogProcessorInterface; | ||
use Spryker\Yves\Kernel\AbstractFactory; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
|
||
class CustomerFactory extends AbstractFactory | ||
{ | ||
/** | ||
* @return \Spryker\Yves\Customer\Processor\CurrentCustomerDataRequestLogProcessorInterface | ||
*/ | ||
public function createCurrentCustomerDataRequestLogProcessor(): CurrentCustomerDataRequestLogProcessorInterface | ||
{ | ||
return new CurrentCustomerDataRequestLogProcessor($this->getRequestStackService()); | ||
} | ||
|
||
/** | ||
* @return \Symfony\Component\HttpFoundation\RequestStack | ||
*/ | ||
public function getRequestStackService(): RequestStack | ||
{ | ||
return $this->getProvidedDependency(CustomerDependencyProvider::SERVICE_REQUEST_STACK); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Spryker/Yves/Customer/Plugin/Log/CurrentCustomerDataRequestProcessorPlugin.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,33 @@ | ||
<?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\Yves\Customer\Plugin\Log; | ||
|
||
use Spryker\Shared\Log\Dependency\Plugin\LogProcessorPluginInterface; | ||
use Spryker\Yves\Kernel\AbstractPlugin; | ||
|
||
/** | ||
* @method \Spryker\Yves\Customer\CustomerFactory getFactory() | ||
* @method \Spryker\Yves\Customer\CustomerConfig getConfig() | ||
*/ | ||
class CurrentCustomerDataRequestProcessorPlugin extends AbstractPlugin implements LogProcessorPluginInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
* - Adds customer email and customer reference from the current request. | ||
* | ||
* @api | ||
* | ||
* @param array<string, mixed> $data | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function __invoke(array $data): array | ||
{ | ||
return $this->getFactory()->createCurrentCustomerDataRequestLogProcessor()->__invoke($data); | ||
} | ||
} |
123 changes: 123 additions & 0 deletions
123
src/Spryker/Yves/Customer/Processor/CurrentCustomerDataRequestLogProcessor.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,123 @@ | ||
<?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\Yves\Customer\Processor; | ||
|
||
use Generated\Shared\Transfer\CustomerTransfer; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
|
||
class CurrentCustomerDataRequestLogProcessor implements CurrentCustomerDataRequestLogProcessorInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected const RECORD_KEY_EXTRA = 'extra'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected const RECORD_KEY_REQUEST = 'request'; | ||
|
||
/** | ||
* @uses \Spryker\Client\Customer\Session\CustomerSession::SESSION_KEY | ||
* | ||
* @var string | ||
*/ | ||
protected const SESSION_KEY_CUSTOMER_DATA = 'customer data'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected const RECORD_KEY_USERNAME = 'username'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected const RECORD_KEY_CUSTOMER_REFERENCE = 'customer_reference'; | ||
|
||
/** | ||
* @var \Symfony\Component\HttpFoundation\RequestStack | ||
*/ | ||
protected RequestStack $requestStack; | ||
|
||
/** | ||
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack | ||
*/ | ||
public function __construct(RequestStack $requestStack) | ||
{ | ||
$this->requestStack = $requestStack; | ||
} | ||
|
||
/** | ||
* @param array<string, mixed> $data | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function __invoke(array $data): array | ||
{ | ||
$customerTransfer = $this->findCurrentCustomer(); | ||
|
||
if (!$customerTransfer) { | ||
return $data; | ||
} | ||
|
||
$currentRequestData = $this->getCurrentRequestData($customerTransfer); | ||
|
||
if (isset($data[static::RECORD_KEY_EXTRA][static::RECORD_KEY_REQUEST])) { | ||
$data[static::RECORD_KEY_EXTRA][static::RECORD_KEY_REQUEST] = array_merge( | ||
$data[static::RECORD_KEY_EXTRA][static::RECORD_KEY_REQUEST], | ||
$currentRequestData, | ||
); | ||
|
||
return $data; | ||
} | ||
|
||
$data[static::RECORD_KEY_EXTRA][static::RECORD_KEY_REQUEST] = $currentRequestData; | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* @return \Generated\Shared\Transfer\CustomerTransfer|null | ||
*/ | ||
protected function findCurrentCustomer(): ?CustomerTransfer | ||
{ | ||
$currentRequest = $this->requestStack->getCurrentRequest(); | ||
|
||
if (!$currentRequest || !$currentRequest->hasSession()) { | ||
return null; | ||
} | ||
|
||
return $this->findCustomerInRequest($currentRequest); | ||
} | ||
|
||
/** | ||
* @param \Generated\Shared\Transfer\CustomerTransfer $customerTransfer | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
protected function getCurrentRequestData(CustomerTransfer $customerTransfer): array | ||
{ | ||
$currentRequestData = []; | ||
|
||
$currentRequestData[static::RECORD_KEY_USERNAME] = $customerTransfer->getEmail(); | ||
$currentRequestData[static::RECORD_KEY_CUSTOMER_REFERENCE] = $customerTransfer->getCustomerReference(); | ||
|
||
return $currentRequestData; | ||
} | ||
|
||
/** | ||
* @param \Symfony\Component\HttpFoundation\Request $request | ||
* | ||
* @return \Generated\Shared\Transfer\CustomerTransfer|null | ||
*/ | ||
protected function findCustomerInRequest(Request $request): ?CustomerTransfer | ||
{ | ||
return $request->getSession()->get(static::SESSION_KEY_CUSTOMER_DATA); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Spryker/Yves/Customer/Processor/CurrentCustomerDataRequestLogProcessorInterface.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,18 @@ | ||
<?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\Yves\Customer\Processor; | ||
|
||
interface CurrentCustomerDataRequestLogProcessorInterface | ||
{ | ||
/** | ||
* @param array<string, mixed> $data | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function __invoke(array $data): array; | ||
} |
Oops, something went wrong.