From 8a0afc31b199c0fc7e25d5d7f4542bba954d34f7 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sun, 6 Mar 2022 01:21:19 +0000 Subject: [PATCH] EtcdConfig: Remove YAML from available 'encoding' options This appears impossible to use because the request is always made with `Content-Type: application/json`. * It seems unreasonable for an Etcd server to not support JSON. * It seems unreasonable for an Etcd server to respond with YAML to a JSON request. * It seems unlikely that anyone would prefer YAML over JSON for the automated encoding and decoding of fully automated inter-service communication. Change-Id: I290e03e17d547c3dc675820bb024c940e02e097a --- RELEASE-NOTES-1.38 | 2 ++ composer.json | 1 - includes/config/EtcdConfig.php | 15 ++++----------- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/RELEASE-NOTES-1.38 b/RELEASE-NOTES-1.38 index 83c29ee6949..5ac33075557 100644 --- a/RELEASE-NOTES-1.38 +++ b/RELEASE-NOTES-1.38 @@ -266,6 +266,8 @@ because of Phabricator reports. User::removeWatch() * ParserOptions::setTidy() that had no effect and was deprecated since 1.35 has been removed. +* The "YAML" encoding option of EtcdConfig, has been removed without + deprecation. * The constant ApiBase::PARAM_VALUE_LINKS, deprecated since 1.35 has been removed. * UserLoadOptions, UserSaveOptions and UserResetAllOptions hooks, deprecated diff --git a/composer.json b/composer.json index fbc1f4e7037..c2cda6ddd63 100644 --- a/composer.json +++ b/composer.json @@ -116,7 +116,6 @@ "ext-readline": "Enable CLI history and autocomplete, e.g. for eval.php and other REPLs.", "ext-sockets": "Enable CLI concurrent processing, e.g. for rebuildLocalisationCache.php.", "ext-wikidiff2": "Faster text difference engine.", - "ext-yaml": "Enable YAML type for EtcdConfig backend.", "ext-zlib": "Enable use of GZIP compression, e.g. for SqlBagOStuff (ParserCache), $wgCompressRevisions, or $wgUseFileCache.", "monolog/monolog": "Enable use of MonologSpi ($wgMWLoggerDefaultSpi).", "nmred/kafka-php": "Enable use of KafkaHandler (MonologSpi), or EventRelayerKafka ($wgEventRelayerConfig)." diff --git a/includes/config/EtcdConfig.php b/includes/config/EtcdConfig.php index fdc22954d57..c57e66acd40 100644 --- a/includes/config/EtcdConfig.php +++ b/includes/config/EtcdConfig.php @@ -51,8 +51,6 @@ class EtcdConfig implements Config, LoggerAwareInterface { private $protocol; /** @var string */ private $directory; - /** @var string */ - private $encoding; /** @var int */ private $baseCacheTTL; /** @var int */ @@ -67,7 +65,6 @@ class EtcdConfig implements Config, LoggerAwareInterface { * - service: service name used in SRV discovery. Defaults to 'etcd'. [optional] * - port: custom host port [optional] * - protocol: one of ("http", "https"). Defaults to http. [optional] - * - encoding: one of ("JSON", "YAML"). Defaults to JSON. [optional] * - cache: BagOStuff instance or ObjectFactory spec thereof for a server cache. * The cache will also be used as a fallback if etcd is down. [optional] * - cacheTTL: logical cache TTL in seconds [optional] @@ -79,7 +76,6 @@ class EtcdConfig implements Config, LoggerAwareInterface { 'service' => 'etcd', 'port' => null, 'protocol' => 'http', - 'encoding' => 'JSON', 'cacheTTL' => 10, 'skewTTL' => 1, 'timeout' => 2 @@ -90,7 +86,6 @@ class EtcdConfig implements Config, LoggerAwareInterface { $this->port = $params['port']; $this->protocol = $params['protocol']; $this->directory = trim( $params['directory'], '/' ); - $this->encoding = $params['encoding']; $this->skewCacheTTL = $params['skewTTL']; $this->baseCacheTTL = max( $params['cacheTTL'] - $this->skewCacheTTL, 0 ); $this->timeout = $params['timeout']; @@ -274,7 +269,9 @@ class EtcdConfig implements Config, LoggerAwareInterface { list( $rcode, $rdesc, /* $rhdrs */, $rbody, $rerr ) = $this->http->run( [ 'method' => 'GET', 'url' => "{$this->protocol}://{$host}/v2/keys/{$this->directory}/?recursive=true", - 'headers' => [ 'content-type' => 'application/json' ] + 'headers' => [ + 'content-type' => 'application/json', + ] ] ); $response = [ 'config' => null, 'error' => null, 'retry' => false, 'modifiedIndex' => 0 ]; @@ -359,10 +356,6 @@ class EtcdConfig implements Config, LoggerAwareInterface { * @return mixed */ private function unserialize( $string ) { - if ( $this->encoding === 'YAML' ) { - return yaml_parse( $string ); - } else { - return json_decode( $string, true ); - } + return json_decode( $string, true ); } }