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

Remove deprecated symbols #142

Merged
merged 2 commits into from
Feb 13, 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this

### Removed
* Remove `BackwardsCompatibleMonologProcessorDelegator`.
* Remove support for redis URIs with just a password in place of the username (like `tcp://[email protected]`).
* Remove support for non-URL-encoded credentials in redis URIs.
* Remove `json_decode` and `json_encode` functions.

### Fixed
* *Nothing*
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,15 @@ return [

'redis' => [
'servers' => [
// These should be valid URIs. Make sure credentials are URL-encoded
'tcp://1.1.1.1:6379',
'tcp://2.2.2.2:6379',
'tcp://3.3.3.3:6379',
'tcp://user:password@4.4.4.4:6379', // Redis ACL (https://redis.io/docs/management/security/acl/)
'tcp://user:pass%40word@4.4.4.4:6379', // Redis ACL (https://redis.io/docs/management/security/acl/)
'tcp://:[email protected]:6379', // Redis security (https://redis.io/docs/management/security/)
'tcp://[email protected]:6379', // Same as above, but it's deprecated, as it's not a standard URI
'tls://server_with_encryption:6379',
],
'sentinel_service' => 'the_service', // Optional.
'decode_credentials' => true // Optional. Defaults to false
],
],

Expand All @@ -72,7 +71,6 @@ You can allow caching to be done on a redis instance, redis cluster or redis sen

* `servers`: A list of redis servers. If one is provided, it will be treated as a single instance, and otherwise, a cluster will be assumed.
* `sentinel_service`: Lets you enable sentinel mode. When provided, the servers will be treated as sentinel instances.
* `decode_credentials`: Indicates if server credentials (if present) should be URL decoded before passing to redis connection. Otherwise, they are passed verbatim.

> **Note**
> The entries in `servers` support credentials in the form of `tcp://password@my-server:6379` or `tcp://username:password@my-server:6379`.
Expand Down
15 changes: 0 additions & 15 deletions functions/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,10 @@
namespace Shlinkio\Shlink\Common;

use Cake\Chronos\Chronos;
use JsonSerializable;
use Shlinkio\Shlink\Common\Util\DateRange;

use function array_pad;
use function explode;
use function Shlinkio\Shlink\Json\json_decode as shlink_json_decode;
use function Shlinkio\Shlink\Json\json_encode as shlink_json_encode;

/** @deprecated Use the same function from shlinkio/shlink-json */
function json_decode(string $json): array
{
return shlink_json_decode($json);
}

/** @deprecated Use the same function from shlinkio/shlink-json */
function json_encode(array|JsonSerializable $payload): string
{
return shlink_json_encode($payload);
}

function buildDateRange(?Chronos $startDate, ?Chronos $endDate): DateRange
{
Expand Down
31 changes: 11 additions & 20 deletions src/Cache/RedisFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,17 @@
private function resolveServers(array $redisConfig): array
{
$servers = $redisConfig['servers'] ?? [];
$decodeCredentials = $redisConfig['decode_credentials'] ?? false;

$servers = array_map(
fn (string $server) => $this->normalizeServer($server, $decodeCredentials),
fn (string $server) => $this->normalizeServer($server),
is_string($servers) ? explode(',', $servers) : $servers,
);

// If there's only one server, we return it as is. If an array is provided, predis expects cluster config
return count($servers) === 1 ? $servers[0] : $servers;
}

private function normalizeServer(string $server, bool $decodeCredentials): array
private function normalizeServer(string $server): array
{
$parsedServer = parse_url(trim($server));
if (! is_array($parsedServer)) {
Expand All @@ -62,25 +61,17 @@
$parsedServer['ssl'] = SSL::OPTIONS;
}

if (! isset($parsedServer['user']) && ! isset($parsedServer['pass'])) {
return $parsedServer;
}
// Set credentials if set
$user = $parsedServer['user'] ?? null;
$pass = $parsedServer['pass'] ?? null;
unset($parsedServer['user'], $parsedServer['pass']);

// Deprecated. Apply URL decoding only if explicitly requested, for BC. Next major version will always do it
$credentialsCallback = static fn (string $val) => ($decodeCredentials ? urldecode($val) : $val);

if (isset($parsedServer['user']) && ! isset($parsedServer['pass'])) {
// For historical reasons, we support URLs in the form of `tcp://redis_password@redis_host:1234`, but this
// is deprecated
$parsedServer['password'] = $credentialsCallback($parsedServer['user']);
} elseif (isset($parsedServer['user'], $parsedServer['pass'])) {
if ($parsedServer['user'] !== '') {
$parsedServer['username'] = $credentialsCallback($parsedServer['user']);
}
$parsedServer['password'] = $credentialsCallback($parsedServer['pass']);
if ($user !== null && $user !== '') {
$parsedServer['username'] = urldecode($user);
}
if ($pass !== null) {
$parsedServer['password'] = urldecode($pass);
}

unset($parsedServer['user'], $parsedServer['pass']);

return $parsedServer;
}
Expand All @@ -95,6 +86,6 @@
];
}

