Skip to content

Commit 4c723e6

Browse files
committed
IBX-10764: Remove dependencies to Platform.sh
1 parent 4b60242 commit 4c723e6

File tree

4 files changed

+5
-289
lines changed

4 files changed

+5
-289
lines changed

src/bundle/Core/DependencyInjection/IbexaCoreExtension.php

Lines changed: 0 additions & 184 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Ibexa\Bundle\Core\DependencyInjection\Configuration\Suggestion\Formatter\YamlSuggestionFormatter;
2020
use Ibexa\Bundle\Core\DependencyInjection\Security\PolicyProvider\PoliciesConfigBuilder;
2121
use Ibexa\Bundle\Core\DependencyInjection\Security\PolicyProvider\PolicyProviderInterface;
22-
use Ibexa\Bundle\Core\Session\Handler\NativeSessionHandler;
2322
use Ibexa\Bundle\Core\SiteAccess\SiteAccessConfigurationFilter;
2423
use Ibexa\Contracts\Core\MVC\EventSubscriber\ConfigScopeChangeSubscriber;
2524
use Ibexa\Contracts\Core\Repository\Values\Filter\CriterionQueryBuilder as FilteringCriterionQueryBuilder;
@@ -194,7 +193,6 @@ public function prepend(ContainerBuilder $container): void
194193
$this->handleDefaultSettingsLoading($container);
195194

196195
$this->configureGenericSetup($container);
197-
$this->configurePlatformShSetup($container);
198196
}
199197

