Skip to content

Commit

Permalink
CC-34136 Quicksight user registration and persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
AsonUnique committed Aug 5, 2024
1 parent d1acbd9 commit d6154a9
Show file tree
Hide file tree
Showing 22 changed files with 940 additions and 4 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
},
"require-dev": {
"phpstan/phpstan": "*",
"spryker/code-sniffer": "*"
"spryker/code-sniffer": "*",
"spryker/propel": "*",
"spryker/testify": "*"
},
"autoload": {
"psr-4": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,34 @@
<property name="updatedAt" type="string"/>
</transfer>

<transfer name="UserCollectionResponse" strict="true">
<property name="users" type="User[]" singular="user"/>
<property name="errors" type="Error[]" singular="error"/>
</transfer>

<transfer name="User">
<property name="quicksightUser" type="QuicksightUser" strict="true"/>
<property name="idUser" type="int"/>
<property name="username" type="string"/>
</transfer>

<transfer name="QuicksightUserRegisterResponse" strict="true">
<property name="errors" type="Error[]" singular="error"/>
<property name="quicksightUser" type="QuicksightUser"/>
</transfer>

<transfer name="QuicksightUserRegisterRequest" strict="true">
<property name="awsAccountId" type="string"/>
<property name="email" type="string" />
<property name="identityType" type="string" />
<property name="namespace" type="string"/>
<property name="userRole" type="string" />
<property name="userName" type="string"/>
</transfer>

<transfer name="Error">
<property name="message" type="string"/>
<property name="entityIdentifier" type="string"/>
</transfer>

</transfers>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AmazonQuicksightConfig extends AbstractBundleConfig
/**
* @var string
*/
protected const QUICKSIGHT_USER_REGISTER_NAMESPACE = 'default';
protected const QUICKSIGHT_REGISTER_USER_NAMESPACE = 'default';

/**
* @var string
Expand Down Expand Up @@ -66,9 +66,9 @@ public function getAwsAccountId(): string
*
* @return string
*/
public function getQuicksightUserRegisterNamespace(): string
public function getQuicksightRegisterUserNamespace(): string
{
return static::QUICKSIGHT_USER_REGISTER_NAMESPACE;
return static::QUICKSIGHT_REGISTER_USER_NAMESPACE;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
namespace SprykerEco\Zed\AmazonQuicksight\Business;

use Spryker\Zed\Kernel\Business\AbstractBusinessFactory;
use SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightDependencyProvider;
use SprykerEco\Zed\AmazonQuicksight\Business\ApiClient\AmazonQuicksightApiClient;
use SprykerEco\Zed\AmazonQuicksight\Business\ApiClient\AmazonQuicksightApiClientInterface;
use SprykerEco\Zed\AmazonQuicksight\Business\Creator\QuicksightUserCreator;
use SprykerEco\Zed\AmazonQuicksight\Business\Creator\QuicksightUserCreatorInterface;
use SprykerEco\Zed\AmazonQuicksight\Business\Formatter\AmazonQuicksightRequestDataFormatter;
use SprykerEco\Zed\AmazonQuicksight\Business\Formatter\AmazonQuicksightRequestDataFormatterInterface;
use SprykerEco\Zed\AmazonQuicksight\Business\Mapper\AmazonQuicksightMapper;
use SprykerEco\Zed\AmazonQuicksight\Business\Mapper\AmazonQuicksightMapperInterface;
use SprykerEco\Zed\AmazonQuicksight\Dependency\External\AmazonQuicksightToAwsQuicksightClientInterface;

/**
* @method \SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig getConfig()
Expand All @@ -16,4 +26,51 @@
*/
class AmazonQuicksightBusinessFactory extends AbstractBusinessFactory
{
/**
* @return \SprykerEco\Zed\AmazonQuicksight\Business\Creator\QuicksightUserCreatorInterface
*/
public function createQuicksightUserCreator(): QuicksightUserCreatorInterface
{
return new QuicksightUserCreator(
$this->createAmazonQuicksightApiClient(),
$this->getEntityManager(),
);
}

/**
* @return \SprykerEco\Zed\AmazonQuicksight\Business\ApiClient\AmazonQuicksightApiClientInterface
*/
public function createAmazonQuicksightApiClient(): AmazonQuicksightApiClientInterface
{
return new AmazonQuicksightApiClient(
$this->getConfig(),
$this->createAmazonQuicksightMapper(),
$this->createAmazonQuicksightRequestDataFormatter(),
$this->getAwsQuicksightClient(),
);
}

/**
* @return \SprykerEco\Zed\AmazonQuicksight\Business\Mapper\AmazonQuicksightMapperInterface
*/
public function createAmazonQuicksightMapper(): AmazonQuicksightMapperInterface
{
return new AmazonQuicksightMapper();
}

/**
* @return \SprykerEco\Zed\AmazonQuicksight\Business\Formatter\AmazonQuicksightRequestDataFormatterInterface
*/
public function createAmazonQuicksightRequestDataFormatter(): AmazonQuicksightRequestDataFormatterInterface
{
return new AmazonQuicksightRequestDataFormatter();
}

/**
* @return \SprykerEco\Zed\AmazonQuicksight\Dependency\External\AmazonQuicksightToAwsQuicksightClientInterface
*/
public function getAwsQuicksightClient(): AmazonQuicksightToAwsQuicksightClientInterface
{
return $this->getProvidedDependency(AmazonQuicksightDependencyProvider::AWS_QUICKSIGHT_CLIENT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace SprykerEco\Zed\AmazonQuicksight\Business;

use Generated\Shared\Transfer\UserCollectionResponseTransfer;
use Spryker\Zed\Kernel\Business\AbstractFacade;

/**
Expand All @@ -16,4 +17,20 @@
*/
class AmazonQuicksightFacade extends AbstractFacade implements AmazonQuicksightFacadeInterface
{
/**
* {@inheritDoc}
*
* @api
*
* @param \Generated\Shared\Transfer\UserCollectionResponseTransfer $userCollectionResponseTransfer
*
* @return \Generated\Shared\Transfer\UserCollectionResponseTransfer
*/
public function createQuicksightUsersForUserTransfers(
UserCollectionResponseTransfer $userCollectionResponseTransfer

Check failure on line 30 in src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacade.php

View workflow job for this annotation

GitHub Actions / Validation

Parameter $userCollectionResponseTransfer of method SprykerEco\Zed\AmazonQuicksight\Business\AmazonQuicksightFacade::createQuicksightUsersForUserTransfers() has invalid typehint type Generated\Shared\Transfer\UserCollectionResponseTransfer.

Check failure on line 30 in src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacade.php

View workflow job for this annotation

GitHub Actions / Validation

Parameter $userCollectionResponseTransfer of method SprykerEco\Zed\AmazonQuicksight\Business\AmazonQuicksightFacade::createQuicksightUsersForUserTransfers() has invalid typehint type Generated\Shared\Transfer\UserCollectionResponseTransfer.
): UserCollectionResponseTransfer {

Check failure on line 31 in src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacade.php

View workflow job for this annotation

GitHub Actions / Validation

Return typehint of method SprykerEco\Zed\AmazonQuicksight\Business\AmazonQuicksightFacade::createQuicksightUsersForUserTransfers() has invalid type Generated\Shared\Transfer\UserCollectionResponseTransfer.

Check failure on line 31 in src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacade.php

View workflow job for this annotation

GitHub Actions / Validation

Return typehint of method SprykerEco\Zed\AmazonQuicksight\Business\AmazonQuicksightFacade::createQuicksightUsersForUserTransfers() has invalid type Generated\Shared\Transfer\UserCollectionResponseTransfer.
return $this->getFactory()
->createQuicksightUserCreator()
->createQuicksightUsersForUserTransfers($userCollectionResponseTransfer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@

namespace SprykerEco\Zed\AmazonQuicksight\Business;

use Generated\Shared\Transfer\UserCollectionResponseTransfer;

interface AmazonQuicksightFacadeInterface
{
/**
* Specification:
* - Expects `UserCollectionResponseTransfer.users.quicksightUser.role` to be set.
* - Sends request to AWS API to register Quicksight users. For more information see {@link https://docs.aws.amazon.com/quicksight/latest/APIReference/API_RegisterUser.html}.
* - Adds errors to `UserCollectionResponseTransfer.errors` if Quicksight user registration failed.
* - Persists successfully registered Quicksight users in the database.
* - Returns `UserCollectionResponseTransfer` with updated `UserTransfers`.
*
* @api
*
* @param \Generated\Shared\Transfer\UserCollectionResponseTransfer $userCollectionResponseTransfer
*
* @return \Generated\Shared\Transfer\UserCollectionResponseTransfer
*/
public function createQuicksightUsersForUserTransfers(
UserCollectionResponseTransfer $userCollectionResponseTransfer

Check failure on line 29 in src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacadeInterface.php

View workflow job for this annotation

GitHub Actions / Validation

Parameter $userCollectionResponseTransfer of method SprykerEco\Zed\AmazonQuicksight\Business\AmazonQuicksightFacadeInterface::createQuicksightUsersForUserTransfers() has invalid typehint type Generated\Shared\Transfer\UserCollectionResponseTransfer.

Check failure on line 29 in src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacadeInterface.php

View workflow job for this annotation

GitHub Actions / Validation

Parameter $userCollectionResponseTransfer of method SprykerEco\Zed\AmazonQuicksight\Business\AmazonQuicksightFacadeInterface::createQuicksightUsersForUserTransfers() has invalid typehint type Generated\Shared\Transfer\UserCollectionResponseTransfer.
): UserCollectionResponseTransfer;

Check failure on line 30 in src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacadeInterface.php

View workflow job for this annotation

GitHub Actions / Validation

Return typehint of method SprykerEco\Zed\AmazonQuicksight\Business\AmazonQuicksightFacadeInterface::createQuicksightUsersForUserTransfers() has invalid type Generated\Shared\Transfer\UserCollectionResponseTransfer.

Check failure on line 30 in src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacadeInterface.php

View workflow job for this annotation

GitHub Actions / Validation

Return typehint of method SprykerEco\Zed\AmazonQuicksight\Business\AmazonQuicksightFacadeInterface::createQuicksightUsersForUserTransfers() has invalid type Generated\Shared\Transfer\UserCollectionResponseTransfer.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

/**
* MIT License
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace SprykerEco\Zed\AmazonQuicksight\Business\ApiClient;

use Aws\QuickSight\Exception\QuickSightException;
use Generated\Shared\Transfer\ErrorTransfer;
use Generated\Shared\Transfer\QuicksightUserRegisterRequestTransfer;
use Generated\Shared\Transfer\QuicksightUserRegisterResponseTransfer;
use Generated\Shared\Transfer\UserTransfer;
use SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig;
use SprykerEco\Zed\AmazonQuicksight\Business\Formatter\AmazonQuicksightRequestDataFormatterInterface;
use SprykerEco\Zed\AmazonQuicksight\Business\Mapper\AmazonQuicksightMapperInterface;
use SprykerEco\Zed\AmazonQuicksight\Dependency\External\AmazonQuicksightToAwsQuicksightClientInterface;

class AmazonQuicksightApiClient implements AmazonQuicksightApiClientInterface
{
/**
* @var string
*/
protected const QUICKSIGHT_USER_IDENTITY_TYPE = 'QUICKSIGHT';

/**
* @link https://docs.aws.amazon.com/quicksight/latest/APIReference/API_RegisterUser.html#API_RegisterUser_ResponseSyntax
*
* @var string
*/
protected const RESPONSE_KEY_USER = 'User';

/**
* @var string
*/
protected const ERROR_MESSAGE_USER_REGISTRATION_FAILED = 'Failed to register Quicksight user.';

/**
* @var \SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig
*/
protected AmazonQuicksightConfig $amazonQuicksightConfig;

/**
* @var \SprykerEco\Zed\AmazonQuicksight\Business\Mapper\AmazonQuicksightMapperInterface
*/
protected AmazonQuicksightMapperInterface $amazonQuicksightMapper;

protected AmazonQuicksightRequestDataFormatterInterface $amazonQuicksightRequestDataFormatter;

/**
* @var \SprykerEco\Zed\AmazonQuicksight\Dependency\External\AmazonQuicksightToAwsQuicksightClientInterface
*/
protected AmazonQuicksightToAwsQuicksightClientInterface $amazonQuicksightToAwsQuicksightClient;

/**
* @param \SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig $amazonQuicksightConfig
* @param \SprykerEco\Zed\AmazonQuicksight\Business\Mapper\AmazonQuicksightMapperInterface $amazonQuicksightMapper
* @param \SprykerEco\Zed\AmazonQuicksight\Business\Formatter\AmazonQuicksightRequestDataFormatterInterface $amazonQuicksightRequestDataFormatter
* @param \SprykerEco\Zed\AmazonQuicksight\Dependency\External\AmazonQuicksightToAwsQuicksightClientInterface $amazonQuicksightToAwsQuicksightClient
*/
public function __construct(
AmazonQuicksightConfig $amazonQuicksightConfig,
AmazonQuicksightMapperInterface $amazonQuicksightMapper,
AmazonQuicksightRequestDataFormatterInterface $amazonQuicksightRequestDataFormatter,
AmazonQuicksightToAwsQuicksightClientInterface $amazonQuicksightToAwsQuicksightClient
) {
$this->amazonQuicksightConfig = $amazonQuicksightConfig;
$this->amazonQuicksightMapper = $amazonQuicksightMapper;
$this->amazonQuicksightRequestDataFormatter = $amazonQuicksightRequestDataFormatter;
$this->amazonQuicksightToAwsQuicksightClient = $amazonQuicksightToAwsQuicksightClient;
}

/**
* @param \Generated\Shared\Transfer\UserTransfer $userTransfer
*
* @return \Generated\Shared\Transfer\QuicksightUserRegisterResponseTransfer
*/
public function registerUser(UserTransfer $userTransfer): QuicksightUserRegisterResponseTransfer

Check failure on line 79 in src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/AmazonQuicksightApiClient.php

View workflow job for this annotation

GitHub Actions / Validation

Parameter $userTransfer of method SprykerEco\Zed\AmazonQuicksight\Business\ApiClient\AmazonQuicksightApiClient::registerUser() has invalid typehint type Generated\Shared\Transfer\UserTransfer.

Check failure on line 79 in src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/AmazonQuicksightApiClient.php

View workflow job for this annotation

GitHub Actions / Validation

Parameter $userTransfer of method SprykerEco\Zed\AmazonQuicksight\Business\ApiClient\AmazonQuicksightApiClient::registerUser() has invalid typehint type Generated\Shared\Transfer\UserTransfer.
{
$quicksightUserRegisterRequestTransfer = $this->createQuicksightUserRegisterRequestTransfer();
$quicksightUserRegisterRequestTransfer = $this->amazonQuicksightMapper->mapUserTransferToQuicksightUserRegisterRequestTransfer(
$userTransfer,
$quicksightUserRegisterRequestTransfer,
);

$requestData = $this->amazonQuicksightRequestDataFormatter->formatRequestData(
$quicksightUserRegisterRequestTransfer->toArray(true, true),
);

$quicksightUserRegisterResponseTransfer = new QuicksightUserRegisterResponseTransfer();
try {
$response = $this->amazonQuicksightToAwsQuicksightClient->registerUser($requestData);
} catch (QuickSightException $quickSightException) {
return $quicksightUserRegisterResponseTransfer->addError(
(new ErrorTransfer())->setMessage($quickSightException->getAwsErrorMessage()),
);
}

if (!$response->hasKey(static::RESPONSE_KEY_USER)) {
return $quicksightUserRegisterResponseTransfer->addError(
(new ErrorTransfer())->setMessage(static::ERROR_MESSAGE_USER_REGISTRATION_FAILED),
);
}

$quicksightUserTransfer = $this->amazonQuicksightMapper->mapQuicksightUserDataToQuicksightUserTransfer(
$response->get(static::RESPONSE_KEY_USER),
$userTransfer->getQuicksightUserOrFail(),
);

return $quicksightUserRegisterResponseTransfer->setQuicksightUser($quicksightUserTransfer);
}

/**
* @return \Generated\Shared\Transfer\QuicksightUserRegisterRequestTransfer
*/
protected function createQuicksightUserRegisterRequestTransfer(): QuicksightUserRegisterRequestTransfer
{
return (new QuicksightUserRegisterRequestTransfer())
->setIdentityType(static::QUICKSIGHT_USER_IDENTITY_TYPE)
->setAwsAccountId($this->amazonQuicksightConfig->getAwsAccountId())
->setNamespace($this->amazonQuicksightConfig->getQuicksightRegisterUserNamespace());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/**
* MIT License
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace SprykerEco\Zed\AmazonQuicksight\Business\ApiClient;

use Generated\Shared\Transfer\QuicksightUserRegisterResponseTransfer;
use Generated\Shared\Transfer\UserTransfer;

interface AmazonQuicksightApiClientInterface
{
/**
* @param \Generated\Shared\Transfer\UserTransfer $userTransfer
*
* @return \Generated\Shared\Transfer\QuicksightUserRegisterResponseTransfer
*/
public function registerUser(UserTransfer $userTransfer): QuicksightUserRegisterResponseTransfer;
}
Loading

0 comments on commit d6154a9

Please sign in to comment.