Skip to content

Commit a03e905

Browse files
committed
worked around aura free bug
1 parent 1dd35aa commit a03e905

File tree

5 files changed

+27
-30
lines changed

5 files changed

+27
-30
lines changed

src/Bolt/BoltConnectionPool.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function acquire(
9494

9595
public function canConnect(UriInterface $uri, AuthenticateInterface $authenticate): bool
9696
{
97-
$bolt = BoltFactory::fromVariables($uri, null, null, $authenticate, $this->driverConfig);
97+
$bolt = BoltFactory::fromVariables($uri, $authenticate, $this->driverConfig);
9898

9999
try {
100100
$bolt->build();
@@ -108,9 +108,12 @@ public function canConnect(UriInterface $uri, AuthenticateInterface $authenticat
108108
/**
109109
* @throws \ReflectionException
110110
*/
111-
private function getConnection(UriInterface $connectingTo, AuthenticateInterface $authenticate, SessionConfiguration $config): BoltConnection
112-
{
113-
$factory = BoltFactory::fromVariables($connectingTo, null, null, $authenticate, $this->driverConfig);
111+
private function getConnection(
112+
UriInterface $connectingTo,
113+
AuthenticateInterface $authenticate,
114+
SessionConfiguration $config
115+
): BoltConnection {
116+
$factory = BoltFactory::fromVariables($connectingTo, $authenticate, $this->driverConfig);
114117
[$bolt, $response] = $factory->build();
115118

116119
return new BoltConnection(

src/Bolt/SslConfigurator.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,16 @@
1111

1212
namespace Laudis\Neo4j\Bolt;
1313

14-
use function count;
1514
use function explode;
1615
use const FILTER_VALIDATE_IP;
1716
use function filter_var;
1817
use Laudis\Neo4j\Databags\DriverConfiguration;
1918
use Laudis\Neo4j\Enum\SslMode;
20-
use Laudis\Neo4j\Neo4j\RoutingTable;
2119
use Psr\Http\Message\UriInterface;
2220

2321
final class SslConfigurator
2422
{
25-
public function configure(UriInterface $uri, UriInterface $server, ?RoutingTable $table, DriverConfiguration $config): ?array
23+
public function configure(UriInterface $uri, DriverConfiguration $config): ?array
2624
{
2725
$sslMode = $config->getSslConfiguration()->getMode();
2826
$sslConfig = '';
@@ -37,14 +35,6 @@ public function configure(UriInterface $uri, UriInterface $server, ?RoutingTable
3735
}
3836

3937
if (str_starts_with($sslConfig, 's')) {
40-
// We have to pass a different host when working with ssl on aura.
41-
// There is a strange behaviour where if we pass the uri host on a single
42-
// instance aura deployment, we need to pass the original uri for the
43-
// ssl configuration to be valid.
44-
if ($table && count($table->getWithRole()) > 1) {
45-
return $this->enableSsl($server->getHost(), $sslConfig, $config);
46-
}
47-
4838
return $this->enableSsl($uri->getHost(), $sslConfig, $config);
4939
}
5040

src/BoltFactory.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use Laudis\Neo4j\Databags\DriverConfiguration;
2424
use Laudis\Neo4j\Databags\TransactionConfiguration;
2525
use Laudis\Neo4j\Exception\Neo4jException;
26-
use Laudis\Neo4j\Neo4j\RoutingTable;
2726
use Psr\Http\Message\UriInterface;
2827
use RuntimeException;
2928

@@ -87,22 +86,19 @@ public function getConnection(): IConnection
8786

8887
public static function fromVariables(
8988
UriInterface $uri,
90-
?UriInterface $server,
91-
?RoutingTable $table,
9289
AuthenticateInterface $authenticate,
9390
DriverConfiguration $config
9491
): self {
95-
$connectingTo = $server ?? $uri;
96-
$socket = new StreamSocket($uri->getHost(), $connectingTo->getPort() ?? 7687, TransactionConfiguration::DEFAULT_TIMEOUT);
92+
$socket = new StreamSocket($uri->getHost(), $uri->getPort() ?? 7687, TransactionConfiguration::DEFAULT_TIMEOUT);
9793

98-
self::configureSsl($uri, $connectingTo, $socket, $table, $config);
94+
self::configureSsl($uri, $socket, $config);
9995

10096
return new self(new Bolt($socket), $authenticate, $config->getUserAgent(), $socket);
10197
}
10298

103-
private static function configureSsl(UriInterface $uri, UriInterface $server, StreamSocket $socket, ?RoutingTable $table, DriverConfiguration $config): void
99+
private static function configureSsl(UriInterface $uri, StreamSocket $socket, DriverConfiguration $config): void
104100
{
105-
$options = (new SslConfigurator())->configure($uri, $server, $table, $config);
101+
$options = (new SslConfigurator())->configure($uri, $config);
106102

107103
if ($options !== null) {
108104
$socket->setSslContextOptions($options);

src/Neo4j/Neo4jConnectionPool.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace Laudis\Neo4j\Neo4j;
1515

1616
use function array_slice;
17+
use function array_unique;
1718
use Bolt\protocol\V3;
1819
use Bolt\protocol\V4;
1920
use Bolt\protocol\V4_3;
@@ -78,7 +79,7 @@ public function acquire(
7879
$connection->close();
7980
}
8081

81-
$server = $this->getNextServer($table, $config->getAccessMode());
82+
$server = $this->getNextServer($table, $config->getAccessMode()) ?? $uri;
8283

8384
$authenticate = Authenticate::fromUrl($uri);
8485

@@ -92,8 +93,13 @@ public function acquire(
9293
/**
9394
* @throws Exception
9495
*/
95-
private function getNextServer(RoutingTable $table, AccessMode $mode): Uri
96+
private function getNextServer(RoutingTable $table, AccessMode $mode): ?Uri
9697
{
98+
$servers = array_unique($table->getWithRole());
99+
if (count($servers) === 1) {
100+
return null;
101+
}
102+
97103
if (AccessMode::WRITE() === $mode) {
98104
$servers = $table->getWithRole(RoutingRoles::LEADER());
99105
} else {

tests/Unit/SslConfiguratorTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/*
46
* This file is part of the Laudis Neo4j package.
57
*
@@ -40,7 +42,7 @@ public function testDisablePeerVerification(): void
4042
);
4143

4244
$uri = Uri::create('');
43-
$array = $this->configurator->configure($uri, $uri, null, $config);
45+
$array = $this->configurator->configure($uri, $config);
4446

4547
self::assertNotNull($array);
4648
self::assertArrayHasKey('verify_peer', $array);
@@ -58,7 +60,7 @@ public function testEnablePeerVerification(): void
5860
);
5961

6062
$uri = Uri::create('');
61-
$array = $this->configurator->configure($uri, $uri, null, $config);
63+
$array = $this->configurator->configure($uri, $config);
6264

6365
self::assertNotNull($array);
6466
self::assertArrayHasKey('verify_peer', $array);
@@ -76,7 +78,7 @@ public function testSelfSigned(): void
7678
);
7779

7880
$uri = Uri::create('');
79-
$array = $this->configurator->configure($uri, $uri, null, $config);
81+
$array = $this->configurator->configure($uri, $config);
8082

8183
self::assertNotNull($array);
8284
self::assertArrayHasKey('allow_self_signed', $array);
@@ -93,7 +95,7 @@ public function testFromUriNull(): void
9395
);
9496

9597
$uri = Uri::create('neo4j://localhost');
96-
$array = $this->configurator->configure($uri, $uri, null, $config);
98+
$array = $this->configurator->configure($uri, $config);
9799

98100
self::assertNull($array);
99101
}
@@ -107,7 +109,7 @@ public function testFromUri(): void
107109
);
108110

109111
$uri = Uri::create('neo4j+s://localhost');
110-
$array = $this->configurator->configure($uri, $uri, null, $config);
112+
$array = $this->configurator->configure($uri, $config);
111113

112114
self::assertNotNull($array);
113115
self::assertArrayHasKey('verify_peer', $array);

0 commit comments

Comments
 (0)