200198
/**
@@ -803,188 +801,6 @@ private function configureGenericSetup(ContainerBuilder $container): void
803801
}
804802
}
805803

806-
/**
807-
* @throws \Exception
808-
*/
809-
private function configurePlatformShSetup(ContainerBuilder $container): void
810-
{
811-
$projectDir = $container->getParameter('kernel.project_dir');
812-
813-
// Will not be executed on build step
814-
$relationships = $_SERVER['PLATFORM_RELATIONSHIPS'] ?? false;
815-
if (!$relationships) {
816-
return;
817-
}
818-
$routes = $_SERVER['PLATFORM_ROUTES'];
819-
820-
$relationships = json_decode(base64_decode($relationships), true);
821-
$routes = json_decode(base64_decode($routes), true);
822-
823-
// PLATFORMSH_DFS_NFS_PATH is different compared to DFS_NFS_PATH in the sense that it is relative to ezplatform dir
824-
// DFS_NFS_PATH is an absolute path
825-
if ($dfsNfsPath = $_SERVER['PLATFORMSH_DFS_NFS_PATH'] ?? false) {
826-
$container->setParameter('dfs_nfs_path', sprintf('%s/%s', $projectDir, $dfsNfsPath));
827-
828-
// Map common parameters
829-
$container->setParameter('dfs_database_charset', $container->getParameter('database_charset'));
830-
$container->setParameter(
831-
'dfs_database_collation',
832-
$container->getParameter('database_collation')
833-
);
834-
if (\array_key_exists('dfs_database', $relationships)) {
835-
// process dedicated P.sh dedicated config
836-
foreach ($relationships['dfs_database'] as $endpoint) {
837-
if (empty($endpoint['query']['is_master'])) {
838-
continue;
839-
}
840-
$container->setParameter('dfs_database_driver', 'pdo_' . $endpoint['scheme']);
841-
$container->setParameter(
842-
'dfs_database_url',
843-
sprintf(
844-
'%s://%s:%s@%s:%d/%s',
845-
$endpoint['scheme'],
846-
$endpoint['username'],
847-
$endpoint['password'],
848-
$endpoint['host'],
849-
$endpoint['port'],
850-
$endpoint['path']
851-
)
852-
);
853-
}
854-
} else {
855-
// or set fallback from the Repository database, if not configured
856-
$container->setParameter('dfs_database_driver', $container->getParameter('database_driver'));
857-
}
858-
859-
$loader = new Loader\YamlFileLoader($container, new FileLocator($projectDir . '/config/packages/dfs'));
860-
$loader->load('dfs.yaml');
861-
}
862-
863-
// Use Redis-based caching if possible.
864-
if (isset($relationships['rediscache'])) {
865-
foreach ($relationships['rediscache'] as $endpoint) {
866-
if ($endpoint['scheme'] !== 'redis') {
867-
continue;
868-
}
869-
870-
$loader = new Loader\YamlFileLoader($container, new FileLocator($projectDir . '/config/packages/cache_pool'));
871-
$loader->load('cache.redis.yaml');
872-
873-
$container->setParameter('cache_pool', 'cache.redis');
874-
$container->setParameter('cache_dsn', sprintf('%s:%d', $endpoint['host'], $endpoint['port']) . '?retry_interval=3');
875-
}
876-
} elseif (isset($relationships['cache'])) {
877-
// Fallback to memcached if here (deprecated, we will only handle redis here in the future)
878-
foreach ($relationships['cache'] as $endpoint) {
879-
if ($endpoint['scheme'] !== 'memcached') {
880-
continue;
881-
}
882-
883-
@trigger_error('Usage of Memcached is deprecated, redis is recommended', E_USER_DEPRECATED);
884-
885-
$container->setParameter('cache_pool', 'cache.memcached');
886-
$container->setParameter('cache_dsn', sprintf('%s:%d', $endpoint['host'], $endpoint['port']));
887-
888-
$loader = new Loader\YamlFileLoader($container, new FileLocator($projectDir . '/config/packages/cache_pool'));
889-
$loader->load('cache.memcached.yaml');
890-
}
891-
}
892-
893-
// Use Redis-based sessions if possible. If a separate Redis instance
894-
// is available, use that. If not, share a Redis instance with the
895-
// Cache. (That should be safe to do except on especially high-traffic sites.)
896-
if (isset($relationships['redissession'])) {
897-
foreach ($relationships['redissession'] as $endpoint) {
898-
if ($endpoint['scheme'] !== 'redis') {
899-
continue;
900-
}
901-
902-
$container->setParameter('ibexa.session.handler_id', NativeSessionHandler::class);
903-
$container->setParameter('ibexa.session.save_path', sprintf('%s:%d', $endpoint['host'], $endpoint['port']));
904-
}
905-
} elseif (isset($relationships['rediscache'])) {
906-
foreach ($relationships['rediscache'] as $endpoint) {
907-
if ($endpoint['scheme'] !== 'redis') {
908-
continue;
909-
}
910-
911-
$container->setParameter('ibexa.session.handler_id', NativeSessionHandler::class);
912-
$container->setParameter('ibexa.session.save_path', sprintf('%s:%d', $endpoint['host'], $endpoint['port']));
913-
}
914-
}
915-
916-
if (isset($relationships['solr'])) {
917-
foreach ($relationships['solr'] as $endpoint) {
918-
if ($endpoint['scheme'] !== 'solr') {
919-
continue;
920-
}
921-
922-
$container->setParameter('search_engine', 'solr');
923-
924-
$container->setParameter('solr_dsn', sprintf('http://%s:%d/%s', $endpoint['host'], $endpoint['port'], 'solr'));
925-
// To set solr_core parameter we assume path is in form like: "solr/collection1"
926-
$container->setParameter('solr_core', substr($endpoint['path'], 5));
927-
}
928-
}
929-
930-
if (isset($relationships['elasticsearch'])) {
931-
foreach ($relationships['elasticsearch'] as $endpoint) {
932-
$dsn = sprintf('%s:%d', $endpoint['host'], $endpoint['port']);
933-
934-
if ($endpoint['username'] !== null && $endpoint['password'] !== null) {
935-
$dsn = $endpoint['username'] . ':' . $endpoint['password'] . '@' . $dsn;
936-
}
937-
938-
if ($endpoint['path'] !== null) {
939-
$dsn .= '/' . $endpoint['path'];
940-
}
941-
942-
$dsn = $endpoint['scheme'] . '://' . $dsn;
943-
944-
$container->setParameter('search_engine', 'elasticsearch');
945-
$container->setParameter('elasticsearch_dsn', $dsn);
946-
}
947-
}
948-
949-
// We will pick a varnish route by the following prioritization:
950-
// - The first route found that has upstream: varnish
951-
// - if primary route has upstream: varnish, that route will be prioritised
952-
// If no route is found with upstream: varnish, then purge_server will not be set
953-
$route = null;
954-
foreach ($routes as $host => $info) {
955-
if ($route === null && $info['type'] === 'upstream' && $info['upstream'] === 'varnish') {
956-
$route = $host;
957-
}
958-
if ($info['type'] === 'upstream' && $info['upstream'] === 'varnish' && $info['primary'] === true) {
959-
$route = $host;
960-
break;
961-
}
962-
}
963-
964-
if ($route !== null && !($_SERVER['SKIP_HTTPCACHE_PURGE'] ?? false)) {
965-
$purgeServer = rtrim($route, '/');
966-
if (($_SERVER['HTTPCACHE_USERNAME'] ?? false) && ($_SERVER['HTTPCACHE_PASSWORD'] ?? false)) {
967-
$domain = parse_url($purgeServer, PHP_URL_HOST);
968-
$credentials = urlencode($_SERVER['HTTPCACHE_USERNAME']) . ':' . urlencode($_SERVER['HTTPCACHE_PASSWORD']);
969-
$purgeServer = str_replace($domain, $credentials . '@' . $domain, $purgeServer);
970-
}
971-
972-
$container->setParameter('ibexa.http_cache.purge_type', 'varnish');
973-
$container->setParameter('purge_type', 'varnish');
974-
$container->setParameter('purge_server', $purgeServer);
975-
}
976-
// Setting default value for HTTPCACHE_VARNISH_INVALIDATE_TOKEN if it is not explicitly set
977-
if (!($_SERVER['HTTPCACHE_VARNISH_INVALIDATE_TOKEN'] ?? false)) {
978-
$container->setParameter('varnish_invalidate_token', $_SERVER['PLATFORM_PROJECT_ENTROPY']);
979-
}
980-
981-
// Adapt config based on enabled PHP extensions
982-
// Get imagine to use imagick if enabled, to avoid using php memory for image conversions
983-
if (\extension_loaded('imagick')) {
984-
$container->setParameter('liip_imagine_driver', 'imagick');
985-
}
986-
}
987-
988804
private function shouldLoadTestBehatServices(ContainerBuilder $container): bool
989805
{
990806
return $container->hasParameter('ibexa.behat.browser.enabled')

src/bundle/Core/EventSubscriber/TrustedHeaderClientIpEventSubscriber.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
final class TrustedHeaderClientIpEventSubscriber implements EventSubscriberInterface
1717
{
18-
private const PLATFORM_SH_TRUSTED_HEADER_CLIENT_IP = 'X-Client-IP';
19-
2018
private ?string $trustedHeaderName;
2119

2220
public function __construct(
@@ -40,9 +38,6 @@ public function onKernelRequest(RequestEvent $event): void
4038
$trustedHeaderSet = Request::getTrustedHeaderSet();
4139

4240
$trustedHeaderName = $this->trustedHeaderName;
43-
if (null === $trustedHeaderName && $this->isPlatformShProxy($request)) {
44-
$trustedHeaderName = self::PLATFORM_SH_TRUSTED_HEADER_CLIENT_IP;
45-
}
4641

4742
if (null === $trustedHeaderName) {
4843
return;
@@ -59,9 +54,4 @@ public function onKernelRequest(RequestEvent $event): void
5954

6055
Request::setTrustedProxies($trustedProxies, $trustedHeaderSet);
6156
}
62-
63-
private function isPlatformShProxy(Request $request): bool
64-
{
65-
return null !== $request->server->get('PLATFORM_RELATIONSHIPS');
66-
}
6757
}

tests/bundle/Core/DependencyInjection/IbexaCoreExtensionTest.php

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -911,51 +911,6 @@ public function testLoadsTestServicesWhenParameterIsSpecified(): void
911911
$this->assertContainerBuilderHasService(QueryControllerContext::class);
912912
}
913913

914-
/**
915-
* @throws \JsonException
916-
*/
917-
public function testConfigurePlatformShDFS(): void
918-
{
919-
$dsn = 'mysql://dfs:dfs@localhost:3306/dfs';
920-
$parts = parse_url($dsn);
921-
922-
$relationship = [
923-
'dfs_database' => [
924-
[
925-
'host' => $parts['host'],
926-
'scheme' => $parts['scheme'],
927-
'username' => $parts['user'],
928-
'password' => $parts['pass'],
929-
'port' => $parts['port'],
930-
'path' => ltrim($parts['path'], '/'),
931-
'query' => [
932-
'is_master' => true,
933-
],
934-
],
935-
],
936-
];
937-
938-
$_SERVER['PLATFORM_RELATIONSHIPS'] = base64_encode(json_encode($relationship, JSON_THROW_ON_ERROR));
939-
$_SERVER['PLATFORMSH_DFS_NFS_PATH'] = '/';
940-
$_SERVER['PLATFORM_ROUTES'] = base64_encode(json_encode([], JSON_THROW_ON_ERROR));
941-
$_SERVER['PLATFORM_PROJECT_ENTROPY'] = '';
942-
943-
$this->container->setParameter('database_charset', 'utf8mb4');
944-
$this->container->setParameter('database_collation', 'utf8mb4_general_ci');
945-
$this->container->setParameter('kernel.project_dir', __DIR__ . '/../Resources');
946-
$this->load();
947-
948-
$this->assertContainerBuilderHasParameter('dfs_database_url');
949-
self::assertEquals($dsn, $this->container->getParameter('dfs_database_url'));
950-
951-
unset(
952-
$_SERVER['PLATFORM_RELATIONSHIPS'],
953-
$_SERVER['PLATFORMSH_DFS_NFS_PATH'],
954-
$_SERVER['PLATFORM_ROUTES'],
955-
$_SERVER['PLATFORM_PROJECT_ENTROPY']
956-
);
957-
}
958-
959914
/**
960915
* Prepare Core Container for compilation by mocking required parameters and compile it.
961916
*/

tests/bundle/Core/EventSubscriber/TrustedHeaderClientIpEventSubscriberTest.php

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,11 @@
1919

2020
final class TrustedHeaderClientIpEventSubscriberTest extends TestCase
2121
{
22-
private const PLATFORM_SH_TRUSTED_HEADER_CLIENT_IP = 'X-Client-IP';
23-
2422
private ?string $originalRemoteAddr;
2523

26-
private const PROXY_IP = '127.100.100.1';
27-
28-
private const REAL_CLIENT_IP = '98.76.123.234';
24+
private const string PROXY_IP = '127.100.100.1';
2925

30-
private const CUSTOM_CLIENT_IP = '234.123.78.98';
26+
private const string REAL_CLIENT_IP = '98.76.123.234';
3127

3228
/**
3329
* @param array<mixed> $data
@@ -74,40 +70,6 @@ public function getTrustedHeaderEventSubscriberTestData(): array
7470
null,
7571
['X-Custom-Header' => self::REAL_CLIENT_IP],
7672
],
77-
'default platform.sh behaviour' => [
78-
self::REAL_CLIENT_IP,
79-
self::PROXY_IP,
80-
null,
81-
['X-Client-IP' => self::REAL_CLIENT_IP],
82-
['PLATFORM_RELATIONSHIPS' => true],
83-
],
84-
'use custom header name without valid value on platform.sh' => [
85-
self::PROXY_IP,
86-
self::PROXY_IP,
87-
'X-Custom-Header',
88-
[self::PLATFORM_SH_TRUSTED_HEADER_CLIENT_IP => self::REAL_CLIENT_IP],
89-
['PLATFORM_RELATIONSHIPS' => true],
90-
],
91-
'use custom header with valid value on platform.sh' => [
92-
self::CUSTOM_CLIENT_IP,
93-
self::PROXY_IP,
94-
'X-Custom-Header',
95-
[
96-
self::PLATFORM_SH_TRUSTED_HEADER_CLIENT_IP => self::REAL_CLIENT_IP,
97-
'X-Custom-Header' => self::CUSTOM_CLIENT_IP,
98-
],
99-
['PLATFORM_RELATIONSHIPS' => true],
100-
],
101-
'use valid value without custom header name on platform.sh' => [
102-
self::REAL_CLIENT_IP,
103-
self::PROXY_IP,
104-
null,
105-
[
106-
self::PLATFORM_SH_TRUSTED_HEADER_CLIENT_IP => self::REAL_CLIENT_IP,
107-
'X-Custom-Header' => self::CUSTOM_CLIENT_IP,
108-
],
109-
['PLATFORM_RELATIONSHIPS' => true],
110-
],
11173
];
11274
}
11375

@@ -120,10 +82,7 @@ public function testTrustedHeaderEventSubscriberWithoutTrustedProxy(): void
12082
new TrustedHeaderClientIpEventSubscriber('X-Custom-Header')
12183
);
12284

123-
$request = Request::create('/', Request::METHOD_GET, [], [], [], array_merge(
124-
$_SERVER,
125-
['PLATFORM_RELATIONSHIPS' => true],
126-
));
85+
$request = Request::create('/', Request::METHOD_GET, [], [], [], $_SERVER);
12786
$request->headers->add([
12887
'X-Custom-Header' => self::REAL_CLIENT_IP,
12988
]);
@@ -147,8 +106,7 @@ public function testTrustedHeaderEventSubscriberWithTrustedProxy(
147106
string $expectedIp,
148107
string $remoteAddrIp,
149108
?string $trustedHeaderName = null,
150-
array $headers = [],
151-
array $server = []
109+
array $headers = []
152110
): void {
153111
$_SERVER['REMOTE_ADDR'] = $remoteAddrIp;
154112
Request::setTrustedProxies(['REMOTE_ADDR'], Request::getTrustedHeaderSet());
@@ -158,10 +116,7 @@ public function testTrustedHeaderEventSubscriberWithTrustedProxy(
158116
new TrustedHeaderClientIpEventSubscriber($trustedHeaderName)
159117
);
160118

161-
$request = Request::create('/', Request::METHOD_GET, [], [], [], array_merge(
162-
$server,
163-
['REMOTE_ADDR' => $remoteAddrIp],
164-
));
119+
$request = Request::create('/', Request::METHOD_GET, [], [], [], ['REMOTE_ADDR' => $remoteAddrIp]);
165120
$request->headers->add($headers);
166121

167122
$event = $eventDispatcher->dispatch(new RequestEvent(

0 commit comments

Comments
 (0)