aboutsummaryrefslogtreecommitdiffstats
path: root/apps/federation/lib
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2023-06-26 17:20:08 +0200
committerCôme Chilliet <come.chilliet@nextcloud.com>2023-06-26 17:20:08 +0200
commitd34662f1a3330caea8fa30276ab6e392e8cf0846 (patch)
tree996b8ed4096fd66d8c1e319a266eff98e461a227 /apps/federation/lib
parent9751303182069e510e67015ba81c0cd224b4a483 (diff)
downloadnextcloud-server-d34662f1a3330caea8fa30276ab6e392e8cf0846.tar.gz
nextcloud-server-d34662f1a3330caea8fa30276ab6e392e8cf0846.zip
Migrate federation application to LoggerInterface
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'apps/federation/lib')
-rw-r--r--apps/federation/lib/BackgroundJob/RequestSharedSecret.php89
1 files changed, 28 insertions, 61 deletions
diff --git a/apps/federation/lib/BackgroundJob/RequestSharedSecret.php b/apps/federation/lib/BackgroundJob/RequestSharedSecret.php
index 13ac9178eda..d410af2a7f4 100644
--- a/apps/federation/lib/BackgroundJob/RequestSharedSecret.php
+++ b/apps/federation/lib/BackgroundJob/RequestSharedSecret.php
@@ -1,10 +1,14 @@
<?php
+
+declare(strict_types=1);
+
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Bjoern Schiessle <bjoern@schiessle.org>
* @author Björn Schießle <bjoern@schiessle.org>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
+ * @author Côme Chilliet <come@chilliet.eu>
* @author Joas Schilling <coding@schilljs.com>
* @author Lukas Reschke <lukas@statuscode.ch>
* @author Morris Jobke <hey@morrisjobke.de>
@@ -37,9 +41,9 @@ use OCP\BackgroundJob\IJobList;
use OCP\BackgroundJob\Job;
use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
-use OCP\ILogger;
use OCP\IURLGenerator;
use OCP\OCS\IDiscoveryService;
+use Psr\Log\LoggerInterface;
/**
* Class RequestSharedSecret
@@ -49,74 +53,37 @@ use OCP\OCS\IDiscoveryService;
* @package OCA\Federation\Backgroundjob
*/
class RequestSharedSecret extends Job {
+ private IClient $httpClient;
- /** @var IClient */
- private $httpClient;
-
- /** @var IJobList */
- private $jobList;
-
- /** @var IURLGenerator */
- private $urlGenerator;
-
- /** @var TrustedServers */
- private $trustedServers;
-
- /** @var IDiscoveryService */
- private $ocsDiscoveryService;
-
- /** @var ILogger */
- private $logger;
+ protected bool $retainJob = false;
- /** @var bool */
- protected $retainJob = false;
+ private string $defaultEndPoint = '/ocs/v2.php/apps/federation/api/v1/request-shared-secret';
- private $defaultEndPoint = '/ocs/v2.php/apps/federation/api/v1/request-shared-secret';
+ /** @var int 30 day = 2592000sec */
+ private int $maxLifespan = 2592000;
- /** @var int 30 day = 2592000sec */
- private $maxLifespan = 2592000;
-
- /**
- * RequestSharedSecret constructor.
- *
- * @param IClientService $httpClientService
- * @param IURLGenerator $urlGenerator
- * @param IJobList $jobList
- * @param TrustedServers $trustedServers
- * @param IDiscoveryService $ocsDiscoveryService
- * @param ILogger $logger
- * @param ITimeFactory $timeFactory
- */
public function __construct(
IClientService $httpClientService,
- IURLGenerator $urlGenerator,
- IJobList $jobList,
- TrustedServers $trustedServers,
- IDiscoveryService $ocsDiscoveryService,
- ILogger $logger,
- ITimeFactory $timeFactory
+ private IURLGenerator $urlGenerator,
+ private IJobList $jobList,
+ private TrustedServers $trustedServers,
+ private IDiscoveryService $ocsDiscoveryService,
+ private LoggerInterface $logger,
+ ITimeFactory $timeFactory,
) {
parent::__construct($timeFactory);
$this->httpClient = $httpClientService->newClient();
- $this->jobList = $jobList;
- $this->urlGenerator = $urlGenerator;
- $this->logger = $logger;
- $this->ocsDiscoveryService = $ocsDiscoveryService;
- $this->trustedServers = $trustedServers;
}
/**
* run the job, then remove it from the joblist
- *
- * @param IJobList $jobList
- * @param ILogger|null $logger
*/
- public function execute(IJobList $jobList, ILogger $logger = null) {
+ public function start(IJobList $jobList): void {
$target = $this->argument['url'];
// only execute if target is still in the list of trusted domains
if ($this->trustedServers->isTrustedServer($target)) {
- $this->parentExecute($jobList, $logger);
+ $this->parentStart($jobList);
}
$jobList->remove($this, $this->argument);
@@ -127,15 +94,17 @@ class RequestSharedSecret extends Job {
}
/**
- * call execute() method of parent
- *
- * @param IJobList $jobList
- * @param ILogger $logger
+ * Call start() method of parent
+ * Useful for unit tests
*/
- protected function parentExecute($jobList, $logger) {
- parent::execute($jobList, $logger);
+ protected function parentStart(IJobList $jobList): void {
+ parent::start($jobList);
}
+ /**
+ * @param array $argument
+ * @return void
+ */
protected function run($argument) {
$target = $argument['url'];
$created = isset($argument['created']) ? (int)$argument['created'] : $this->time->getTime();
@@ -185,7 +154,7 @@ class RequestSharedSecret extends Job {
$this->logger->info('Could not connect to ' . $target, ['app' => 'federation']);
} catch (\Throwable $e) {
$status = Http::STATUS_INTERNAL_SERVER_ERROR;
- $this->logger->logException($e, ['app' => 'federation']);
+ $this->logger->error($e->getMessage(), ['app' => 'federation', 'exception' => $e]);
}
// if we received a unexpected response we try again later
@@ -199,10 +168,8 @@ class RequestSharedSecret extends Job {
/**
* re-add background job
- *
- * @param array $argument
*/
- protected function reAddJob(array $argument) {
+ protected function reAddJob(array $argument): void {
$url = $argument['url'];
$created = isset($argument['created']) ? (int)$argument['created'] : $this->time->getTime();
$token = $argument['token'];