-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Migrate federation application to LoggerInterface #39018
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2016, ownCloud, Inc. | ||
* | ||
* @author Bjoern Schiessle <[email protected]> | ||
* @author Björn Schießle <[email protected]> | ||
* @author Christoph Wurst <[email protected]> | ||
* @author Côme Chilliet <[email protected]> | ||
* @author Joas Schilling <[email protected]> | ||
* @author Lukas Reschke <[email protected]> | ||
* @author Morris Jobke <[email protected]> | ||
|
@@ -37,9 +41,9 @@ | |
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 @@ | |
* @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 @@ public function execute(IJobList $jobList, ILogger $logger = null) { | |
} | ||
|
||
/** | ||
* 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 @@ protected function run($argument) { | |
$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 @@ protected function run($argument) { | |
|
||
/** | ||
* 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']; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a public method, just double checking to ensure you have checked for references in other parts of the code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the parent class
OCP\BackgroundJob\Job
is migrating fromexecute
tostart
since 25, I think we should even deprecateexecute
since it’s always a problem for migrating away fromILogger
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an issue for that? If not I could create one and deprecate it rn.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I just saw that
execute
is already deprecated inIJob
interface.Maybe it would still be a good idea to mark it as deprecated in
Job
class as well.