fix: Replace deprecated ILogger with Psr\Log\LoggerInterface
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
Родитель
a10bd946b1
Коммит
360518b905
|
@ -15,20 +15,16 @@ use OCA\SuspiciousLogin\Service\TrainingDataConfig;
|
|||
use OCA\SuspiciousLogin\Service\TrainService;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\BackgroundJob\TimedJob;
|
||||
use OCP\ILogger;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Throwable;
|
||||
|
||||
class TrainJobIpV4 extends TimedJob {
|
||||
|
||||
/** @var TrainService */
|
||||
private $trainService;
|
||||
|
||||
/** @var ILogger */
|
||||
private $logger;
|
||||
|
||||
public function __construct(TrainService $trainService,
|
||||
ILogger $logger,
|
||||
ITimeFactory $time) {
|
||||
public function __construct(
|
||||
private TrainService $trainService,
|
||||
private LoggerInterface $logger,
|
||||
ITimeFactory $time,
|
||||
) {
|
||||
parent::__construct($time);
|
||||
|
||||
$this->setInterval(24 * 60 * 60);
|
||||
|
@ -38,8 +34,6 @@ class TrainJobIpV4 extends TimedJob {
|
|||
if (defined('\OCP\BackgroundJob\IJob::TIME_INSENSITIVE') && method_exists($this, 'setTimeSensitivity')) {
|
||||
$this->setTimeSensitivity(self::TIME_INSENSITIVE);
|
||||
}
|
||||
$this->trainService = $trainService;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,15 +50,9 @@ class TrainJobIpV4 extends TimedJob {
|
|||
$strategy
|
||||
);
|
||||
} catch (InsufficientDataException $ex) {
|
||||
$this->logger->logException($ex, [
|
||||
'level' => ILogger::INFO,
|
||||
'message' => 'No suspicious login model for IPv4 trained because of insufficient data',
|
||||
]);
|
||||
$this->logger->info('No suspicious login model for IPv4 trained because of insufficient data', ['exception' => $ex]);
|
||||
} catch (Throwable $ex) {
|
||||
$this->logger->logException($ex, [
|
||||
'level' => ILogger::ERROR,
|
||||
'message' => 'Caught unknown error during IPv4 background training',
|
||||
]);
|
||||
$this->logger->error('Caught unknown error during IPv4 background training', ['exception' => $ex]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,20 +15,16 @@ use OCA\SuspiciousLogin\Service\TrainingDataConfig;
|
|||
use OCA\SuspiciousLogin\Service\TrainService;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\BackgroundJob\TimedJob;
|
||||
use OCP\ILogger;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Throwable;
|
||||
|
||||
class TrainJobIpV6 extends TimedJob {
|
||||
|
||||
/** @var TrainService */
|
||||
private $trainService;
|
||||
|
||||
/** @var ILogger */
|
||||
private $logger;
|
||||
|
||||
public function __construct(TrainService $trainService,
|
||||
ILogger $logger,
|
||||
ITimeFactory $time) {
|
||||
public function __construct(
|
||||
private TrainService $trainService,
|
||||
private LoggerInterface $logger,
|
||||
ITimeFactory $time,
|
||||
) {
|
||||
parent::__construct($time);
|
||||
|
||||
$this->setInterval(24 * 60 * 60);
|
||||
|
@ -38,8 +34,6 @@ class TrainJobIpV6 extends TimedJob {
|
|||
if (defined('\OCP\BackgroundJob\IJob::TIME_INSENSITIVE') && method_exists($this, 'setTimeSensitivity')) {
|
||||
$this->setTimeSensitivity(self::TIME_INSENSITIVE);
|
||||
}
|
||||
$this->trainService = $trainService;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,15 +50,9 @@ class TrainJobIpV6 extends TimedJob {
|
|||
$strategy
|
||||
);
|
||||
} catch (InsufficientDataException $ex) {
|
||||
$this->logger->logException($ex, [
|
||||
'level' => ILogger::INFO,
|
||||
'message' => 'No suspicious login model for IPv6 trained because of insufficient data',
|
||||
]);
|
||||
$this->logger->info('No suspicious login model for IPv6 trained because of insufficient data', ['exception' => $ex]);
|
||||
} catch (Throwable $ex) {
|
||||
$this->logger->logException($ex, [
|
||||
'level' => ILogger::ERROR,
|
||||
'message' => 'Caught unknown error during IPv6 background training',
|
||||
]);
|
||||
$this->logger->error('Caught unknown error during IPv6 background training', ['exception' => $ex]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,38 +14,24 @@ use OCP\EventDispatcher\Event;
|
|||
use OCP\EventDispatcher\IEventListener;
|
||||
use OCP\IConfig;
|
||||
use OCP\IL10N;
|
||||
use OCP\ILogger;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Mail\IMailer;
|
||||
use OCP\Mail\IMessage;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* @implements IEventListener<SuspiciousLoginEvent>
|
||||
*/
|
||||
class LoginMailListener implements IEventListener {
|
||||
|
||||
/** @var ILogger */
|
||||
private $logger;
|
||||
|
||||
/** @var IMailer */
|
||||
private $mailer;
|
||||
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
|
||||
/** @var IL10N */
|
||||
private $l;
|
||||
|
||||
/** @var IConfig */
|
||||
protected $config;
|
||||
|
||||
public function __construct(ILogger $logger, IMailer $mailer, IUserManager $userManager, IL10N $l, IConfig $config) {
|
||||
$this->logger = $logger;
|
||||
$this->mailer = $mailer;
|
||||
$this->userManager = $userManager;
|
||||
$this->l = $l;
|
||||
$this->config = $config;
|
||||
public function __construct(
|
||||
private LoggerInterface $logger,
|
||||
private IMailer $mailer,
|
||||
private IUserManager $userManager,
|
||||
private IL10N $l,
|
||||
private IConfig $config,
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(Event $event): void {
|
||||
|
@ -69,10 +55,7 @@ class LoginMailListener implements IEventListener {
|
|||
$this->getMail($event, $user)
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
$this->logger->logException($e, [
|
||||
'message' => "Could not send suspicious login email to <$uid>",
|
||||
'level' => ILogger::ERROR,
|
||||
]);
|
||||
$this->logger->error("Could not send suspicious login email to <$uid>", ['exception' => $e]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,27 +13,19 @@ use OCA\SuspiciousLogin\Event\SuspiciousLoginEvent;
|
|||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\EventDispatcher\IEventListener;
|
||||
use OCP\ILogger;
|
||||
use OCP\Notification\IManager;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* @implements IEventListener<SuspiciousLoginEvent>
|
||||
*/
|
||||
class LoginNotificationListener implements IEventListener {
|
||||
|
||||
/** @var IManager */
|
||||
private $notificationManager;
|
||||
/** @var ITimeFactory */
|
||||
private $timeFactory;
|
||||
/** @var ILogger */
|
||||
private $logger;
|
||||
|
||||
public function __construct(IManager $notificationManager,
|
||||
ITimeFactory $timeFactory,
|
||||
ILogger $logger) {
|
||||
$this->notificationManager = $notificationManager;
|
||||
$this->timeFactory = $timeFactory;
|
||||
$this->logger = $logger;
|
||||
public function __construct(
|
||||
private IManager $notificationManager,
|
||||
private ITimeFactory $timeFactory,
|
||||
private LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(Event $event): void {
|
||||
|
@ -52,8 +44,7 @@ class LoginNotificationListener implements IEventListener {
|
|||
]);
|
||||
$this->notificationManager->notify($notification);
|
||||
} catch (\Throwable $ex) {
|
||||
$this->logger->critical("could not send notification about a suspicious login");
|
||||
$this->logger->logException($ex);
|
||||
$this->logger->critical('Could not send notification about a suspicious login', ['exception' => $ex]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,28 +13,18 @@ use Generator;
|
|||
use OCA\SuspiciousLogin\Db\LoginAddressAggregatedMapper;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\ILogger;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Console\Helper\ProgressBar;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class ETLService {
|
||||
public const MAX_BATCH_SIZE = 10000;
|
||||
|
||||
/** @var IDBConnection */
|
||||
private $db;
|
||||
|
||||
/** @var LoginAddressAggregatedMapper */
|
||||
private $aggregatedMapper;
|
||||
|
||||
/** @var ILogger */
|
||||
private $logger;
|
||||
|
||||
public function __construct(IDBConnection $db,
|
||||
LoginAddressAggregatedMapper $aggregatedMapper,
|
||||
ILogger $logger) {
|
||||
$this->db = $db;
|
||||
$this->aggregatedMapper = $aggregatedMapper;
|
||||
$this->logger = $logger;
|
||||
public function __construct(
|
||||
private IDBConnection $db,
|
||||
private LoginAddressAggregatedMapper $aggregatedMapper,
|
||||
private LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
|
||||
private function getRaw(int $max, ?OutputInterface $output = null): Generator {
|
||||
|
|
|
@ -10,22 +10,16 @@ declare(strict_types=1);
|
|||
namespace OCA\SuspiciousLogin\Service;
|
||||
|
||||
use OCA\SuspiciousLogin\Exception\ServiceException;
|
||||
use OCP\ILogger;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Rubix\ML\Datasets\Unlabeled;
|
||||
use RuntimeException;
|
||||
|
||||
class EstimatorService {
|
||||
|
||||
/** @var ModelStore */
|
||||
private $modelStore;
|
||||
|
||||
/** @var ILogger */
|
||||
private $logger;
|
||||
|
||||
public function __construct(ModelStore $modelStore,
|
||||
ILogger $logger) {
|
||||
$this->modelStore = $modelStore;
|
||||
$this->logger = $logger;
|
||||
public function __construct(
|
||||
private ModelStore $modelStore,
|
||||
private LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,8 +16,8 @@ use OCA\SuspiciousLogin\Exception\ServiceException;
|
|||
use OCA\SuspiciousLogin\Util\AddressClassifier;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\ILogger;
|
||||
use OCP\IRequest;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Throwable;
|
||||
use function base64_decode;
|
||||
use function explode;
|
||||
|
@ -27,36 +27,14 @@ use function substr;
|
|||
|
||||
class LoginClassifier {
|
||||
|
||||
/** @var EstimatorService */
|
||||
private $estimator;
|
||||
|
||||
/** @var IRequest */
|
||||
private $request;
|
||||
|
||||
/** @var ILogger */
|
||||
private $logger;
|
||||
|
||||
/** @var SuspiciousLoginMapper */
|
||||
private $mapper;
|
||||
|
||||
/** @var ITimeFactory */
|
||||
private $timeFactory;
|
||||
|
||||
/** @var IEventDispatcher */
|
||||
private $dispatcher;
|
||||
|
||||
public function __construct(EstimatorService $estimator,
|
||||
IRequest $request,
|
||||
ILogger $logger,
|
||||
SuspiciousLoginMapper $mapper,
|
||||
ITimeFactory $timeFactory,
|
||||
IEventDispatcher $dispatcher) {
|
||||
$this->estimator = $estimator;
|
||||
$this->request = $request;
|
||||
$this->logger = $logger;
|
||||
$this->mapper = $mapper;
|
||||
$this->timeFactory = $timeFactory;
|
||||
$this->dispatcher = $dispatcher;
|
||||
public function __construct(
|
||||
private EstimatorService $estimator,
|
||||
private IRequest $request,
|
||||
private LoggerInterface $logger,
|
||||
private SuspiciousLoginMapper $mapper,
|
||||
private ITimeFactory $timeFactory,
|
||||
private IEventDispatcher $dispatcher,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -126,8 +104,7 @@ class LoginClassifier {
|
|||
|
||||
return $entity;
|
||||
} catch (Throwable $ex) {
|
||||
$this->logger->critical("could not save the details of a suspicious login");
|
||||
$this->logger->logException($ex);
|
||||
$this->logger->critical('could not save the details of a suspicious login', ['exception' => $ex]);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,8 +18,8 @@ use OCP\AppFramework\Db\DoesNotExistException;
|
|||
use OCP\Files\IAppData;
|
||||
use OCP\Files\NotFoundException;
|
||||
use OCP\ICacheFactory;
|
||||
use OCP\ILogger;
|
||||
use OCP\ITempManager;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Rubix\ML\Estimator;
|
||||
use Rubix\ML\Persistable;
|
||||
use Rubix\ML\Persisters\Filesystem;
|
||||
|
@ -32,36 +32,14 @@ use function strlen;
|
|||
class ModelStore {
|
||||
public const APPDATA_MODELS_FOLDER = 'models';
|
||||
|
||||
/** @var ModelMapper */
|
||||
private $modelMapper;
|
||||
|
||||
/** @var IAppData */
|
||||
private $appData;
|
||||
|
||||
/** @var IAppManager */
|
||||
private $appManager;
|
||||
|
||||
/** @var ITempManager */
|
||||
private $tempManager;
|
||||
|
||||
/** @var ICacheFactory */
|
||||
private $cacheFactory;
|
||||
|
||||
/** @var ILogger */
|
||||
private $logger;
|
||||
|
||||
public function __construct(ModelMapper $modelMapper,
|
||||
IAppData $appData,
|
||||
IAppManager $appManager,
|
||||
ITempManager $tempManager,
|
||||
ICacheFactory $cachFactory,
|
||||
ILogger $logger) {
|
||||
$this->appData = $appData;
|
||||
$this->appManager = $appManager;
|
||||
$this->modelMapper = $modelMapper;
|
||||
$this->tempManager = $tempManager;
|
||||
$this->cacheFactory = $cachFactory;
|
||||
$this->logger = $logger;
|
||||
public function __construct(
|
||||
private ModelMapper $modelMapper,
|
||||
private IAppData $appData,
|
||||
private IAppManager $appManager,
|
||||
private ITempManager $tempManager,
|
||||
private ICacheFactory $cacheFactory,
|
||||
private LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Загрузка…
Ссылка в новой задаче