Skip to content

Commit 2da101e

Browse files
committed
IBX-10764: Remove dependencies to Platform.sh
1 parent 4d75abc commit 2da101e

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;
@@ -193,7 +192,6 @@ public function prepend(ContainerBuilder $container): void
193192
$this->handleDefaultSettingsLoading($container);
194193

195194
$this->configureGenericSetup($container);
196-
$this->configurePlatformShSetup($container);
197195
}
198196

199197
/**
@@ -802,188 +800,6 @@ private function configureGenericSetup(ContainerBuilder $container): void
802800
}
803801
}
804802

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