Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verification #384

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bin/update-required-packages.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
$composerFile = $package['directory'] . DIRECTORY_SEPARATOR . 'composer.json';
$composer = json_decode(file_get_contents($composerFile), true);
$composer['extra']['branch-alias']['dev-main'] = $version . '-dev';
$releaseTime = (new \DateTimeImmutable('now', new DateTimeZone('UTC')))->modify("+15 min");
$composer['extra']['release-time'] = $releaseTime->format('Y-m-d H:i:s');

foreach ($composer['require'] as $requiredPackage => $requiredVersion) {
if (in_array($requiredPackage, $packageNames)) {
Expand Down
3 changes: 2 additions & 1 deletion packages/Ecotone/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
"name": "Enterprise License",
"description": "Allows to use Enterprise features of Ecotone. For more information please write to support@simplycodedsoftware.com"
}
}
},
"release-time": "2024-10-08 14:31:00"
},
"config": {
"sort-packages": true,
Expand Down
51 changes: 34 additions & 17 deletions packages/Ecotone/src/Lite/EcotoneLite.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,20 @@ public static function bootstrap(
array $configurationVariables = [],
bool $useCachedVersion = false,
?string $pathToRootCatalog = null,
bool $allowGatewaysToBeRegisteredInContainer = false
bool $allowGatewaysToBeRegisteredInContainer = false,
?string $enterpriseLicenceKey = null,
): ConfiguredMessagingSystem {
return self::prepareConfiguration($containerOrAvailableServices, $configuration, $classesToResolve, $configurationVariables, $pathToRootCatalog, false, $allowGatewaysToBeRegisteredInContainer, $useCachedVersion);
return self::prepareConfiguration(
$containerOrAvailableServices,
$configuration,
$classesToResolve,
$configurationVariables,
$pathToRootCatalog,
false,
$allowGatewaysToBeRegisteredInContainer,
$useCachedVersion,
$enterpriseLicenceKey,
);
}

/**
Expand Down Expand Up @@ -96,7 +107,7 @@ public static function bootstrapForTesting(
* @param array<string,string> $configurationVariables
* @param ContainerInterface|object[] $containerOrAvailableServices
* @param MessageChannelBuilder[] $enableAsynchronousProcessing
* @param bool $withEnterpriseLicence bool Forces to use Enterprise mode or not (must be used instead of ServiceConfiguration option)
* @param bool $enterpriseLicenceKey bool Make use of Enterprise Modules for testing purposes
*/
public static function bootstrapFlowTesting(
array $classesToResolve = [],
Expand All @@ -109,9 +120,9 @@ public static function bootstrapFlowTesting(
bool $addInMemoryEventSourcedRepository = true,
?array $enableAsynchronousProcessing = null,
TestConfiguration $testConfiguration = null,
bool $withEnterpriseLicence = false
?string $enterpriseLicenceKey = null
): FlowTestSupport {
$configuration = self::prepareForFlowTesting($configuration, ModulePackageList::allPackages(), $classesToResolve, $addInMemoryStateStoredRepository, $enableAsynchronousProcessing, $testConfiguration, $withEnterpriseLicence);
$configuration = self::prepareForFlowTesting($configuration, ModulePackageList::allPackages(), $classesToResolve, $addInMemoryStateStoredRepository, $enableAsynchronousProcessing, $testConfiguration, $enterpriseLicenceKey);

if ($addInMemoryEventSourcedRepository) {
$configuration = $configuration->addExtensionObject(InMemoryRepositoryBuilder::createDefaultEventSourcedRepository());
Expand Down Expand Up @@ -140,9 +151,9 @@ public static function bootstrapFlowTestingWithEventStore(
bool $runForProductionEventStore = false,
?array $enableAsynchronousProcessing = null,
TestConfiguration $testConfiguration = null,
bool $withEnterpriseLicence = false,
?string $enterpriseLicenceKey = null,
): FlowTestSupport {
$configuration = self::prepareForFlowTesting($configuration, ModulePackageList::allPackagesExcept([ModulePackageList::EVENT_SOURCING_PACKAGE, ModulePackageList::DBAL_PACKAGE, ModulePackageList::JMS_CONVERTER_PACKAGE]), $classesToResolve, $addInMemoryStateStoredRepository, $enableAsynchronousProcessing, $testConfiguration, $withEnterpriseLicence);
$configuration = self::prepareForFlowTesting($configuration, ModulePackageList::allPackagesExcept([ModulePackageList::EVENT_SOURCING_PACKAGE, ModulePackageList::DBAL_PACKAGE, ModulePackageList::JMS_CONVERTER_PACKAGE]), $classesToResolve, $addInMemoryStateStoredRepository, $enableAsynchronousProcessing, $testConfiguration, $enterpriseLicenceKey);

if (! $configuration->hasExtensionObject(BaseEventSourcingConfiguration::class) && ! $runForProductionEventStore) {
Assert::isTrue(class_exists(EventSourcingConfiguration::class), 'To use Flow Testing with Event Store you need to add event sourcing module.');
Expand Down Expand Up @@ -201,7 +212,7 @@ private static function getFileNameBasedOnConfig(
* @param string[] $classesToResolve
* @param array<string,string> $configurationVariables
*/
private static function prepareConfiguration(ContainerInterface|array $containerOrAvailableServices, ?ServiceConfiguration $serviceConfiguration, array $classesToResolve, array $configurationVariables, ?string $originalPathToRootCatalog, bool $enableTesting, bool $allowGatewaysToBeRegisteredInContainer, bool $useCachedVersion): ConfiguredMessagingSystemWithTestSupport|ConfiguredMessagingSystem
private static function prepareConfiguration(ContainerInterface|array $containerOrAvailableServices, ?ServiceConfiguration $serviceConfiguration, array $classesToResolve, array $configurationVariables, ?string $originalPathToRootCatalog, bool $enableTesting, bool $allowGatewaysToBeRegisteredInContainer, bool $useCachedVersion, ?string $enterpriseLicenceKey = null): ConfiguredMessagingSystemWithTestSupport|ConfiguredMessagingSystem
{
// moving out of vendor catalog
$pathToRootCatalog = $originalPathToRootCatalog ?: __DIR__ . '/../../../../';
Expand All @@ -216,12 +227,14 @@ private static function prepareConfiguration(ContainerInterface|array $container
);
}



if (is_null($serviceConfiguration)) {
$serviceConfiguration = ServiceConfiguration::createWithDefaults();
}

if ($enterpriseLicenceKey !== null) {
$serviceConfiguration = $serviceConfiguration->withLicenceKey($enterpriseLicenceKey);
}

$externalContainer = $containerOrAvailableServices instanceof ContainerInterface ? $containerOrAvailableServices : InMemoryPSRContainer::createFromAssociativeArray($containerOrAvailableServices);

$serviceCacheConfiguration = new ServiceCacheConfiguration(
Expand Down Expand Up @@ -297,12 +310,12 @@ private static function getExtensionObjectsWithoutTestConfiguration(ServiceConfi

private static function prepareForFlowTesting(
?ServiceConfiguration $configuration,
array $packagesToSkip,
array $classesToResolve,
array $packagesToSkip,
array $classesToResolve,
bool $addInMemoryStateStoredRepository,
?array $enableAsynchronousProcessing,
?TestConfiguration $testConfiguration,
bool $withEnterpriseLicence,
?array $enableAsynchronousProcessing,
?TestConfiguration $testConfiguration,
?string $enterpriseLicenceKey,
): ServiceConfiguration {
if ($enableAsynchronousProcessing !== null) {
if ($configuration !== null && in_array(ModulePackageList::ASYNCHRONOUS_PACKAGE, $configuration->getSkippedModulesPackages())) {
Expand Down Expand Up @@ -349,8 +362,12 @@ private static function prepareForFlowTesting(
->addExtensionObject(InMemoryRepositoryBuilder::createDefaultStateStoredRepository());
}

return $configuration
->withEnterpriseLicence($withEnterpriseLicence);
if ($enterpriseLicenceKey !== null) {
$configuration = $configuration
->withLicenceKey($enterpriseLicenceKey);
}

return $configuration;
}

private static function shouldUseAutomaticCache(bool $useCachedVersion, string $pathToRootCatalog): bool
Expand Down
58 changes: 58 additions & 0 deletions packages/Ecotone/src/Messaging/Config/Licence/LicenceService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

namespace Ecotone\Messaging\Config\Licence;

use Ecotone\Messaging\Support\LicensingException;

/**
* licence Enterprise
*/
final class LicenceService
{
public function validate(string $licenceKey): void
{
if (!extension_loaded('openssl')) {
throw LicensingException::create('OpenSSL extension is required for licencing. Please install `ext-openssl` before using.');
}

$publicKey = openssl_pkey_get_public(file_get_contents(__DIR__ . '/key.pem'));
$licence = \json_decode(base64_decode($licenceKey), true, JSON_THROW_ON_ERROR);

if (!isset($licence['signature']) || !isset($licence['data'])) {
throw LicensingException::create('Invalid licence key provided. Please contact us at: "support@simplycodedsoftware.com"');
}

$result = openssl_verify(
data: \json_encode($licence['data'], JSON_THROW_ON_ERROR),
signature: base64_decode($licence['signature']),
public_key: $publicKey,
algorithm: OPENSSL_ALGO_SHA256
);

if ($result !== 1) {
throw LicensingException::create('Invalid licence key provided. Please contact us at: "support@simplycodedsoftware.com"');
};

/** @var array{email: string, expireAt: string, isEnterprisePlus: bool} $data */
$data = $licence['data'];
$licenceExpirationTime = new \DateTimeImmutable($data['expireAt'], new \DateTimeZone('UTC'));

if ($data['isEnterprisePlus']) {
$mainComposer = json_decode(file_get_contents(__DIR__.'/../../../../composer.json'), true, JSON_THROW_ON_ERROR);
$versionReleaseAt = new \DateTimeImmutable(trim($mainComposer['extra']['release-time']), new \DateTimeZone('UTC'));

if ($licenceExpirationTime < $versionReleaseAt) {
throw LicensingException::create(sprintf('Licence has expired at %s UTC. Please renew the licence or contact us at: "support@simplycodedsoftware.com"', $licenceExpirationTime->format('Y-m-d H:i:s')));
}

return;
}

$currentTime = new \DateTimeImmutable('now', new \DateTimeZone('UTC'));
if ($licenceExpirationTime < $currentTime) {
throw LicensingException::create(sprintf('Licence has expired at %s UTC. Please renew the licence or contact us at: "support@simplycodedsoftware.com"', $licenceExpirationTime->format('Y-m-d H:i:s')));
}
}
}
14 changes: 14 additions & 0 deletions packages/Ecotone/src/Messaging/Config/Licence/key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAxcGDppMxkeBMHV9KhjWS
zJ6bMG1DeIy/qXmT443PSNS1S1maLcgnfGdT69koej1sskBcL/Or3WqVAj/3RrKG
gLiVL1aa95QW2JDy7YsKptbd1NfDxuR4lvAPH4iK69jqp6UPZOWJCJECRyy4F+gm
1vmW+iWSuyhXAhBPfQHHbUoPsInedB5M47kkW4pu43P9QHcz6TxYiB4mQiSRwY1s
rxqopY48K5kKRnOBQd1wRLV14Z938rHJiksh6678LwtT0eMlyRKt++Lh1I21iL8/
BYeJLxDq9Ysu/tXCP+O412ns5qWVcuxa8QX9Frgs871InXDHb7pwJqVlOoIvsMe+
5X6mNmgrAy6gtsLwSrm0+A1HQuRQ+nsc2pj0g9uIkFsIukoTMFU5en+bXjcBYg76
ZbraiOAy2lEj66ZxhZDJchpFYlgvrs3zKrGI/GrDBKmdZL4AGC6IODAtS6DLDCzx
O67U2/pba1IymJbYW1gRuhZKtl6tAKo0DJVmPt+X3TUKwAR0Z2kRXwGsiM8TPAER
SoU7czLfuX1q9g/FjKUTghUSW8awDhhy2TI7AruY+0izOx76bC4dL2xUYxfPd2YD
f1Srd7s+8RXlJtUtFqvkHAj0tARuU1lM1r5V5ecM4hObbSPDiulBqXdNA+SEFs1l
GcJLariOAtOQY+f2HsB9Q1ECAwEAAQ==
-----END PUBLIC KEY-----
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Ecotone\Messaging\Config;

use function array_map;

use Ecotone\AnnotationFinder\AnnotationFinder;
use Ecotone\AnnotationFinder\AnnotationFinderFactory;
use Ecotone\Lite\Test\TestConfiguration;
Expand All @@ -32,6 +30,8 @@
use Ecotone\Messaging\Config\Container\InterfaceToCallReference;
use Ecotone\Messaging\Config\Container\MessagingContainerBuilder;
use Ecotone\Messaging\Config\Container\Reference;
use Ecotone\Messaging\Config\Licence\LicenceService;
use Ecotone\Messaging\Config\Licence\LicenceValidator;
use Ecotone\Messaging\ConfigurationVariableService;
use Ecotone\Messaging\Conversion\AutoCollectionConversionService;
use Ecotone\Messaging\Conversion\ConversionService;
Expand Down Expand Up @@ -60,13 +60,13 @@
use Ecotone\Messaging\NullableMessageChannel;
use Ecotone\Messaging\PollableChannel;
use Ecotone\Messaging\Support\Assert;
use Ecotone\Messaging\Support\LicensingException;
use Ecotone\Modelling\Config\BusModule;
use Exception;

use function is_a;

use Psr\Container\ContainerInterface;
use Ramsey\Uuid\Uuid;
use function array_map;
use function is_a;

/**
* Class Configuration
Expand Down Expand Up @@ -156,7 +156,7 @@ final class MessagingSystemConfiguration implements Configuration

private InterfaceToCallRegistry $interfaceToCallRegistry;

private bool $isRunningForEnterpriseLicence;
private bool $isRunningForEnterpriseLicence = false;
/**
* @var CompilerPass[] $compilerPasses
*/
Expand Down Expand Up @@ -209,7 +209,12 @@ function ($extensionObject) {
$this->isRunningForTest = ExtensionObjectResolver::contains(TestConfiguration::class, $extensionObjects);

$extensionObjects[] = $serviceConfiguration;
$this->isRunningForEnterpriseLicence = $serviceConfiguration->hasEnterpriseLicence();

if ($serviceConfiguration->getLicenceKey() !== null) {
(new LicenceService())->validate($serviceConfiguration->getLicenceKey());
$this->isRunningForEnterpriseLicence = true;
}

$this->initialize($moduleConfigurationRetrievingService, $extensionObjects, $serviceConfiguration);
}

Expand Down
10 changes: 5 additions & 5 deletions packages/Ecotone/src/Messaging/Config/ServiceConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ServiceConfiguration
*/
private array $pollableEndpointAnnotations = [];

private bool $hasEnterpriseLicence = false;
private ?string $licenceKey = null;

private function __construct()
{
Expand Down Expand Up @@ -224,16 +224,16 @@ public function withConnectionRetryTemplate(RetryTemplateBuilder $channelPollRet
return $this;
}

public function withEnterpriseLicence(bool $enabled): self
public function withLicenceKey(string $licenceKey): self
{
$this->hasEnterpriseLicence = $enabled;
$this->licenceKey = $licenceKey;

return $this;
}

public function hasEnterpriseLicence(): bool
public function getLicenceKey(): ?string
{
return $this->hasEnterpriseLicence;
return $this->licenceKey;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Ecotone\Messaging\MessagingException;

/**
* licence Apache-2.0
* licence Enterprise
*/
final class LicensingException extends MessagingException
{
Expand Down
7 changes: 6 additions & 1 deletion packages/Ecotone/src/Test/ComponentTestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public static function create(
FileSystemAnnotationFinder::getRealRootCatalog($pathToRootCatalog, $pathToRootCatalog);

$configurationVariableService = InMemoryConfigurationVariableService::create($configurationVariables);
$serviceConfiguration = $configuration ?? ServiceConfiguration::createWithDefaults()->withSkippedModulePackageNames(ModulePackageList::allPackages());
if ($defaultEnterpriseMode) {
$serviceConfiguration = $serviceConfiguration->withLicenceKey(LicenceTesting::VALID_LICENCE);
}

return new self(
InMemoryPSRContainer::createFromAssociativeArray([
ServiceCacheConfiguration::REFERENCE_NAME => ServiceCacheConfiguration::noCache(),
Expand All @@ -65,7 +70,7 @@ public static function create(
MessagingSystemConfiguration::prepare(
$pathToRootCatalog,
$configurationVariableService,
$configuration ?? ServiceConfiguration::createWithDefaults()->withSkippedModulePackageNames(ModulePackageList::allPackages())->withEnterpriseLicence($defaultEnterpriseMode),
$serviceConfiguration,
$classesToResolve,
true,
)
Expand Down
13 changes: 13 additions & 0 deletions packages/Ecotone/src/Test/LicenceTesting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Ecotone\Test;

/**
* licence Enterprise
*/
final class LicenceTesting
{
public const VALID_LICENCE = 'eyJzaWduYXR1cmUiOiJxRmtrSDdCQkxzdUlTRzExZmVXeHVKVTY3bGZScmFSTFBpb0VUaGdoZTAyYWRjajlVRkNWWXhvaGl4YXhoaEFlNzU5aExOT0R5NXo1T2N2eFppUGQyemRRblYrb1dNZjFwM2lqbFN4cUg1MDhVV1wvOG90TllkM28wMVRZRmdMSjU4RXJzYThLcUJib0Z1MmhaZW9lczQ3elM2VHR5TzFGV2pOeWxlbG1aRWNLUHFydFhzOTNcL1YxY0wwWVg4UFBOZDl6bVRPOWxyc3UzM3F1anBXVlB4eVRMTW4yK3lPc3Jxa2pJZDArSU1LSWl0dG1IZGlBcml6NnZIXC93RnFKTU5Od2JKWnFsUXRNa3pQc3pvRlFseVgyZnNPTG5CTWNCajA5S0VnNjhVcG14OVwvUnBHZXBNV2UzcThYeFZMa3laOEtXdndEN2JBZDZPSXVoejlxRThyamVQVVVsbUxybm0wd3ZFYjV6UVZEbU5OY21uZnNkMEYyazJhSldySzc5VXlEWVY3UFNvVkZiM0diV0VNN2p1STVFV2w5cTVaWXJiOGxFcmxTTmNpYmQwbCttMWkzUWk1TnZhU1RscHBTV1BGS0g4c2x5dDhKRzV4YXZqQlJFU3BJWGVDNE9VREdoZDRJNEhaaEpDXC9Wcm9Nb0FRNzBMaXRrUHcxWkdWQ1dqTURucHdNdWRyWThpMVQwak5MRytXYlpYckpvRHZxd0x4SENKdU9EWnhuYVNISkVVSVFndGViUXZPRURIKzBjN0o0VVJMWkV2NnU2d2tcL1F6TzlPVnVVS1BubDkzK1dVam8xVDZqOEJ0MEtSeHhsMmtBY2pQcE9wWTg5Q25BQlBtckF4THJhYkxXeThpZmxVQ0cwUjNmZzB4UnpiMjlMSENvUW95b2NmRStzYjhFYz0iLCJkYXRhIjp7ImVtYWlsIjoiam9obnlAd3AucGwiLCJleHBpcmVBdCI6IjIwMzItMTAtMTEgMDA6MDA6MDAiLCJpc0VudGVycHJpc2VQbHVzIjpmYWxzZX19';
}
3 changes: 3 additions & 0 deletions packages/Ecotone/tests/Lite/EcotoneLiteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
use Ecotone\Messaging\Channel\SimpleMessageChannelBuilder;
use Ecotone\Messaging\Config\ModulePackageList;
use Ecotone\Messaging\Config\ServiceConfiguration;
use Ecotone\Messaging\Support\LicensingException;
use PHPUnit\Framework\TestCase;
use Test\Ecotone\Modelling\Fixture\EventRevision\Person;
use Test\Ecotone\Modelling\Fixture\EventRevision\RegisterPerson;
use Test\Ecotone\Modelling\Fixture\Order\ChannelConfiguration;
use Test\Ecotone\Modelling\Fixture\Order\OrderService;

Expand Down
Loading
Loading