Skip to content

feat: maintenance update, basic object storage support, minor cleanup #122

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

Merged
merged 7 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to this project will be documented in this file.

## [0.2.0 - 2024-10-20]

Maintenance update. Update NC versions to support NC30+ only.

### Added

- Added basic ObjectStorage support (/tmp folder used to execute binary scripts)

## [0.1.9 - 2023-12-14]

Maintenance update.
Expand Down
4 changes: 2 additions & 2 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Nextcloud Python API Framework
- [MediaDC](https://apps.nextcloud.com/apps/mediadc) - Nextcloud Media Duplicate Collector app
]]>
</description>
<version>0.1.9</version>
<version>0.2.0</version>
<licence>agpl</licence>
<author mail="[email protected]" homepage="https://github.com/andrey18106">Andrey Borysenko</author>
<author mail="[email protected]" homepage="https://github.com/bigcat88">Alexander Piskun</author>
Expand All @@ -37,7 +37,7 @@ Nextcloud Python API Framework
<repository type="git">https://github.com/cloud-py-api/cloud_py_api</repository>
<dependencies>
<php min-version="7.4" min-int-size="64" />
<nextcloud min-version="28" max-version="29" />
<nextcloud min-version="30" max-version="31" />
</dependencies>
<repair-steps>
<post-migration>
Expand Down
14 changes: 4 additions & 10 deletions lib/Command/GetFileContentsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,11 @@ class GetFileContentsCommand extends Command {
public const ARGUMENT_FILE_ID = 'fileid';
public const ARGUMENT_USER_ID = 'userid';

/** @var IRootFolder */
private $rootFolder;

/** @var LoggerInterface */
private $logger;

public function __construct(IRootFolder $rootFolder, LoggerInterface $logger) {
public function __construct(
private readonly IRootFolder $rootFolder,
private readonly LoggerInterface $logger
) {
parent::__construct();

$this->rootFolder = $rootFolder;
$this->logger = $logger;
}

protected function configure(): void {
Expand Down
63 changes: 11 additions & 52 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

namespace OCA\Cloud_Py_API\Controller;

use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired;
use OCP\IRequest;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
Expand All @@ -38,80 +40,37 @@
use OCA\Cloud_Py_API\Service\UtilsService;

class SettingsController extends Controller {
/** @var SettingsService */
private $service;

/** @var UtilsService */
private $utils;

public function __construct(
IRequest $request,
SettingsService $service,
UtilsService $utils
private readonly SettingsService $service,
private readonly UtilsService $utils
) {
parent::__construct(Application::APP_ID, $request);

$this->service = $service;
$this->utils = $utils;
}

/**
* @NoAdminRequired
* @NoCSRFRequired
*
* @return JSONResponse array of all settings
*/
public function index() {
#[NoAdminRequired]
public function index(): JSONResponse {
return new JSONResponse($this->service->getSettings(), Http::STATUS_OK);
}

/**
* @NoCSRFRequired
*
* @param array $settings
*
* @return JSONResponse
*/
public function update($settings) {
#[PasswordConfirmationRequired]
public function update(array $settings): JSONResponse {
return new JSONResponse($this->service->updateSettings($settings), Http::STATUS_OK);
}

/**
* @NoCSRFRequired
*
* @param array $setting
*
* @return JSONResponse
*/
public function updateSetting($setting) {
#[PasswordConfirmationRequired]
public function updateSetting(array $setting): JSONResponse {
return new JSONResponse($this->service->updateSetting($setting), Http::STATUS_OK);
}

/**
* @NoAdminRequired
* @NoCSRFRequired
*
* @param int $id
*/
public function getSettingById($id): JSONResponse {
public function getSettingById(int $id): JSONResponse {
return new JSONResponse($this->service->getSettingById($id), Http::STATUS_OK);
}

/**
* @NoAdminRequired
* @NoCSRFRequired
*
* @param string $name
*/
public function getSettingByName($name): JSONResponse {
return new JSONResponse($this->service->getSettingByName($name), Http::STATUS_OK);
}

/**
* @NoCSRFRequired
*
* @return JSONResponse array of system configuration
*/
public function systemInfo() {
return new JSONResponse($this->utils->getSystemInfo(), Http::STATUS_OK);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Db/SettingMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(IDBConnection $db) {
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
*/
public function find(int $id): Entity {
public function find(int $id): Setting {
$qb = $this->db->getQueryBuilder();

$qb->select('*')
Expand Down
13 changes: 4 additions & 9 deletions lib/Migration/AppDataInitializationStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,10 @@
use OCA\Cloud_Py_API\Service\UtilsService;

class AppDataInitializationStep implements IRepairStep {
/** @var SettingsMapper */
private $settingMapper;

/** @var UtilsService */
private $utils;

public function __construct(SettingMapper $settingMapper, UtilsService $utils) {
$this->settingMapper = $settingMapper;
$this->utils = $utils;
public function __construct(
private readonly SettingMapper $settingMapper,
private readonly UtilsService $utils,
) {
}

public function getName(): string {
Expand Down
8 changes: 3 additions & 5 deletions lib/Migration/AppUpdateStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@
use OCA\Cloud_Py_API\Service\UtilsService;

class AppUpdateStep implements IRepairStep {
/** @var UtilsService */
private $utils;

public function __construct(UtilsService $utils) {
$this->utils = $utils;
public function __construct(
private readonly UtilsService $utils,
) {
}

public function getName(): string {
Expand Down
45 changes: 26 additions & 19 deletions lib/Service/PythonService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,29 @@

use OCA\Cloud_Py_API\Db\SettingMapper;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\ITempManager;

class PythonService {
/** @var string */
private $pythonCommand;

/** @var string */
private $ncInstanceId;

/** @var string */
private $ncDataFolder;

/** @var UtilsService */
private $utils;
private string $pythonCommand;
private string $ncInstanceId;
private string $ncDataFolder;
private bool $isObjectStorage;

public function __construct(
IConfig $config,
private readonly IConfig $config,
SettingMapper $settingMapper,
UtilsService $utils
private readonly UtilsService $utils,
private readonly ITempManager $tempManager,
) {
try {
$pythonCommand = $settingMapper->findByName('python_command');
$this->pythonCommand = $pythonCommand->getValue();
} catch (DoesNotExistException $e) {
$this->pythonCommand = '/usr/bin/python3';
}
$this->utils = $utils;
$this->ncInstanceId = $config->getSystemValue('instanceid');
$this->ncDataFolder = $config->getSystemValue('datadirectory');
$this->ncInstanceId = $this->config->getSystemValue('instanceid');
$this->ncDataFolder = $this->config->getSystemValue('datadirectory');
$this->isObjectStorage = $this->config->getSystemValue('objectstore', null) !== null;
}

/**
Expand All @@ -84,10 +79,14 @@ public function run(
array $scriptParams = [],
bool $nonBlocking = false,
array $env = [],
bool $binary = false
bool $binary = false,
) {
if ($binary) {
$cwd = $this->ncDataFolder . '/appdata_' . $this->ncInstanceId . '/' . $appId . '/';
if ($this->isObjectStorage) {
$cwd = ''; // scriptName should already include absolute path (/tmp/...)
} else {
$cwd = $this->ncDataFolder . '/appdata_' . $this->ncInstanceId . '/' . $appId . '/';
}
} else {
$cwd = $this->utils->getCustomAppsDirectory() . $appId . '/';
}
Expand All @@ -111,7 +110,15 @@ public function run(
}
if ($nonBlocking) {
if ($binary) {
$logFile = $cwd . 'logs/' . date('d-m-Y_H-i-s', time()) . '.log';
if (!$this->isObjectStorage) {
$logFile = $cwd . 'logs/' . date('d-m-Y_H-i-s', time()) . '.log';
} else {
$tempLogsDir = $this->tempManager->getTempBaseDir() . '/' . $appId . '/logs/';
if (!file_exists($tempLogsDir)) {
mkdir($tempLogsDir, 0700, true);
}
$logFile = $tempLogsDir . $appId . '_' . date('d-m-Y_H-i-s', time()) . '.log';
}
} else {
$appDataDir = $this->ncDataFolder . '/appdata_' . $this->ncInstanceId . '/' . $appId . '/';
$pyBitecodeEnvVar = 'PYTHONBYTECODEBASE="' . $appDataDir . '" ';
Expand Down
8 changes: 3 additions & 5 deletions lib/Service/SettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@
use OCA\Cloud_Py_API\Db\SettingMapper;

class SettingsService {
/** @var SettingMapper */
private $mapper;

public function __construct(SettingMapper $settingMapper) {
$this->mapper = $settingMapper;
public function __construct(
private readonly SettingMapper $mapper
) {
}

/**
Expand Down
Loading
Loading