return ! isset($servers[0]) ? null : ['cluster' => 'redis'];

Check warning on line 89 in src/Cache/RedisFactory.php

View workflow job for this annotation

GitHub Actions / ci / mutation-tests (8.2)

Escaped Mutant for Mutator "IncrementInteger": --- Original +++ New @@ @@ if ($sentinelService !== null) { return ['replication' => 'sentinel', 'service' => $sentinelService]; } - return !isset($servers[0]) ? null : ['cluster' => 'redis']; + return !isset($servers[1]) ? null : ['cluster' => 'redis']; } }

Check warning on line 89 in src/Cache/RedisFactory.php

View workflow job for this annotation

GitHub Actions / ci / mutation-tests (8.3)

Escaped Mutant for Mutator "IncrementInteger": --- Original +++ New @@ @@ if ($sentinelService !== null) { return ['replication' => 'sentinel', 'service' => $sentinelService]; } - return !isset($servers[0]) ? null : ['cluster' => 'redis']; + return !isset($servers[1]) ? null : ['cluster' => 'redis']; } }
}
}
2 changes: 1 addition & 1 deletion src/RabbitMq/AMQPConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __invoke(ContainerInterface $container): AMQPStreamConnection
// We have to pass the config as the ssl_protocol to avoid an internal deprecation warning
// When the ssl_protocol is a config instance, it is internally set as config.
// See https://github.com/php-amqplib/php-amqplib/blob/b4ade54ebe4685873f6316f9a05fc2c77a9e28f9/PhpAmqpLib/Connection/AMQPStreamConnection.php#L48-L55
ssl_protocol: $connectionConfig, // @phpstan-ignore-line
ssl_protocol: $connectionConfig,
);
}

Expand Down
12 changes: 2 additions & 10 deletions test/Cache/RedisFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,11 @@ public static function provideServersWithCredentials(): iterable
yield 'password only' => [[
'servers' => ['tcp://:[email protected]:6379'],
], null, 'baz', null];
yield 'password only (deprecated)' => [[
yield 'username only' => [[
'servers' => ['tcp://[email protected]:6379'],
], null, 'foo', null];
], 'foo', null, null];
yield 'URL-encoded' => [[
'servers' => ['tcp://user%3Aname:pass%[email protected]:6379'],
], 'user%3Aname', 'pass%40word', null];
yield 'URL-encoded, no request decode' => [[
'servers' => ['tcp://user%3Aname:pass%[email protected]:6379'],
'decode_credentials' => false,
], 'user%3Aname', 'pass%40word', null];
yield 'URL-encoded, request decode' => [[
'servers' => ['tcp://user%3Aname:pass%[email protected]:6379'],
'decode_credentials' => true,
], 'user:name', 'pass@word', null];
yield 'tls encryption' => [[
'servers' => ['tls://1.1.1.1:6379'],
Expand Down
Loading