Skip to content
Open
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: 2 additions & 1 deletion apps/admin_audit/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\Services\IAppConfig;
use OCP\Authentication\Events\AnyLoginFailedEvent;
use OCP\Authentication\TwoFactorAuth\TwoFactorProviderChallengeFailed;
use OCP\Authentication\TwoFactorAuth\TwoFactorProviderChallengePassed;
Expand Down Expand Up @@ -81,7 +82,7 @@ public function __construct() {

public function register(IRegistrationContext $context): void {
$context->registerService(IAuditLogger::class, function (ContainerInterface $c) {
return new AuditLogger($c->get(ILogFactory::class), $c->get(IConfig::class));
return new AuditLogger($c->get(ILogFactory::class), $c->get(IAppConfig::class), $c->get(IConfig::class));
});
Comment on lines 84 to 86
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could simply be an alias I believe?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need the factory/closure to create the IAuditLogger service AFAIK. In this case the factory/closure is creating the IAuditLogger:class as a service, by returning an AuditLogger.

Just the interface IAuditLogger is being published as the service directly.

I guess we could do both, but I don't see any reason to register the service against both the implementation and the interface. Existing behavior too. ;-)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DI is able to magically build classes based on their attributes.
So you can just do

$context->registerServiceAlias(IAuditLogger::class, AuditLogger::class);


$context->registerEventListener(CriticalActionPerformedEvent::class, CriticalActionPerformedEventListener::class);
Expand Down
9 changes: 7 additions & 2 deletions apps/admin_audit/lib/AuditLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace OCA\AdminAudit;

use OCP\AppFramework\Services\IAppConfig;
use OCP\IConfig;
use OCP\Log\ILogFactory;
use Psr\Log\LoggerInterface;
Expand All @@ -20,7 +21,11 @@ class AuditLogger implements IAuditLogger {

private LoggerInterface $parentLogger;

public function __construct(ILogFactory $logFactory, IConfig $config) {
public function __construct(
ILogFactory $logFactory,
IAppConfig $appConfig,
IConfig $config,
) {
$auditType = $config->getSystemValueString('log_type_audit', 'file');
$defaultTag = $config->getSystemValueString('syslog_tag', 'Nextcloud');
$auditTag = $config->getSystemValueString('syslog_tag_audit', $defaultTag);
Expand All @@ -29,7 +34,7 @@ public function __construct(ILogFactory $logFactory, IConfig $config) {
if ($auditType === 'file' && !$logFile) {
$default = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log';
// Legacy way was appconfig, now it's paralleled with the normal log config
$logFile = $config->getAppValue('admin_audit', 'logfile', $default);
$logFile = $appConfig->getAppValueString('logfile', $default);
}

$this->parentLogger = $logFactory->getCustomPsrLogger($logFile, $auditType, $auditTag);
Expand Down
4 changes: 3 additions & 1 deletion apps/admin_audit/lib/BackgroundJobs/Rotate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
namespace OCA\AdminAudit\BackgroundJobs;

use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCP\IConfig;
Expand All @@ -17,6 +18,7 @@ class Rotate extends TimedJob {

public function __construct(
ITimeFactory $time,
private IAppConfig $appConfig,
private IConfig $config,
) {
parent::__construct($time);
Expand All @@ -26,7 +28,7 @@ public function __construct(

protected function run($argument): void {
$default = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log';
$this->filePath = $this->config->getAppValue('admin_audit', 'logfile', $default);
$this->filePath = $this->appConfig->getAppValueString('logfile', $default);

if ($this->filePath === '') {
// default log file, nothing to do
Expand Down
10 changes: 0 additions & 10 deletions build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@
<code><![CDATA[Util::connectHook(Share::class, 'share_link_access', $shareActions, 'shareAccessed')]]></code>
</DeprecatedMethod>
</file>
<file src="apps/admin_audit/lib/AuditLogger.php">
<DeprecatedMethod>
<code><![CDATA[getAppValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/admin_audit/lib/BackgroundJobs/Rotate.php">
<DeprecatedMethod>
<code><![CDATA[getAppValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/cloud_federation_api/lib/Controller/RequestHandlerController.php">
<DeprecatedMethod>
<code><![CDATA[Util::emitHook(
Expand Down
Loading