diff options
author | Joas Schilling <coding@schilljs.com> | 2016-09-19 19:43:47 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2016-10-21 09:09:23 +0200 |
commit | 0b1fb180a53fc4e533e2f194977293bc509c5df3 (patch) | |
tree | d28abeb617a3eaf2bee8d97bd284fab126d4cd3f /apps/provisioning_api | |
parent | 50b6ee67cb025332f1ec7012d3705150ef5a165a (diff) | |
download | nextcloud-server-0b1fb180a53fc4e533e2f194977293bc509c5df3.tar.gz nextcloud-server-0b1fb180a53fc4e533e2f194977293bc509c5df3.zip |
Make AppConfig part of the public API
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/provisioning_api')
-rw-r--r-- | apps/provisioning_api/appinfo/routes.php | 17 | ||||
-rw-r--r-- | apps/provisioning_api/lib/Controller/AppConfigController.php | 158 |
2 files changed, 167 insertions, 8 deletions
diff --git a/apps/provisioning_api/appinfo/routes.php b/apps/provisioning_api/appinfo/routes.php index a7366a32a06..04a34fba903 100644 --- a/apps/provisioning_api/appinfo/routes.php +++ b/apps/provisioning_api/appinfo/routes.php @@ -26,12 +26,7 @@ * */ -use OCA\Provisioning_API\Apps; -use OCA\Provisioning_API\Users; -use OCP\API; - -$app = new \OCA\Provisioning_API\AppInfo\Application(); -$app->registerRoutes($this, [ +return [ 'ocs' => [ // Apps ['root' => '/cloud', 'name' => 'Apps#getApps', 'url' => '/apps', 'verb' => 'GET'], @@ -46,7 +41,7 @@ $app->registerRoutes($this, [ ['root' => '/cloud', 'name' => 'Groups#deleteGroup', 'url' => '/groups/{groupId}', 'verb' => 'DELETE'], ['root' => '/cloud', 'name' => 'Groups#getSubAdminsOfGroup', 'url' => '/groups/{groupId}/subadmins', 'verb' => 'GET'], - //Users + // Users ['root' => '/cloud', 'name' => 'Users#getUsers', 'url' => '/users', 'verb' => 'GET'], ['root' => '/cloud', 'name' => 'Users#addUser', 'url' => '/users', 'verb' => 'POST'], ['root' => '/cloud', 'name' => 'Users#getUser', 'url' => '/users/{userId}', 'verb' => 'GET'], @@ -61,5 +56,11 @@ $app->registerRoutes($this, [ ['root' => '/cloud', 'name' => 'Users#addSubAdmin', 'url' => '/users/{userId}/subadmins', 'verb' => 'POST'], ['root' => '/cloud', 'name' => 'Users#removeSubAdmin', 'url' => '/users/{userId}/subadmins', 'verb' => 'DELETE'], + // Config + ['name' => 'AppConfig#getApps', 'url' => '/api/v1/config/apps', 'verb' => 'GET'], + ['name' => 'AppConfig#getKeys', 'url' => '/api/v1/config/apps/{app}', 'verb' => 'GET'], + ['name' => 'AppConfig#getValue', 'url' => '/api/v1/config/apps/{app}/{key}', 'verb' => 'GET'], + ['name' => 'AppConfig#setValue', 'url' => '/api/v1/config/apps/{app}/{key}', 'verb' => 'POST'], + ['name' => 'AppConfig#deleteKey', 'url' => '/api/v1/config/apps/{app}/{key}', 'verb' => 'DELETE'], ], -]); +]; diff --git a/apps/provisioning_api/lib/Controller/AppConfigController.php b/apps/provisioning_api/lib/Controller/AppConfigController.php new file mode 100644 index 00000000000..05c86c17ac2 --- /dev/null +++ b/apps/provisioning_api/lib/Controller/AppConfigController.php @@ -0,0 +1,158 @@ +<?php +/** + * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\Provisioning_API\Controller; + + +use OCP\AppFramework\Http; +use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\OCSController; +use OCP\IAppConfig; +use OCP\IConfig; +use OCP\IRequest; + +class AppConfigController extends OCSController { + + /** @var IAppConfig */ + protected $config; + + /** @var IConfig */ + protected $appConfig; + + /** + * @param string $appName + * @param IRequest $request + * @param IConfig $config + * @param IAppConfig $appConfig + */ + public function __construct($appName, + IRequest $request, + IConfig $config, + IAppConfig $appConfig) { + parent::__construct($appName, $request); + $this->config = $config; + $this->appConfig = $appConfig; + } + + /** + * @return DataResponse + */ + public function getApps() { + return new DataResponse([ + 'data' => $this->appConfig->getApps(), + ]); + } + + /** + * @param string $app + * @return DataResponse + */ + public function getKeys($app) { + try { + $this->verifyAppId($app); + } catch (\InvalidArgumentException $e) { + return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_FORBIDDEN); + } + return new DataResponse([ + 'data' => $this->config->getAppKeys($app), + ]); + } + + /** + * @param string $app + * @param string $key + * @param string $defaultValue + * @return DataResponse + */ + public function getValue($app, $key, $defaultValue = '') { + try { + $this->verifyAppId($app); + } catch (\InvalidArgumentException $e) { + return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_FORBIDDEN); + } + return new DataResponse([ + 'data' => $this->config->getAppValue($app, $key, $defaultValue), + ]); + } + + /** + * @PasswordConfirmationRequired + * @param string $app + * @param string $key + * @param string $value + * @return DataResponse + */ + public function setValue($app, $key, $value) { + try { + $this->verifyAppId($app); + $this->verifyConfigKey($app, $key); + } catch (\InvalidArgumentException $e) { + return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_FORBIDDEN); + } + + $this->config->setAppValue($app, $key, $value); + return new DataResponse(); + } + + /** + * @PasswordConfirmationRequired + * @param string $app + * @param string $key + * @return DataResponse + */ + public function deleteKey($app, $key) { + try { + $this->verifyAppId($app); + $this->verifyConfigKey($app, $key); + } catch (\InvalidArgumentException $e) { + return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_FORBIDDEN); + } + + return new DataResponse([ + 'data' => $this->config->deleteAppValue($app, $key), + ]); + } + + /** + * @param string $app + * @throws \InvalidArgumentException + */ + protected function verifyAppId($app) { + if (\OC_App::cleanAppId($app) !== $app) { + throw new \InvalidArgumentException('Invalid app id given'); + } + } + + /** + * @param string $app + * @param string $key + * @throws \InvalidArgumentException + */ + protected function verifyConfigKey($app, $key) { + if (in_array($key, ['installed_version', 'enabled', 'types'])) { + throw new \InvalidArgumentException('The given key can not be set'); + } + + if ($app === 'core' && (strpos($key, 'public_') === 0 || strpos($key, 'remote_') === 0)) { + throw new \InvalidArgumentException('The given key can not be set'); + } + } +} |