Completed
Pull Request — master (#5550)
by Andreas
16:28
created
apps/files_external/lib/config.php 1 patch
Indentation   +367 added lines, -367 removed lines patch added patch discarded remove patch
@@ -45,371 +45,371 @@
 block discarded – undo
45 45
  * Class to configure mount.json globally and for users
46 46
  */
47 47
 class OC_Mount_Config {
48
-	// TODO: make this class non-static and give it a proper namespace
49
-
50
-	const MOUNT_TYPE_GLOBAL = 'global';
51
-	const MOUNT_TYPE_GROUP = 'group';
52
-	const MOUNT_TYPE_USER = 'user';
53
-	const MOUNT_TYPE_PERSONAL = 'personal';
54
-
55
-	// whether to skip backend test (for unit tests, as this static class is not mockable)
56
-	public static $skipTest = false;
57
-
58
-	/** @var Application */
59
-	public static $app;
60
-
61
-	/**
62
-	 * @param string $class
63
-	 * @param array $definition
64
-	 * @return bool
65
-	 * @deprecated 8.2.0 use \OCA\Files_External\Service\BackendService::registerBackend()
66
-	 */
67
-	public static function registerBackend($class, $definition) {
68
-		$backendService = self::$app->getContainer()->query('OCA\Files_External\Service\BackendService');
69
-		$auth = self::$app->getContainer()->query('OCA\Files_External\Lib\Auth\Builtin');
70
-
71
-		$backendService->registerBackend(new LegacyBackend($class, $definition, $auth));
72
-
73
-		return true;
74
-	}
75
-
76
-	/**
77
-	 * Returns the mount points for the given user.
78
-	 * The mount point is relative to the data directory.
79
-	 *
80
-	 * @param string $uid user
81
-	 * @return array of mount point string as key, mountpoint config as value
82
-	 *
83
-	 * @deprecated 8.2.0 use UserGlobalStoragesService::getStorages() and UserStoragesService::getStorages()
84
-	 */
85
-	public static function getAbsoluteMountPoints($uid) {
86
-		$mountPoints = array();
87
-
88
-		$userGlobalStoragesService = self::$app->getContainer()->query('OCA\Files_External\Service\UserGlobalStoragesService');
89
-		$userStoragesService = self::$app->getContainer()->query('OCA\Files_External\Service\UserStoragesService');
90
-		$user = self::$app->getContainer()->query('OCP\IUserManager')->get($uid);
91
-
92
-		$userGlobalStoragesService->setUser($user);
93
-		$userStoragesService->setUser($user);
94
-
95
-		foreach ($userGlobalStoragesService->getStorages() as $storage) {
96
-			/** @var \OCA\Files_External\Lib\StorageConfig $storage */
97
-			$mountPoint = '/'.$uid.'/files'.$storage->getMountPoint();
98
-			$mountEntry = self::prepareMountPointEntry($storage, false);
99
-			foreach ($mountEntry['options'] as &$option) {
100
-				$option = self::setUserVars($uid, $option);
101
-			}
102
-			$mountPoints[$mountPoint] = $mountEntry;
103
-		}
104
-
105
-		foreach ($userStoragesService->getStorages() as $storage) {
106
-			$mountPoint = '/'.$uid.'/files'.$storage->getMountPoint();
107
-			$mountEntry = self::prepareMountPointEntry($storage, true);
108
-			foreach ($mountEntry['options'] as &$option) {
109
-				$option = self::setUserVars($uid, $option);
110
-			}
111
-			$mountPoints[$mountPoint] = $mountEntry;
112
-		}
113
-
114
-		$userGlobalStoragesService->resetUser();
115
-		$userStoragesService->resetUser();
116
-
117
-		return $mountPoints;
118
-	}
119
-
120
-	/**
121
-	 * Get the system mount points
122
-	 *
123
-	 * @return array
124
-	 *
125
-	 * @deprecated 8.2.0 use GlobalStoragesService::getStorages()
126
-	 */
127
-	public static function getSystemMountPoints() {
128
-		$mountPoints = [];
129
-		$service = self::$app->getContainer()->query('OCA\Files_External\Service\GlobalStoragesService');
130
-
131
-		foreach ($service->getStorages() as $storage) {
132
-			$mountPoints[] = self::prepareMountPointEntry($storage, false);
133
-		}
134
-
135
-		return $mountPoints;
136
-	}
137
-
138
-	/**
139
-	 * Get the personal mount points of the current user
140
-	 *
141
-	 * @return array
142
-	 *
143
-	 * @deprecated 8.2.0 use UserStoragesService::getStorages()
144
-	 */
145
-	public static function getPersonalMountPoints() {
146
-		$mountPoints = [];
147
-		$service = self::$app->getContainer()->query('OCA\Files_External\Service\UserStoragesService');
148
-
149
-		foreach ($service->getStorages() as $storage) {
150
-			$mountPoints[] = self::prepareMountPointEntry($storage, true);
151
-		}
152
-
153
-		return $mountPoints;
154
-	}
155
-
156
-	/**
157
-	 * Convert a StorageConfig to the legacy mountPoints array format
158
-	 * There's a lot of extra information in here, to satisfy all of the legacy functions
159
-	 *
160
-	 * @param StorageConfig $storage
161
-	 * @param bool $isPersonal
162
-	 * @return array
163
-	 */
164
-	private static function prepareMountPointEntry(StorageConfig $storage, $isPersonal) {
165
-		$mountEntry = [];
166
-
167
-		$mountEntry['mountpoint'] = substr($storage->getMountPoint(), 1); // remove leading slash
168
-		$mountEntry['class'] = $storage->getBackend()->getIdentifier();
169
-		$mountEntry['backend'] = $storage->getBackend()->getText();
170
-		$mountEntry['authMechanism'] = $storage->getAuthMechanism()->getIdentifier();
171
-		$mountEntry['personal'] = $isPersonal;
172
-		$mountEntry['options'] = self::decryptPasswords($storage->getBackendOptions());
173
-		$mountEntry['mountOptions'] = $storage->getMountOptions();
174
-		$mountEntry['priority'] = $storage->getPriority();
175
-		$mountEntry['applicable'] = [
176
-			'groups' => $storage->getApplicableGroups(),
177
-			'users' => $storage->getApplicableUsers(),
178
-		];
179
-		// if mountpoint is applicable to all users the old API expects ['all']
180
-		if (empty($mountEntry['applicable']['groups']) && empty($mountEntry['applicable']['users'])) {
181
-			$mountEntry['applicable']['users'] = ['all'];
182
-		}
183
-
184
-		$mountEntry['id'] = $storage->getId();
185
-
186
-		return $mountEntry;
187
-	}
188
-
189
-	/**
190
-	 * fill in the correct values for $user
191
-	 *
192
-	 * @param string $user user value
193
-	 * @param string|array $input
194
-	 * @return string
195
-	 */
196
-	public static function setUserVars($user, $input) {
197
-		if (is_array($input)) {
198
-			foreach ($input as &$value) {
199
-				if (is_string($value)) {
200
-					$value = str_replace('$user', $user, $value);
201
-				}
202
-			}
203
-		} else {
204
-			if (is_string($input)) {
205
-				$input = str_replace('$user', $user, $input);
206
-			}
207
-		}
208
-		return $input;
209
-	}
210
-
211
-	/**
212
-	 * Test connecting using the given backend configuration
213
-	 *
214
-	 * @param string $class backend class name
215
-	 * @param array $options backend configuration options
216
-	 * @param boolean $isPersonal
217
-	 * @return int see self::STATUS_*
218
-	 * @throws Exception
219
-	 */
220
-	public static function getBackendStatus($class, $options, $isPersonal, $testOnly = true) {
221
-		if (self::$skipTest) {
222
-			return StorageNotAvailableException::STATUS_SUCCESS;
223
-		}
224
-		foreach ($options as &$option) {
225
-			$option = self::setUserVars(OCP\User::getUser(), $option);
226
-		}
227
-		if (class_exists($class)) {
228
-			try {
229
-				/** @var \OC\Files\Storage\Common $storage */
230
-				$storage = new $class($options);
231
-
232
-				try {
233
-					$result = $storage->test($isPersonal, $testOnly);
234
-					$storage->setAvailability($result);
235
-					if ($result) {
236
-						return StorageNotAvailableException::STATUS_SUCCESS;
237
-					}
238
-				} catch (\Exception $e) {
239
-					$storage->setAvailability(false);
240
-					throw $e;
241
-				}
242
-			} catch (Exception $exception) {
243
-				\OCP\Util::logException('files_external', $exception);
244
-				throw $exception;
245
-			}
246
-		}
247
-		return StorageNotAvailableException::STATUS_ERROR;
248
-	}
249
-
250
-	/**
251
-	 * Read the mount points in the config file into an array
252
-	 *
253
-	 * @param string|null $user If not null, personal for $user, otherwise system
254
-	 * @return array
255
-	 */
256
-	public static function readData($user = null) {
257
-		if (isset($user)) {
258
-			$jsonFile = \OC::$server->getUserManager()->get($user)->getHome() . '/mount.json';
259
-		} else {
260
-			$config = \OC::$server->getConfig();
261
-			$datadir = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/');
262
-			$jsonFile = $config->getSystemValue('mount_file', $datadir . '/mount.json');
263
-		}
264
-		if (is_file($jsonFile)) {
265
-			$mountPoints = json_decode(file_get_contents($jsonFile), true);
266
-			if (is_array($mountPoints)) {
267
-				return $mountPoints;
268
-			}
269
-		}
270
-		return array();
271
-	}
272
-
273
-	/**
274
-	 * Get backend dependency message
275
-	 * TODO: move into AppFramework along with templates
276
-	 *
277
-	 * @param Backend[] $backends
278
-	 * @return string
279
-	 */
280
-	public static function dependencyMessage($backends) {
281
-		$l = \OC::$server->getL10N('files_external');
282
-		$message = '';
283
-		$dependencyGroups = [];
284
-
285
-		foreach ($backends as $backend) {
286
-			foreach ($backend->checkDependencies() as $dependency) {
287
-				if ($message = $dependency->getMessage()) {
288
-					$message .= '<p>' . $message . '</p>';
289
-				} else {
290
-					$dependencyGroups[$dependency->getDependency()][] = $backend;
291
-				}
292
-			}
293
-		}
294
-
295
-		foreach ($dependencyGroups as $module => $dependants) {
296
-			$backends = implode(', ', array_map(function($backend) {
297
-				return '"' . $backend->getText() . '"';
298
-			}, $dependants));
299
-			$message .= '<p>' . OC_Mount_Config::getSingleDependencyMessage($l, $module, $backends) . '</p>';
300
-		}
301
-
302
-		return $message;
303
-	}
304
-
305
-	/**
306
-	 * Returns a dependency missing message
307
-	 *
308
-	 * @param \OCP\IL10N $l
309
-	 * @param string $module
310
-	 * @param string $backend
311
-	 * @return string
312
-	 */
313
-	private static function getSingleDependencyMessage(\OCP\IL10N $l, $module, $backend) {
314
-		switch (strtolower($module)) {
315
-			case 'curl':
316
-				return (string)$l->t('The cURL support in PHP is not enabled or installed. Mounting of %s is not possible. Please ask your system administrator to install it.', $backend);
317
-			case 'ftp':
318
-				return (string)$l->t('The FTP support in PHP is not enabled or installed. Mounting of %s is not possible. Please ask your system administrator to install it.', $backend);
319
-			default:
320
-				return (string)$l->t('"%s" is not installed. Mounting of %s is not possible. Please ask your system administrator to install it.', array($module, $backend));
321
-		}
322
-	}
323
-
324
-	/**
325
-	 * Encrypt passwords in the given config options
326
-	 *
327
-	 * @param array $options mount options
328
-	 * @return array updated options
329
-	 */
330
-	public static function encryptPasswords($options) {
331
-		if (isset($options['password'])) {
332
-			$options['password_encrypted'] = self::encryptPassword($options['password']);
333
-			// do not unset the password, we want to keep the keys order
334
-			// on load... because that's how the UI currently works
335
-			$options['password'] = '';
336
-		}
337
-		return $options;
338
-	}
339
-
340
-	/**
341
-	 * Decrypt passwords in the given config options
342
-	 *
343
-	 * @param array $options mount options
344
-	 * @return array updated options
345
-	 */
346
-	public static function decryptPasswords($options) {
347
-		// note: legacy options might still have the unencrypted password in the "password" field
348
-		if (isset($options['password_encrypted'])) {
349
-			$options['password'] = self::decryptPassword($options['password_encrypted']);
350
-			unset($options['password_encrypted']);
351
-		}
352
-		return $options;
353
-	}
354
-
355
-	/**
356
-	 * Encrypt a single password
357
-	 *
358
-	 * @param string $password plain text password
359
-	 * @return string encrypted password
360
-	 */
361
-	private static function encryptPassword($password) {
362
-		$cipher = self::getCipher();
363
-		$iv = \OCP\Util::generateRandomBytes(16);
364
-		$cipher->setIV($iv);
365
-		return base64_encode($iv . $cipher->encrypt($password));
366
-	}
367
-
368
-	/**
369
-	 * Decrypts a single password
370
-	 *
371
-	 * @param string $encryptedPassword encrypted password
372
-	 * @return string plain text password
373
-	 */
374
-	private static function decryptPassword($encryptedPassword) {
375
-		$cipher = self::getCipher();
376
-		$binaryPassword = base64_decode($encryptedPassword);
377
-		$iv = substr($binaryPassword, 0, 16);
378
-		$cipher->setIV($iv);
379
-		$binaryPassword = substr($binaryPassword, 16);
380
-		return $cipher->decrypt($binaryPassword);
381
-	}
382
-
383
-	/**
384
-	 * Returns the encryption cipher
385
-	 *
386
-	 * @return AES
387
-	 */
388
-	private static function getCipher() {
389
-		$cipher = new AES(AES::MODE_CBC);
390
-		$cipher->setKey(\OC::$server->getConfig()->getSystemValue('passwordsalt', null));
391
-		return $cipher;
392
-	}
393
-
394
-	/**
395
-	 * Computes a hash based on the given configuration.
396
-	 * This is mostly used to find out whether configurations
397
-	 * are the same.
398
-	 *
399
-	 * @param array $config
400
-	 * @return string
401
-	 */
402
-	public static function makeConfigHash($config) {
403
-		$data = json_encode(
404
-			array(
405
-				'c' => $config['backend'],
406
-				'a' => $config['authMechanism'],
407
-				'm' => $config['mountpoint'],
408
-				'o' => $config['options'],
409
-				'p' => isset($config['priority']) ? $config['priority'] : -1,
410
-				'mo' => isset($config['mountOptions']) ? $config['mountOptions'] : [],
411
-			)
412
-		);
413
-		return hash('md5', $data);
414
-	}
48
+    // TODO: make this class non-static and give it a proper namespace
49
+
50
+    const MOUNT_TYPE_GLOBAL = 'global';
51
+    const MOUNT_TYPE_GROUP = 'group';
52
+    const MOUNT_TYPE_USER = 'user';
53
+    const MOUNT_TYPE_PERSONAL = 'personal';
54
+
55
+    // whether to skip backend test (for unit tests, as this static class is not mockable)
56
+    public static $skipTest = false;
57
+
58
+    /** @var Application */
59
+    public static $app;
60
+
61
+    /**
62
+     * @param string $class
63
+     * @param array $definition
64
+     * @return bool
65
+     * @deprecated 8.2.0 use \OCA\Files_External\Service\BackendService::registerBackend()
66
+     */
67
+    public static function registerBackend($class, $definition) {
68
+        $backendService = self::$app->getContainer()->query('OCA\Files_External\Service\BackendService');
69
+        $auth = self::$app->getContainer()->query('OCA\Files_External\Lib\Auth\Builtin');
70
+
71
+        $backendService->registerBackend(new LegacyBackend($class, $definition, $auth));
72
+
73
+        return true;
74
+    }
75
+
76
+    /**
77
+     * Returns the mount points for the given user.
78
+     * The mount point is relative to the data directory.
79
+     *
80
+     * @param string $uid user
81
+     * @return array of mount point string as key, mountpoint config as value
82
+     *
83
+     * @deprecated 8.2.0 use UserGlobalStoragesService::getStorages() and UserStoragesService::getStorages()
84
+     */
85
+    public static function getAbsoluteMountPoints($uid) {
86
+        $mountPoints = array();
87
+
88
+        $userGlobalStoragesService = self::$app->getContainer()->query('OCA\Files_External\Service\UserGlobalStoragesService');
89
+        $userStoragesService = self::$app->getContainer()->query('OCA\Files_External\Service\UserStoragesService');
90
+        $user = self::$app->getContainer()->query('OCP\IUserManager')->get($uid);
91
+
92
+        $userGlobalStoragesService->setUser($user);
93
+        $userStoragesService->setUser($user);
94
+
95
+        foreach ($userGlobalStoragesService->getStorages() as $storage) {
96
+            /** @var \OCA\Files_External\Lib\StorageConfig $storage */
97
+            $mountPoint = '/'.$uid.'/files'.$storage->getMountPoint();
98
+            $mountEntry = self::prepareMountPointEntry($storage, false);
99
+            foreach ($mountEntry['options'] as &$option) {
100
+                $option = self::setUserVars($uid, $option);
101
+            }
102
+            $mountPoints[$mountPoint] = $mountEntry;
103
+        }
104
+
105
+        foreach ($userStoragesService->getStorages() as $storage) {
106
+            $mountPoint = '/'.$uid.'/files'.$storage->getMountPoint();
107
+            $mountEntry = self::prepareMountPointEntry($storage, true);
108
+            foreach ($mountEntry['options'] as &$option) {
109
+                $option = self::setUserVars($uid, $option);
110
+            }
111
+            $mountPoints[$mountPoint] = $mountEntry;
112
+        }
113
+
114
+        $userGlobalStoragesService->resetUser();
115
+        $userStoragesService->resetUser();
116
+
117
+        return $mountPoints;
118
+    }
119
+
120
+    /**
121
+     * Get the system mount points
122
+     *
123
+     * @return array
124
+     *
125
+     * @deprecated 8.2.0 use GlobalStoragesService::getStorages()
126
+     */
127
+    public static function getSystemMountPoints() {
128
+        $mountPoints = [];
129
+        $service = self::$app->getContainer()->query('OCA\Files_External\Service\GlobalStoragesService');
130
+
131
+        foreach ($service->getStorages() as $storage) {
132
+            $mountPoints[] = self::prepareMountPointEntry($storage, false);
133
+        }
134
+
135
+        return $mountPoints;
136
+    }
137
+
138
+    /**
139
+     * Get the personal mount points of the current user
140
+     *
141
+     * @return array
142
+     *
143
+     * @deprecated 8.2.0 use UserStoragesService::getStorages()
144
+     */
145
+    public static function getPersonalMountPoints() {
146
+        $mountPoints = [];
147
+        $service = self::$app->getContainer()->query('OCA\Files_External\Service\UserStoragesService');
148
+
149
+        foreach ($service->getStorages() as $storage) {
150
+            $mountPoints[] = self::prepareMountPointEntry($storage, true);
151
+        }
152
+
153
+        return $mountPoints;
154
+    }
155
+
156
+    /**
157
+     * Convert a StorageConfig to the legacy mountPoints array format
158
+     * There's a lot of extra information in here, to satisfy all of the legacy functions
159
+     *
160
+     * @param StorageConfig $storage
161
+     * @param bool $isPersonal
162
+     * @return array
163
+     */
164
+    private static function prepareMountPointEntry(StorageConfig $storage, $isPersonal) {
165
+        $mountEntry = [];
166
+
167
+        $mountEntry['mountpoint'] = substr($storage->getMountPoint(), 1); // remove leading slash
168
+        $mountEntry['class'] = $storage->getBackend()->getIdentifier();
169
+        $mountEntry['backend'] = $storage->getBackend()->getText();
170
+        $mountEntry['authMechanism'] = $storage->getAuthMechanism()->getIdentifier();
171
+        $mountEntry['personal'] = $isPersonal;
172
+        $mountEntry['options'] = self::decryptPasswords($storage->getBackendOptions());
173
+        $mountEntry['mountOptions'] = $storage->getMountOptions();
174
+        $mountEntry['priority'] = $storage->getPriority();
175
+        $mountEntry['applicable'] = [
176
+            'groups' => $storage->getApplicableGroups(),
177
+            'users' => $storage->getApplicableUsers(),
178
+        ];
179
+        // if mountpoint is applicable to all users the old API expects ['all']
180
+        if (empty($mountEntry['applicable']['groups']) && empty($mountEntry['applicable']['users'])) {
181
+            $mountEntry['applicable']['users'] = ['all'];
182
+        }
183
+
184
+        $mountEntry['id'] = $storage->getId();
185
+
186
+        return $mountEntry;
187
+    }
188
+
189
+    /**
190
+     * fill in the correct values for $user
191
+     *
192
+     * @param string $user user value
193
+     * @param string|array $input
194
+     * @return string
195
+     */
196
+    public static function setUserVars($user, $input) {
197
+        if (is_array($input)) {
198
+            foreach ($input as &$value) {
199
+                if (is_string($value)) {
200
+                    $value = str_replace('$user', $user, $value);
201
+                }
202
+            }
203
+        } else {
204
+            if (is_string($input)) {
205
+                $input = str_replace('$user', $user, $input);
206
+            }
207
+        }
208
+        return $input;
209
+    }
210
+
211
+    /**
212
+     * Test connecting using the given backend configuration
213
+     *
214
+     * @param string $class backend class name
215
+     * @param array $options backend configuration options
216
+     * @param boolean $isPersonal
217
+     * @return int see self::STATUS_*
218
+     * @throws Exception
219
+     */
220
+    public static function getBackendStatus($class, $options, $isPersonal, $testOnly = true) {
221
+        if (self::$skipTest) {
222
+            return StorageNotAvailableException::STATUS_SUCCESS;
223
+        }
224
+        foreach ($options as &$option) {
225
+            $option = self::setUserVars(OCP\User::getUser(), $option);
226
+        }
227
+        if (class_exists($class)) {
228
+            try {
229
+                /** @var \OC\Files\Storage\Common $storage */
230
+                $storage = new $class($options);
231
+
232
+                try {
233
+                    $result = $storage->test($isPersonal, $testOnly);
234
+                    $storage->setAvailability($result);
235
+                    if ($result) {
236
+                        return StorageNotAvailableException::STATUS_SUCCESS;
237
+                    }
238
+                } catch (\Exception $e) {
239
+                    $storage->setAvailability(false);
240
+                    throw $e;
241
+                }
242
+            } catch (Exception $exception) {
243
+                \OCP\Util::logException('files_external', $exception);
244
+                throw $exception;
245
+            }
246
+        }
247
+        return StorageNotAvailableException::STATUS_ERROR;
248
+    }
249
+
250
+    /**
251
+     * Read the mount points in the config file into an array
252
+     *
253
+     * @param string|null $user If not null, personal for $user, otherwise system
254
+     * @return array
255
+     */
256
+    public static function readData($user = null) {
257
+        if (isset($user)) {
258
+            $jsonFile = \OC::$server->getUserManager()->get($user)->getHome() . '/mount.json';
259
+        } else {
260
+            $config = \OC::$server->getConfig();
261
+            $datadir = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/');
262
+            $jsonFile = $config->getSystemValue('mount_file', $datadir . '/mount.json');
263
+        }
264
+        if (is_file($jsonFile)) {
265
+            $mountPoints = json_decode(file_get_contents($jsonFile), true);
266
+            if (is_array($mountPoints)) {
267
+                return $mountPoints;
268
+            }
269
+        }
270
+        return array();
271
+    }
272
+
273
+    /**
274
+     * Get backend dependency message
275
+     * TODO: move into AppFramework along with templates
276
+     *
277
+     * @param Backend[] $backends
278
+     * @return string
279
+     */
280
+    public static function dependencyMessage($backends) {
281
+        $l = \OC::$server->getL10N('files_external');
282
+        $message = '';
283
+        $dependencyGroups = [];
284
+
285
+        foreach ($backends as $backend) {
286
+            foreach ($backend->checkDependencies() as $dependency) {
287
+                if ($message = $dependency->getMessage()) {
288
+                    $message .= '<p>' . $message . '</p>';
289
+                } else {
290
+                    $dependencyGroups[$dependency->getDependency()][] = $backend;
291
+                }
292
+            }
293
+        }
294
+
295
+        foreach ($dependencyGroups as $module => $dependants) {
296
+            $backends = implode(', ', array_map(function($backend) {
297
+                return '"' . $backend->getText() . '"';
298
+            }, $dependants));
299
+            $message .= '<p>' . OC_Mount_Config::getSingleDependencyMessage($l, $module, $backends) . '</p>';
300
+        }
301
+
302
+        return $message;
303
+    }
304
+
305
+    /**
306
+     * Returns a dependency missing message
307
+     *
308
+     * @param \OCP\IL10N $l
309
+     * @param string $module
310
+     * @param string $backend
311
+     * @return string
312
+     */
313
+    private static function getSingleDependencyMessage(\OCP\IL10N $l, $module, $backend) {
314
+        switch (strtolower($module)) {
315
+            case 'curl':
316
+                return (string)$l->t('The cURL support in PHP is not enabled or installed. Mounting of %s is not possible. Please ask your system administrator to install it.', $backend);
317
+            case 'ftp':
318
+                return (string)$l->t('The FTP support in PHP is not enabled or installed. Mounting of %s is not possible. Please ask your system administrator to install it.', $backend);
319
+            default:
320
+                return (string)$l->t('"%s" is not installed. Mounting of %s is not possible. Please ask your system administrator to install it.', array($module, $backend));
321
+        }
322
+    }
323
+
324
+    /**
325
+     * Encrypt passwords in the given config options
326
+     *
327
+     * @param array $options mount options
328
+     * @return array updated options
329
+     */
330
+    public static function encryptPasswords($options) {
331
+        if (isset($options['password'])) {
332
+            $options['password_encrypted'] = self::encryptPassword($options['password']);
333
+            // do not unset the password, we want to keep the keys order
334
+            // on load... because that's how the UI currently works
335
+            $options['password'] = '';
336
+        }
337
+        return $options;
338
+    }
339
+
340
+    /**
341
+     * Decrypt passwords in the given config options
342
+     *
343
+     * @param array $options mount options
344
+     * @return array updated options
345
+     */
346
+    public static function decryptPasswords($options) {
347
+        // note: legacy options might still have the unencrypted password in the "password" field
348
+        if (isset($options['password_encrypted'])) {
349
+            $options['password'] = self::decryptPassword($options['password_encrypted']);
350
+            unset($options['password_encrypted']);
351
+        }
352
+        return $options;
353
+    }
354
+
355
+    /**
356
+     * Encrypt a single password
357
+     *
358
+     * @param string $password plain text password
359
+     * @return string encrypted password
360
+     */
361
+    private static function encryptPassword($password) {
362
+        $cipher = self::getCipher();
363
+        $iv = \OCP\Util::generateRandomBytes(16);
364
+        $cipher->setIV($iv);
365
+        return base64_encode($iv . $cipher->encrypt($password));
366
+    }
367
+
368
+    /**
369
+     * Decrypts a single password
370
+     *
371
+     * @param string $encryptedPassword encrypted password
372
+     * @return string plain text password
373
+     */
374
+    private static function decryptPassword($encryptedPassword) {
375
+        $cipher = self::getCipher();
376
+        $binaryPassword = base64_decode($encryptedPassword);
377
+        $iv = substr($binaryPassword, 0, 16);
378
+        $cipher->setIV($iv);
379
+        $binaryPassword = substr($binaryPassword, 16);
380
+        return $cipher->decrypt($binaryPassword);
381
+    }
382
+
383
+    /**
384
+     * Returns the encryption cipher
385
+     *
386
+     * @return AES
387
+     */
388
+    private static function getCipher() {
389
+        $cipher = new AES(AES::MODE_CBC);
390
+        $cipher->setKey(\OC::$server->getConfig()->getSystemValue('passwordsalt', null));
391
+        return $cipher;
392
+    }
393
+
394
+    /**
395
+     * Computes a hash based on the given configuration.
396
+     * This is mostly used to find out whether configurations
397
+     * are the same.
398
+     *
399
+     * @param array $config
400
+     * @return string
401
+     */
402
+    public static function makeConfigHash($config) {
403
+        $data = json_encode(
404
+            array(
405
+                'c' => $config['backend'],
406
+                'a' => $config['authMechanism'],
407
+                'm' => $config['mountpoint'],
408
+                'o' => $config['options'],
409
+                'p' => isset($config['priority']) ? $config['priority'] : -1,
410
+                'mo' => isset($config['mountOptions']) ? $config['mountOptions'] : [],
411
+            )
412
+        );
413
+        return hash('md5', $data);
414
+    }
415 415
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Migration/DummyUserSession.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -28,26 +28,26 @@
 block discarded – undo
28 28
 
29 29
 class DummyUserSession implements IUserSession {
30 30
 
31
-	/**
32
-	 * @var IUser
33
-	 */
34
-	private $user;
31
+    /**
32
+     * @var IUser
33
+     */
34
+    private $user;
35 35
 
36
-	public function login($user, $password) {
37
-	}
36
+    public function login($user, $password) {
37
+    }
38 38
 
39
-	public function logout() {
40
-	}
39
+    public function logout() {
40
+    }
41 41
 
42
-	public function setUser($user) {
43
-		$this->user = $user;
44
-	}
42
+    public function setUser($user) {
43
+        $this->user = $user;
44
+    }
45 45
 
46
-	public function getUser() {
47
-		return $this->user;
48
-	}
46
+    public function getUser() {
47
+        return $this->user;
48
+    }
49 49
 
50
-	public function isLoggedIn() {
51
-		return !is_null($this->user);
52
-	}
50
+    public function isLoggedIn() {
51
+        return !is_null($this->user);
52
+    }
53 53
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Command/Export.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -30,30 +30,30 @@
 block discarded – undo
30 30
 
31 31
 class Export extends ListCommand {
32 32
 
33
-	protected function configure() {
34
-		$this
35
-			->setName('files_external:export')
36
-			->setDescription('Export mount configurations')
37
-			->addArgument(
38
-				'user_id',
39
-				InputArgument::OPTIONAL,
40
-				'user id to export the personal mounts for, if no user is provided admin mounts will be exported'
41
-			)->addOption(
42
-				'all',
43
-				'a',
44
-				InputOption::VALUE_NONE,
45
-				'show both system wide mounts and all personal mounts'
46
-			);
47
-	}
33
+    protected function configure() {
34
+        $this
35
+            ->setName('files_external:export')
36
+            ->setDescription('Export mount configurations')
37
+            ->addArgument(
38
+                'user_id',
39
+                InputArgument::OPTIONAL,
40
+                'user id to export the personal mounts for, if no user is provided admin mounts will be exported'
41
+            )->addOption(
42
+                'all',
43
+                'a',
44
+                InputOption::VALUE_NONE,
45
+                'show both system wide mounts and all personal mounts'
46
+            );
47
+    }
48 48
 
49
-	protected function execute(InputInterface $input, OutputInterface $output) {
50
-		$listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager);
51
-		$listInput = new ArrayInput([], $listCommand->getDefinition());
52
-		$listInput->setArgument('user_id', $input->getArgument('user_id'));
53
-		$listInput->setOption('all', $input->getOption('all'));
54
-		$listInput->setOption('output', 'json_pretty');
55
-		$listInput->setOption('show-password', true);
56
-		$listInput->setOption('full', true);
57
-		$listCommand->execute($listInput, $output);
58
-	}
49
+    protected function execute(InputInterface $input, OutputInterface $output) {
50
+        $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager);
51
+        $listInput = new ArrayInput([], $listCommand->getDefinition());
52
+        $listInput->setArgument('user_id', $input->getArgument('user_id'));
53
+        $listInput->setOption('all', $input->getOption('all'));
54
+        $listInput->setOption('output', 'json_pretty');
55
+        $listInput->setOption('show-password', true);
56
+        $listInput->setOption('full', true);
57
+        $listCommand->execute($listInput, $output);
58
+    }
59 59
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Command/Applicable.php 1 patch
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -35,122 +35,122 @@
 block discarded – undo
35 35
 use Symfony\Component\Console\Output\OutputInterface;
36 36
 
37 37
 class Applicable extends Base {
38
-	/**
39
-	 * @var GlobalStoragesService
40
-	 */
41
-	protected $globalService;
38
+    /**
39
+     * @var GlobalStoragesService
40
+     */
41
+    protected $globalService;
42 42
 
43
-	/**
44
-	 * @var IUserManager
45
-	 */
46
-	private $userManager;
43
+    /**
44
+     * @var IUserManager
45
+     */
46
+    private $userManager;
47 47
 
48
-	/**
49
-	 * @var IGroupManager
50
-	 */
51
-	private $groupManager;
48
+    /**
49
+     * @var IGroupManager
50
+     */
51
+    private $groupManager;
52 52
 
53
-	function __construct(
54
-		GlobalStoragesService $globalService,
55
-		IUserManager $userManager,
56
-		IGroupManager $groupManager
57
-	) {
58
-		parent::__construct();
59
-		$this->globalService = $globalService;
60
-		$this->userManager = $userManager;
61
-		$this->groupManager = $groupManager;
62
-	}
53
+    function __construct(
54
+        GlobalStoragesService $globalService,
55
+        IUserManager $userManager,
56
+        IGroupManager $groupManager
57
+    ) {
58
+        parent::__construct();
59
+        $this->globalService = $globalService;
60
+        $this->userManager = $userManager;
61
+        $this->groupManager = $groupManager;
62
+    }
63 63
 
64
-	protected function configure() {
65
-		$this
66
-			->setName('files_external:applicable')
67
-			->setDescription('Manage applicable users and groups for a mount')
68
-			->addArgument(
69
-				'mount_id',
70
-				InputArgument::REQUIRED,
71
-				'The id of the mount to edit'
72
-			)->addOption(
73
-				'add-user',
74
-				null,
75
-				InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
76
-				'user to add as applicable'
77
-			)->addOption(
78
-				'remove-user',
79
-				null,
80
-				InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
81
-				'user to remove as applicable'
82
-			)->addOption(
83
-				'add-group',
84
-				null,
85
-				InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
86
-				'group to add as applicable'
87
-			)->addOption(
88
-				'remove-group',
89
-				null,
90
-				InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
91
-				'group to remove as applicable'
92
-			)->addOption(
93
-				'remove-all',
94
-				null,
95
-				InputOption::VALUE_NONE,
96
-				'Set the mount to be globally applicable'
97
-			);
98
-		parent::configure();
99
-	}
64
+    protected function configure() {
65
+        $this
66
+            ->setName('files_external:applicable')
67
+            ->setDescription('Manage applicable users and groups for a mount')
68
+            ->addArgument(
69
+                'mount_id',
70
+                InputArgument::REQUIRED,
71
+                'The id of the mount to edit'
72
+            )->addOption(
73
+                'add-user',
74
+                null,
75
+                InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
76
+                'user to add as applicable'
77
+            )->addOption(
78
+                'remove-user',
79
+                null,
80
+                InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
81
+                'user to remove as applicable'
82
+            )->addOption(
83
+                'add-group',
84
+                null,
85
+                InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
86
+                'group to add as applicable'
87
+            )->addOption(
88
+                'remove-group',
89
+                null,
90
+                InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
91
+                'group to remove as applicable'
92
+            )->addOption(
93
+                'remove-all',
94
+                null,
95
+                InputOption::VALUE_NONE,
96
+                'Set the mount to be globally applicable'
97
+            );
98
+        parent::configure();
99
+    }
100 100
 
101
-	protected function execute(InputInterface $input, OutputInterface $output) {
102
-		$mountId = $input->getArgument('mount_id');
103
-		try {
104
-			$mount = $this->globalService->getStorage($mountId);
105
-		} catch (NotFoundException $e) {
106
-			$output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts</error>');
107
-			return 404;
108
-		}
101
+    protected function execute(InputInterface $input, OutputInterface $output) {
102
+        $mountId = $input->getArgument('mount_id');
103
+        try {
104
+            $mount = $this->globalService->getStorage($mountId);
105
+        } catch (NotFoundException $e) {
106
+            $output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts</error>');
107
+            return 404;
108
+        }
109 109
 
110
-		if ($mount->getType() === StorageConfig::MOUNT_TYPE_PERSONAl) {
111
-			$output->writeln('<error>Can\'t change applicables on personal mounts</error>');
112
-			return 1;
113
-		}
110
+        if ($mount->getType() === StorageConfig::MOUNT_TYPE_PERSONAl) {
111
+            $output->writeln('<error>Can\'t change applicables on personal mounts</error>');
112
+            return 1;
113
+        }
114 114
 
115
-		$addUsers = $input->getOption('add-user');
116
-		$removeUsers = $input->getOption('remove-user');
117
-		$addGroups = $input->getOption('add-group');
118
-		$removeGroups = $input->getOption('remove-group');
115
+        $addUsers = $input->getOption('add-user');
116
+        $removeUsers = $input->getOption('remove-user');
117
+        $addGroups = $input->getOption('add-group');
118
+        $removeGroups = $input->getOption('remove-group');
119 119
 
120
-		$applicableUsers = $mount->getApplicableUsers();
121
-		$applicableGroups = $mount->getApplicableGroups();
120
+        $applicableUsers = $mount->getApplicableUsers();
121
+        $applicableGroups = $mount->getApplicableGroups();
122 122
 
123
-		if ((count($addUsers) + count($removeUsers) + count($addGroups) + count($removeGroups) > 0) || $input->getOption('remove-all')) {
124
-			foreach ($addUsers as $addUser) {
125
-				if (!$this->userManager->userExists($addUser)) {
126
-					$output->writeln('<error>User "' . $addUser . '" not found</error>');
127
-					return 404;
128
-				}
129
-			}
130
-			foreach ($addGroups as $addGroup) {
131
-				if (!$this->groupManager->groupExists($addGroup)) {
132
-					$output->writeln('<error>Group "' . $addGroup . '" not found</error>');
133
-					return 404;
134
-				}
135
-			}
123
+        if ((count($addUsers) + count($removeUsers) + count($addGroups) + count($removeGroups) > 0) || $input->getOption('remove-all')) {
124
+            foreach ($addUsers as $addUser) {
125
+                if (!$this->userManager->userExists($addUser)) {
126
+                    $output->writeln('<error>User "' . $addUser . '" not found</error>');
127
+                    return 404;
128
+                }
129
+            }
130
+            foreach ($addGroups as $addGroup) {
131
+                if (!$this->groupManager->groupExists($addGroup)) {
132
+                    $output->writeln('<error>Group "' . $addGroup . '" not found</error>');
133
+                    return 404;
134
+                }
135
+            }
136 136
 
137
-			if ($input->getOption('remove-all')) {
138
-				$applicableUsers = [];
139
-				$applicableGroups = [];
140
-			} else {
141
-				$applicableUsers = array_unique(array_merge($applicableUsers, $addUsers));
142
-				$applicableUsers = array_values(array_diff($applicableUsers, $removeUsers));
143
-				$applicableGroups = array_unique(array_merge($applicableGroups, $addGroups));
144
-				$applicableGroups = array_values(array_diff($applicableGroups, $removeGroups));
145
-			}
146
-			$mount->setApplicableUsers($applicableUsers);
147
-			$mount->setApplicableGroups($applicableGroups);
148
-			$this->globalService->updateStorage($mount);
149
-		}
137
+            if ($input->getOption('remove-all')) {
138
+                $applicableUsers = [];
139
+                $applicableGroups = [];
140
+            } else {
141
+                $applicableUsers = array_unique(array_merge($applicableUsers, $addUsers));
142
+                $applicableUsers = array_values(array_diff($applicableUsers, $removeUsers));
143
+                $applicableGroups = array_unique(array_merge($applicableGroups, $addGroups));
144
+                $applicableGroups = array_values(array_diff($applicableGroups, $removeGroups));
145
+            }
146
+            $mount->setApplicableUsers($applicableUsers);
147
+            $mount->setApplicableGroups($applicableGroups);
148
+            $this->globalService->updateStorage($mount);
149
+        }
150 150
 
151
-		$this->writeArrayInOutputFormat($input, $output, [
152
-			'users' => $applicableUsers,
153
-			'groups' => $applicableGroups
154
-		]);
155
-	}
151
+        $this->writeArrayInOutputFormat($input, $output, [
152
+            'users' => $applicableUsers,
153
+            'groups' => $applicableGroups
154
+        ]);
155
+    }
156 156
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Command/ListCommand.php 1 patch
Indentation   +210 added lines, -210 removed lines patch added patch discarded remove patch
@@ -37,239 +37,239 @@
 block discarded – undo
37 37
 use Symfony\Component\Console\Output\OutputInterface;
38 38
 
39 39
 class ListCommand extends Base {
40
-	/**
41
-	 * @var GlobalStoragesService
42
-	 */
43
-	protected $globalService;
40
+    /**
41
+     * @var GlobalStoragesService
42
+     */
43
+    protected $globalService;
44 44
 
45
-	/**
46
-	 * @var UserStoragesService
47
-	 */
48
-	protected $userService;
45
+    /**
46
+     * @var UserStoragesService
47
+     */
48
+    protected $userService;
49 49
 
50
-	/**
51
-	 * @var IUserSession
52
-	 */
53
-	protected $userSession;
50
+    /**
51
+     * @var IUserSession
52
+     */
53
+    protected $userSession;
54 54
 
55
-	/**
56
-	 * @var IUserManager
57
-	 */
58
-	protected $userManager;
55
+    /**
56
+     * @var IUserManager
57
+     */
58
+    protected $userManager;
59 59
 
60
-	const ALL = -1;
60
+    const ALL = -1;
61 61
 
62
-	function __construct(GlobalStoragesService $globalService, UserStoragesService $userService, IUserSession $userSession, IUserManager $userManager) {
63
-		parent::__construct();
64
-		$this->globalService = $globalService;
65
-		$this->userService = $userService;
66
-		$this->userSession = $userSession;
67
-		$this->userManager = $userManager;
68
-	}
62
+    function __construct(GlobalStoragesService $globalService, UserStoragesService $userService, IUserSession $userSession, IUserManager $userManager) {
63
+        parent::__construct();
64
+        $this->globalService = $globalService;
65
+        $this->userService = $userService;
66
+        $this->userSession = $userSession;
67
+        $this->userManager = $userManager;
68
+    }
69 69
 
70
-	protected function configure() {
71
-		$this
72
-			->setName('files_external:list')
73
-			->setDescription('List configured admin or personal mounts')
74
-			->addArgument(
75
-				'user_id',
76
-				InputArgument::OPTIONAL,
77
-				'user id to list the personal mounts for, if no user is provided admin mounts will be listed'
78
-			)->addOption(
79
-				'show-password',
80
-				null,
81
-				InputOption::VALUE_NONE,
82
-				'show passwords and secrets'
83
-			)->addOption(
84
-				'full',
85
-				null,
86
-				InputOption::VALUE_NONE,
87
-				'don\'t truncate long values in table output'
88
-			)->addOption(
89
-				'all',
90
-				'a',
91
-				InputOption::VALUE_NONE,
92
-				'show both system wide mounts and all personal mounts'
93
-			);
94
-		parent::configure();
95
-	}
70
+    protected function configure() {
71
+        $this
72
+            ->setName('files_external:list')
73
+            ->setDescription('List configured admin or personal mounts')
74
+            ->addArgument(
75
+                'user_id',
76
+                InputArgument::OPTIONAL,
77
+                'user id to list the personal mounts for, if no user is provided admin mounts will be listed'
78
+            )->addOption(
79
+                'show-password',
80
+                null,
81
+                InputOption::VALUE_NONE,
82
+                'show passwords and secrets'
83
+            )->addOption(
84
+                'full',
85
+                null,
86
+                InputOption::VALUE_NONE,
87
+                'don\'t truncate long values in table output'
88
+            )->addOption(
89
+                'all',
90
+                'a',
91
+                InputOption::VALUE_NONE,
92
+                'show both system wide mounts and all personal mounts'
93
+            );
94
+        parent::configure();
95
+    }
96 96
 
97
-	protected function execute(InputInterface $input, OutputInterface $output) {
98
-		if ($input->getOption('all')) {
99
-			/** @var  $mounts StorageConfig[] */
100
-			$mounts = $this->globalService->getStorageForAllUsers();
101
-			$userId = self::ALL;
102
-		} else {
103
-			$userId = $input->getArgument('user_id');
104
-			$storageService = $this->getStorageService($userId);
97
+    protected function execute(InputInterface $input, OutputInterface $output) {
98
+        if ($input->getOption('all')) {
99
+            /** @var  $mounts StorageConfig[] */
100
+            $mounts = $this->globalService->getStorageForAllUsers();
101
+            $userId = self::ALL;
102
+        } else {
103
+            $userId = $input->getArgument('user_id');
104
+            $storageService = $this->getStorageService($userId);
105 105
 
106
-			/** @var  $mounts StorageConfig[] */
107
-			$mounts = $storageService->getAllStorages();
108
-		}
106
+            /** @var  $mounts StorageConfig[] */
107
+            $mounts = $storageService->getAllStorages();
108
+        }
109 109
 
110
-		$this->listMounts($userId, $mounts, $input, $output);
111
-	}
110
+        $this->listMounts($userId, $mounts, $input, $output);
111
+    }
112 112
 
113
-	/**
114
-	 * @param $userId $userId
115
-	 * @param StorageConfig[] $mounts
116
-	 * @param InputInterface $input
117
-	 * @param OutputInterface $output
118
-	 */
119
-	public function listMounts($userId, array $mounts, InputInterface $input, OutputInterface $output) {
120
-		$outputType = $input->getOption('output');
121
-		if (count($mounts) === 0) {
122
-			if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) {
123
-				$output->writeln('[]');
124
-			} else {
125
-				if ($userId === self::ALL) {
126
-					$output->writeln("<info>No mounts configured</info>");
127
-				} else if ($userId) {
128
-					$output->writeln("<info>No mounts configured by $userId</info>");
129
-				} else {
130
-					$output->writeln("<info>No admin mounts configured</info>");
131
-				}
132
-			}
133
-			return;
134
-		}
113
+    /**
114
+     * @param $userId $userId
115
+     * @param StorageConfig[] $mounts
116
+     * @param InputInterface $input
117
+     * @param OutputInterface $output
118
+     */
119
+    public function listMounts($userId, array $mounts, InputInterface $input, OutputInterface $output) {
120
+        $outputType = $input->getOption('output');
121
+        if (count($mounts) === 0) {
122
+            if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) {
123
+                $output->writeln('[]');
124
+            } else {
125
+                if ($userId === self::ALL) {
126
+                    $output->writeln("<info>No mounts configured</info>");
127
+                } else if ($userId) {
128
+                    $output->writeln("<info>No mounts configured by $userId</info>");
129
+                } else {
130
+                    $output->writeln("<info>No admin mounts configured</info>");
131
+                }
132
+            }
133
+            return;
134
+        }
135 135
 
136
-		$headers = ['Mount ID', 'Mount Point', 'Storage', 'Authentication Type', 'Configuration', 'Options'];
136
+        $headers = ['Mount ID', 'Mount Point', 'Storage', 'Authentication Type', 'Configuration', 'Options'];
137 137
 
138
-		if (!$userId || $userId === self::ALL) {
139
-			$headers[] = 'Applicable Users';
140
-			$headers[] = 'Applicable Groups';
141
-		}
142
-		if ($userId === self::ALL) {
143
-			$headers[] = 'Type';
144
-		}
138
+        if (!$userId || $userId === self::ALL) {
139
+            $headers[] = 'Applicable Users';
140
+            $headers[] = 'Applicable Groups';
141
+        }
142
+        if ($userId === self::ALL) {
143
+            $headers[] = 'Type';
144
+        }
145 145
 
146
-		if (!$input->getOption('show-password')) {
147
-			$hideKeys = ['password', 'refresh_token', 'token', 'client_secret', 'public_key', 'private_key'];
148
-			foreach ($mounts as $mount) {
149
-				$config = $mount->getBackendOptions();
150
-				foreach ($config as $key => $value) {
151
-					if (in_array($key, $hideKeys)) {
152
-						$mount->setBackendOption($key, '***');
153
-					}
154
-				}
155
-			}
156
-		}
146
+        if (!$input->getOption('show-password')) {
147
+            $hideKeys = ['password', 'refresh_token', 'token', 'client_secret', 'public_key', 'private_key'];
148
+            foreach ($mounts as $mount) {
149
+                $config = $mount->getBackendOptions();
150
+                foreach ($config as $key => $value) {
151
+                    if (in_array($key, $hideKeys)) {
152
+                        $mount->setBackendOption($key, '***');
153
+                    }
154
+                }
155
+            }
156
+        }
157 157
 
158
-		if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) {
159
-			$keys = array_map(function ($header) {
160
-				return strtolower(str_replace(' ', '_', $header));
161
-			}, $headers);
158
+        if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) {
159
+            $keys = array_map(function ($header) {
160
+                return strtolower(str_replace(' ', '_', $header));
161
+            }, $headers);
162 162
 
163
-			$pairs = array_map(function (StorageConfig $config) use ($keys, $userId) {
164
-				$values = [
165
-					$config->getId(),
166
-					$config->getMountPoint(),
167
-					$config->getBackend()->getStorageClass(),
168
-					$config->getAuthMechanism()->getIdentifier(),
169
-					$config->getBackendOptions(),
170
-					$config->getMountOptions()
171
-				];
172
-				if (!$userId || $userId === self::ALL) {
173
-					$values[] = $config->getApplicableUsers();
174
-					$values[] = $config->getApplicableGroups();
175
-				}
176
-				if ($userId === self::ALL) {
177
-					$values[] = $config->getType() === StorageConfig::MOUNT_TYPE_ADMIN ? 'admin' : 'personal';
178
-				}
163
+            $pairs = array_map(function (StorageConfig $config) use ($keys, $userId) {
164
+                $values = [
165
+                    $config->getId(),
166
+                    $config->getMountPoint(),
167
+                    $config->getBackend()->getStorageClass(),
168
+                    $config->getAuthMechanism()->getIdentifier(),
169
+                    $config->getBackendOptions(),
170
+                    $config->getMountOptions()
171
+                ];
172
+                if (!$userId || $userId === self::ALL) {
173
+                    $values[] = $config->getApplicableUsers();
174
+                    $values[] = $config->getApplicableGroups();
175
+                }
176
+                if ($userId === self::ALL) {
177
+                    $values[] = $config->getType() === StorageConfig::MOUNT_TYPE_ADMIN ? 'admin' : 'personal';
178
+                }
179 179
 
180
-				return array_combine($keys, $values);
181
-			}, $mounts);
182
-			if ($outputType === self::OUTPUT_FORMAT_JSON) {
183
-				$output->writeln(json_encode(array_values($pairs)));
184
-			} else {
185
-				$output->writeln(json_encode(array_values($pairs), JSON_PRETTY_PRINT));
186
-			}
187
-		} else {
188
-			$full = $input->getOption('full');
189
-			$defaultMountOptions = [
190
-				'encrypt' => true,
191
-				'previews' => true,
192
-				'filesystem_check_changes' => 1,
193
-				'enable_sharing' => false,
194
-				'encoding_compatibility' => false
195
-			];
196
-			$rows = array_map(function (StorageConfig $config) use ($userId, $defaultMountOptions, $full) {
197
-				$storageConfig = $config->getBackendOptions();
198
-				$keys = array_keys($storageConfig);
199
-				$values = array_values($storageConfig);
180
+                return array_combine($keys, $values);
181
+            }, $mounts);
182
+            if ($outputType === self::OUTPUT_FORMAT_JSON) {
183
+                $output->writeln(json_encode(array_values($pairs)));
184
+            } else {
185
+                $output->writeln(json_encode(array_values($pairs), JSON_PRETTY_PRINT));
186
+            }
187
+        } else {
188
+            $full = $input->getOption('full');
189
+            $defaultMountOptions = [
190
+                'encrypt' => true,
191
+                'previews' => true,
192
+                'filesystem_check_changes' => 1,
193
+                'enable_sharing' => false,
194
+                'encoding_compatibility' => false
195
+            ];
196
+            $rows = array_map(function (StorageConfig $config) use ($userId, $defaultMountOptions, $full) {
197
+                $storageConfig = $config->getBackendOptions();
198
+                $keys = array_keys($storageConfig);
199
+                $values = array_values($storageConfig);
200 200
 
201
-				if (!$full) {
202
-					$values = array_map(function ($value) {
203
-						if (is_string($value) && strlen($value) > 32) {
204
-							return substr($value, 0, 6) . '...' . substr($value, -6, 6);
205
-						} else {
206
-							return $value;
207
-						}
208
-					}, $values);
209
-				}
201
+                if (!$full) {
202
+                    $values = array_map(function ($value) {
203
+                        if (is_string($value) && strlen($value) > 32) {
204
+                            return substr($value, 0, 6) . '...' . substr($value, -6, 6);
205
+                        } else {
206
+                            return $value;
207
+                        }
208
+                    }, $values);
209
+                }
210 210
 
211
-				$configStrings = array_map(function ($key, $value) {
212
-					return $key . ': ' . json_encode($value);
213
-				}, $keys, $values);
214
-				$configString = implode(', ', $configStrings);
211
+                $configStrings = array_map(function ($key, $value) {
212
+                    return $key . ': ' . json_encode($value);
213
+                }, $keys, $values);
214
+                $configString = implode(', ', $configStrings);
215 215
 
216
-				$mountOptions = $config->getMountOptions();
217
-				// hide defaults
218
-				foreach ($mountOptions as $key => $value) {
219
-					if ($value === $defaultMountOptions[$key]) {
220
-						unset($mountOptions[$key]);
221
-					}
222
-				}
223
-				$keys = array_keys($mountOptions);
224
-				$values = array_values($mountOptions);
216
+                $mountOptions = $config->getMountOptions();
217
+                // hide defaults
218
+                foreach ($mountOptions as $key => $value) {
219
+                    if ($value === $defaultMountOptions[$key]) {
220
+                        unset($mountOptions[$key]);
221
+                    }
222
+                }
223
+                $keys = array_keys($mountOptions);
224
+                $values = array_values($mountOptions);
225 225
 
226
-				$optionsStrings = array_map(function ($key, $value) {
227
-					return $key . ': ' . json_encode($value);
228
-				}, $keys, $values);
229
-				$optionsString = implode(', ', $optionsStrings);
226
+                $optionsStrings = array_map(function ($key, $value) {
227
+                    return $key . ': ' . json_encode($value);
228
+                }, $keys, $values);
229
+                $optionsString = implode(', ', $optionsStrings);
230 230
 
231
-				$values = [
232
-					$config->getId(),
233
-					$config->getMountPoint(),
234
-					$config->getBackend()->getText(),
235
-					$config->getAuthMechanism()->getText(),
236
-					$configString,
237
-					$optionsString
238
-				];
231
+                $values = [
232
+                    $config->getId(),
233
+                    $config->getMountPoint(),
234
+                    $config->getBackend()->getText(),
235
+                    $config->getAuthMechanism()->getText(),
236
+                    $configString,
237
+                    $optionsString
238
+                ];
239 239
 
240
-				if (!$userId || $userId === self::ALL) {
241
-					$applicableUsers = implode(', ', $config->getApplicableUsers());
242
-					$applicableGroups = implode(', ', $config->getApplicableGroups());
243
-					if ($applicableUsers === '' && $applicableGroups === '') {
244
-						$applicableUsers = 'All';
245
-					}
246
-					$values[] = $applicableUsers;
247
-					$values[] = $applicableGroups;
248
-				}
249
-				if ($userId === self::ALL) {
250
-					$values[] = $config->getType() === StorageConfig::MOUNT_TYPE_ADMIN ? 'Admin' : 'Personal';
251
-				}
240
+                if (!$userId || $userId === self::ALL) {
241
+                    $applicableUsers = implode(', ', $config->getApplicableUsers());
242
+                    $applicableGroups = implode(', ', $config->getApplicableGroups());
243
+                    if ($applicableUsers === '' && $applicableGroups === '') {
244
+                        $applicableUsers = 'All';
245
+                    }
246
+                    $values[] = $applicableUsers;
247
+                    $values[] = $applicableGroups;
248
+                }
249
+                if ($userId === self::ALL) {
250
+                    $values[] = $config->getType() === StorageConfig::MOUNT_TYPE_ADMIN ? 'Admin' : 'Personal';
251
+                }
252 252
 
253
-				return $values;
254
-			}, $mounts);
253
+                return $values;
254
+            }, $mounts);
255 255
 
256
-			$table = new Table($output);
257
-			$table->setHeaders($headers);
258
-			$table->setRows($rows);
259
-			$table->render();
260
-		}
261
-	}
256
+            $table = new Table($output);
257
+            $table->setHeaders($headers);
258
+            $table->setRows($rows);
259
+            $table->render();
260
+        }
261
+    }
262 262
 
263
-	protected function getStorageService($userId) {
264
-		if (!empty($userId)) {
265
-			$user = $this->userManager->get($userId);
266
-			if (is_null($user)) {
267
-				throw new NoUserException("user $userId not found");
268
-			}
269
-			$this->userSession->setUser($user);
270
-			return $this->userService;
271
-		} else {
272
-			return $this->globalService;
273
-		}
274
-	}
263
+    protected function getStorageService($userId) {
264
+        if (!empty($userId)) {
265
+            $user = $this->userManager->get($userId);
266
+            if (is_null($user)) {
267
+                throw new NoUserException("user $userId not found");
268
+            }
269
+            $this->userSession->setUser($user);
270
+            return $this->userService;
271
+        } else {
272
+            return $this->globalService;
273
+        }
274
+    }
275 275
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Command/Verify.php 1 patch
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -37,108 +37,108 @@
 block discarded – undo
37 37
 use Symfony\Component\Console\Output\OutputInterface;
38 38
 
39 39
 class Verify extends Base {
40
-	/**
41
-	 * @var GlobalStoragesService
42
-	 */
43
-	protected $globalService;
40
+    /**
41
+     * @var GlobalStoragesService
42
+     */
43
+    protected $globalService;
44 44
 
45
-	function __construct(GlobalStoragesService $globalService) {
46
-		parent::__construct();
47
-		$this->globalService = $globalService;
48
-	}
45
+    function __construct(GlobalStoragesService $globalService) {
46
+        parent::__construct();
47
+        $this->globalService = $globalService;
48
+    }
49 49
 
50
-	protected function configure() {
51
-		$this
52
-			->setName('files_external:verify')
53
-			->setDescription('Verify mount configuration')
54
-			->addArgument(
55
-				'mount_id',
56
-				InputArgument::REQUIRED,
57
-				'The id of the mount to check'
58
-			)->addOption(
59
-				'config',
60
-				'c',
61
-				InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
62
-				'Additional config option to set before checking in key=value pairs, required for certain auth backends such as login credentails'
63
-			);
64
-		parent::configure();
65
-	}
50
+    protected function configure() {
51
+        $this
52
+            ->setName('files_external:verify')
53
+            ->setDescription('Verify mount configuration')
54
+            ->addArgument(
55
+                'mount_id',
56
+                InputArgument::REQUIRED,
57
+                'The id of the mount to check'
58
+            )->addOption(
59
+                'config',
60
+                'c',
61
+                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
62
+                'Additional config option to set before checking in key=value pairs, required for certain auth backends such as login credentails'
63
+            );
64
+        parent::configure();
65
+    }
66 66
 
67
-	protected function execute(InputInterface $input, OutputInterface $output) {
68
-		$mountId = $input->getArgument('mount_id');
69
-		$configInput = $input->getOption('config');
67
+    protected function execute(InputInterface $input, OutputInterface $output) {
68
+        $mountId = $input->getArgument('mount_id');
69
+        $configInput = $input->getOption('config');
70 70
 
71
-		try {
72
-			$mount = $this->globalService->getStorage($mountId);
73
-		} catch (NotFoundException $e) {
74
-			$output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts"</error>');
75
-			return 404;
76
-		}
71
+        try {
72
+            $mount = $this->globalService->getStorage($mountId);
73
+        } catch (NotFoundException $e) {
74
+            $output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts"</error>');
75
+            return 404;
76
+        }
77 77
 
78
-		$this->updateStorageStatus($mount, $configInput, $output);
78
+        $this->updateStorageStatus($mount, $configInput, $output);
79 79
 
80
-		$this->writeArrayInOutputFormat($input, $output, [
81
-			'status' => StorageNotAvailableException::getStateCodeName($mount->getStatus()),
82
-			'code' => $mount->getStatus(),
83
-			'message' => $mount->getStatusMessage()
84
-		]);
85
-	}
80
+        $this->writeArrayInOutputFormat($input, $output, [
81
+            'status' => StorageNotAvailableException::getStateCodeName($mount->getStatus()),
82
+            'code' => $mount->getStatus(),
83
+            'message' => $mount->getStatusMessage()
84
+        ]);
85
+    }
86 86
 
87
-	private function manipulateStorageConfig(StorageConfig $storage) {
88
-		/** @var AuthMechanism */
89
-		$authMechanism = $storage->getAuthMechanism();
90
-		$authMechanism->manipulateStorageConfig($storage);
91
-		/** @var Backend */
92
-		$backend = $storage->getBackend();
93
-		$backend->manipulateStorageConfig($storage);
94
-	}
87
+    private function manipulateStorageConfig(StorageConfig $storage) {
88
+        /** @var AuthMechanism */
89
+        $authMechanism = $storage->getAuthMechanism();
90
+        $authMechanism->manipulateStorageConfig($storage);
91
+        /** @var Backend */
92
+        $backend = $storage->getBackend();
93
+        $backend->manipulateStorageConfig($storage);
94
+    }
95 95
 
96
-	private function updateStorageStatus(StorageConfig &$storage, $configInput, OutputInterface $output) {
97
-		try {
98
-			try {
99
-				$this->manipulateStorageConfig($storage);
100
-			} catch (InsufficientDataForMeaningfulAnswerException $e) {
101
-				if (count($configInput) === 0) { // extra config options might solve the error
102
-					throw $e;
103
-				}
104
-			}
96
+    private function updateStorageStatus(StorageConfig &$storage, $configInput, OutputInterface $output) {
97
+        try {
98
+            try {
99
+                $this->manipulateStorageConfig($storage);
100
+            } catch (InsufficientDataForMeaningfulAnswerException $e) {
101
+                if (count($configInput) === 0) { // extra config options might solve the error
102
+                    throw $e;
103
+                }
104
+            }
105 105
 
106
-			foreach ($configInput as $configOption) {
107
-				if (!strpos($configOption, '=')) {
108
-					$output->writeln('<error>Invalid mount configuration option "' . $configOption . '"</error>');
109
-					return;
110
-				}
111
-				list($key, $value) = explode('=', $configOption, 2);
112
-				$storage->setBackendOption($key, $value);
113
-			}
106
+            foreach ($configInput as $configOption) {
107
+                if (!strpos($configOption, '=')) {
108
+                    $output->writeln('<error>Invalid mount configuration option "' . $configOption . '"</error>');
109
+                    return;
110
+                }
111
+                list($key, $value) = explode('=', $configOption, 2);
112
+                $storage->setBackendOption($key, $value);
113
+            }
114 114
 
115
-			/** @var Backend */
116
-			$backend = $storage->getBackend();
117
-			// update status (can be time-consuming)
118
-			$storage->setStatus(
119
-				\OC_Mount_Config::getBackendStatus(
120
-					$backend->getStorageClass(),
121
-					$storage->getBackendOptions(),
122
-					false
123
-				)
124
-			);
125
-		} catch (InsufficientDataForMeaningfulAnswerException $e) {
126
-			$status = $e->getCode() ? $e->getCode() : StorageNotAvailableException::STATUS_INDETERMINATE;
127
-			$storage->setStatus(
128
-				$status,
129
-				$e->getMessage()
130
-			);
131
-		} catch (StorageNotAvailableException $e) {
132
-			$storage->setStatus(
133
-				$e->getCode(),
134
-				$e->getMessage()
135
-			);
136
-		} catch (\Exception $e) {
137
-			// FIXME: convert storage exceptions to StorageNotAvailableException
138
-			$storage->setStatus(
139
-				StorageNotAvailableException::STATUS_ERROR,
140
-				get_class($e) . ': ' . $e->getMessage()
141
-			);
142
-		}
143
-	}
115
+            /** @var Backend */
116
+            $backend = $storage->getBackend();
117
+            // update status (can be time-consuming)
118
+            $storage->setStatus(
119
+                \OC_Mount_Config::getBackendStatus(
120
+                    $backend->getStorageClass(),
121
+                    $storage->getBackendOptions(),
122
+                    false
123
+                )
124
+            );
125
+        } catch (InsufficientDataForMeaningfulAnswerException $e) {
126
+            $status = $e->getCode() ? $e->getCode() : StorageNotAvailableException::STATUS_INDETERMINATE;
127
+            $storage->setStatus(
128
+                $status,
129
+                $e->getMessage()
130
+            );
131
+        } catch (StorageNotAvailableException $e) {
132
+            $storage->setStatus(
133
+                $e->getCode(),
134
+                $e->getMessage()
135
+            );
136
+        } catch (\Exception $e) {
137
+            // FIXME: convert storage exceptions to StorageNotAvailableException
138
+            $storage->setStatus(
139
+                StorageNotAvailableException::STATUS_ERROR,
140
+                get_class($e) . ': ' . $e->getMessage()
141
+            );
142
+        }
143
+    }
144 144
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Command/Option.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -28,50 +28,50 @@
 block discarded – undo
28 28
 use Symfony\Component\Console\Output\OutputInterface;
29 29
 
30 30
 class Option extends Config {
31
-	protected function configure() {
32
-		$this
33
-			->setName('files_external:option')
34
-			->setDescription('Manage mount options for a mount')
35
-			->addArgument(
36
-				'mount_id',
37
-				InputArgument::REQUIRED,
38
-				'The id of the mount to edit'
39
-			)->addArgument(
40
-				'key',
41
-				InputArgument::REQUIRED,
42
-				'key of the mount option to set/get'
43
-			)->addArgument(
44
-				'value',
45
-				InputArgument::OPTIONAL,
46
-				'value to set the mount option to, when no value is provided the existing value will be printed'
47
-			);
48
-	}
31
+    protected function configure() {
32
+        $this
33
+            ->setName('files_external:option')
34
+            ->setDescription('Manage mount options for a mount')
35
+            ->addArgument(
36
+                'mount_id',
37
+                InputArgument::REQUIRED,
38
+                'The id of the mount to edit'
39
+            )->addArgument(
40
+                'key',
41
+                InputArgument::REQUIRED,
42
+                'key of the mount option to set/get'
43
+            )->addArgument(
44
+                'value',
45
+                InputArgument::OPTIONAL,
46
+                'value to set the mount option to, when no value is provided the existing value will be printed'
47
+            );
48
+    }
49 49
 
50
-	/**
51
-	 * @param StorageConfig $mount
52
-	 * @param string $key
53
-	 * @param OutputInterface $output
54
-	 */
55
-	protected function getOption(StorageConfig $mount, $key, OutputInterface $output) {
56
-		$value = $mount->getMountOption($key);
57
-		if (!is_string($value)) { // show bools and objects correctly
58
-			$value = json_encode($value);
59
-		}
60
-		$output->writeln($value);
61
-	}
50
+    /**
51
+     * @param StorageConfig $mount
52
+     * @param string $key
53
+     * @param OutputInterface $output
54
+     */
55
+    protected function getOption(StorageConfig $mount, $key, OutputInterface $output) {
56
+        $value = $mount->getMountOption($key);
57
+        if (!is_string($value)) { // show bools and objects correctly
58
+            $value = json_encode($value);
59
+        }
60
+        $output->writeln($value);
61
+    }
62 62
 
63
-	/**
64
-	 * @param StorageConfig $mount
65
-	 * @param string $key
66
-	 * @param string $value
67
-	 * @param OutputInterface $output
68
-	 */
69
-	protected function setOption(StorageConfig $mount, $key, $value, OutputInterface $output) {
70
-		$decoded = json_decode($value, true);
71
-		if (!is_null($decoded)) {
72
-			$value = $decoded;
73
-		}
74
-		$mount->setMountOption($key, $value);
75
-		$this->globalService->updateStorage($mount);
76
-	}
63
+    /**
64
+     * @param StorageConfig $mount
65
+     * @param string $key
66
+     * @param string $value
67
+     * @param OutputInterface $output
68
+     */
69
+    protected function setOption(StorageConfig $mount, $key, $value, OutputInterface $output) {
70
+        $decoded = json_decode($value, true);
71
+        if (!is_null($decoded)) {
72
+            $value = $decoded;
73
+        }
74
+        $mount->setMountOption($key, $value);
75
+        $this->globalService->updateStorage($mount);
76
+    }
77 77
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Command/Notify.php 1 patch
Indentation   +172 added lines, -172 removed lines patch added patch discarded remove patch
@@ -40,178 +40,178 @@
 block discarded – undo
40 40
 use Symfony\Component\Console\Output\OutputInterface;
41 41
 
42 42
 class Notify extends Base {
43
-	/** @var GlobalStoragesService */
44
-	private $globalService;
45
-	/** @var IDBConnection */
46
-	private $connection;
47
-	/** @var \OCP\DB\QueryBuilder\IQueryBuilder */
48
-	private $updateQuery;
49
-
50
-	function __construct(GlobalStoragesService $globalService, IDBConnection $connection) {
51
-		parent::__construct();
52
-		$this->globalService = $globalService;
53
-		$this->connection = $connection;
54
-		// the query builder doesn't really like subqueries with parameters
55
-		$this->updateQuery = $this->connection->prepare(
56
-			'UPDATE *PREFIX*filecache SET size = -1
43
+    /** @var GlobalStoragesService */
44
+    private $globalService;
45
+    /** @var IDBConnection */
46
+    private $connection;
47
+    /** @var \OCP\DB\QueryBuilder\IQueryBuilder */
48
+    private $updateQuery;
49
+
50
+    function __construct(GlobalStoragesService $globalService, IDBConnection $connection) {
51
+        parent::__construct();
52
+        $this->globalService = $globalService;
53
+        $this->connection = $connection;
54
+        // the query builder doesn't really like subqueries with parameters
55
+        $this->updateQuery = $this->connection->prepare(
56
+            'UPDATE *PREFIX*filecache SET size = -1
57 57
 			WHERE `path` = ?
58 58
 			AND `storage` IN (SELECT storage_id FROM *PREFIX*mounts WHERE mount_id = ?)'
59
-		);
60
-	}
61
-
62
-	protected function configure() {
63
-		$this
64
-			->setName('files_external:notify')
65
-			->setDescription('Listen for active update notifications for a configured external mount')
66
-			->addArgument(
67
-				'mount_id',
68
-				InputArgument::REQUIRED,
69
-				'the mount id of the mount to listen to'
70
-			)->addOption(
71
-				'user',
72
-				'u',
73
-				InputOption::VALUE_REQUIRED,
74
-				'The username for the remote mount (required only for some mount configuration that don\'t store credentials)'
75
-			)->addOption(
76
-				'password',
77
-				'p',
78
-				InputOption::VALUE_REQUIRED,
79
-				'The password for the remote mount (required only for some mount configuration that don\'t store credentials)'
80
-			)->addOption(
81
-				'path',
82
-				null,
83
-				InputOption::VALUE_REQUIRED,
84
-				'The directory in the storage to listen for updates in',
85
-				'/'
86
-			);
87
-		parent::configure();
88
-	}
89
-
90
-	protected function execute(InputInterface $input, OutputInterface $output) {
91
-		$mount = $this->globalService->getStorage($input->getArgument('mount_id'));
92
-		if (is_null($mount)) {
93
-			$output->writeln('<error>Mount not found</error>');
94
-			return 1;
95
-		}
96
-		$noAuth = false;
97
-		try {
98
-			$authBackend = $mount->getAuthMechanism();
99
-			$authBackend->manipulateStorageConfig($mount);
100
-		} catch (InsufficientDataForMeaningfulAnswerException $e) {
101
-			$noAuth = true;
102
-		} catch (StorageNotAvailableException $e) {
103
-			$noAuth = true;
104
-		}
105
-
106
-		if ($input->getOption('user')) {
107
-			$mount->setBackendOption('user', $input->getOption('user'));
108
-		}
109
-		if ($input->getOption('password')) {
110
-			$mount->setBackendOption('password', $input->getOption('password'));
111
-		}
112
-
113
-		try {
114
-			$storage = $this->createStorage($mount);
115
-		} catch (\Exception $e) {
116
-			$output->writeln('<error>Error while trying to create storage</error>');
117
-			if ($noAuth) {
118
-				$output->writeln('<error>Username and/or password required</error>');
119
-			}
120
-			return 1;
121
-		}
122
-		if (!$storage instanceof INotifyStorage) {
123
-			$output->writeln('<error>Mount of type "' . $mount->getBackend()->getText() . '" does not support active update notifications</error>');
124
-			return 1;
125
-		}
126
-
127
-		$verbose = $input->getOption('verbose');
128
-
129
-		$path = trim($input->getOption('path'), '/');
130
-		$notifyHandler = $storage->notify($path);
131
-		$this->selfTest($storage, $notifyHandler, $verbose, $output);
132
-		$notifyHandler->listen(function (IChange $change) use ($mount, $verbose, $output) {
133
-			if ($verbose) {
134
-				$this->logUpdate($change, $output);
135
-			}
136
-			if ($change instanceof IRenameChange) {
137
-				$this->markParentAsOutdated($mount->getId(), $change->getTargetPath());
138
-			}
139
-			$this->markParentAsOutdated($mount->getId(), $change->getPath());
140
-		});
141
-	}
142
-
143
-	private function createStorage(StorageConfig $mount) {
144
-		$class = $mount->getBackend()->getStorageClass();
145
-		return new $class($mount->getBackendOptions());
146
-	}
147
-
148
-	private function markParentAsOutdated($mountId, $path) {
149
-		$parent = dirname($path);
150
-		if ($parent === '.') {
151
-			$parent = '';
152
-		}
153
-		$this->updateQuery->execute([$parent, $mountId]);
154
-	}
155
-
156
-	private function logUpdate(IChange $change, OutputInterface $output) {
157
-		switch ($change->getType()) {
158
-			case INotifyStorage::NOTIFY_ADDED:
159
-				$text = 'added';
160
-				break;
161
-			case INotifyStorage::NOTIFY_MODIFIED:
162
-				$text = 'modified';
163
-				break;
164
-			case INotifyStorage::NOTIFY_REMOVED:
165
-				$text = 'removed';
166
-				break;
167
-			case INotifyStorage::NOTIFY_RENAMED:
168
-				$text = 'renamed';
169
-				break;
170
-			default:
171
-				return;
172
-		}
173
-
174
-		$text .= ' ' . $change->getPath();
175
-		if ($change instanceof IRenameChange) {
176
-			$text .= ' to ' . $change->getTargetPath();
177
-		}
178
-
179
-		$output->writeln($text);
180
-	}
181
-
182
-	private function selfTest(IStorage $storage, INotifyHandler $notifyHandler, $verbose, OutputInterface $output) {
183
-		usleep(100 * 1000); //give time for the notify to start
184
-		$storage->file_put_contents('/.nc_test_file.txt', 'test content');
185
-		$storage->mkdir('/.nc_test_folder');
186
-		$storage->file_put_contents('/.nc_test_folder/subfile.txt', 'test content');
187
-
188
-		usleep(100 * 1000); //time for all changes to be processed
189
-		$changes = $notifyHandler->getChanges();
190
-
191
-		$storage->unlink('/.nc_test_file.txt');
192
-		$storage->unlink('/.nc_test_folder/subfile.txt');
193
-		$storage->rmdir('/.nc_test_folder');
194
-
195
-		usleep(100 * 1000); //time for all changes to be processed
196
-		$notifyHandler->getChanges(); // flush
197
-
198
-		$foundRootChange = false;
199
-		$foundSubfolderChange = false;
200
-
201
-		foreach ($changes as $change) {
202
-			if ($change->getPath() === '/.nc_test_file.txt' || $change->getPath() === '.nc_test_file.txt') {
203
-				$foundRootChange = true;
204
-			} else if ($change->getPath() === '/.nc_test_folder/subfile.txt' || $change->getPath() === '.nc_test_folder/subfile.txt') {
205
-				$foundSubfolderChange = true;
206
-			}
207
-		}
208
-
209
-		if ($foundRootChange && $foundSubfolderChange && $verbose) {
210
-			$output->writeln('<info>Self-test successful</info>');
211
-		} else if ($foundRootChange && !$foundSubfolderChange) {
212
-			$output->writeln('<error>Error while running self-test, change is subfolder not detected</error>');
213
-		} else if (!$foundRootChange) {
214
-			$output->writeln('<error>Error while running self-test, no changes detected</error>');
215
-		}
216
-	}
59
+        );
60
+    }
61
+
62
+    protected function configure() {
63
+        $this
64
+            ->setName('files_external:notify')
65
+            ->setDescription('Listen for active update notifications for a configured external mount')
66
+            ->addArgument(
67
+                'mount_id',
68
+                InputArgument::REQUIRED,
69
+                'the mount id of the mount to listen to'
70
+            )->addOption(
71
+                'user',
72
+                'u',
73
+                InputOption::VALUE_REQUIRED,
74
+                'The username for the remote mount (required only for some mount configuration that don\'t store credentials)'
75
+            )->addOption(
76
+                'password',
77
+                'p',
78
+                InputOption::VALUE_REQUIRED,
79
+                'The password for the remote mount (required only for some mount configuration that don\'t store credentials)'
80
+            )->addOption(
81
+                'path',
82
+                null,
83
+                InputOption::VALUE_REQUIRED,
84
+                'The directory in the storage to listen for updates in',
85
+                '/'
86
+            );
87
+        parent::configure();
88
+    }
89
+
90
+    protected function execute(InputInterface $input, OutputInterface $output) {
91
+        $mount = $this->globalService->getStorage($input->getArgument('mount_id'));
92
+        if (is_null($mount)) {
93
+            $output->writeln('<error>Mount not found</error>');
94
+            return 1;
95
+        }
96
+        $noAuth = false;
97
+        try {
98
+            $authBackend = $mount->getAuthMechanism();
99
+            $authBackend->manipulateStorageConfig($mount);
100
+        } catch (InsufficientDataForMeaningfulAnswerException $e) {
101
+            $noAuth = true;
102
+        } catch (StorageNotAvailableException $e) {
103
+            $noAuth = true;
104
+        }
105
+
106
+        if ($input->getOption('user')) {
107
+            $mount->setBackendOption('user', $input->getOption('user'));
108
+        }
109
+        if ($input->getOption('password')) {
110
+            $mount->setBackendOption('password', $input->getOption('password'));
111
+        }
112
+
113
+        try {
114
+            $storage = $this->createStorage($mount);
115
+        } catch (\Exception $e) {
116
+            $output->writeln('<error>Error while trying to create storage</error>');
117
+            if ($noAuth) {
118
+                $output->writeln('<error>Username and/or password required</error>');
119
+            }
120
+            return 1;
121
+        }
122
+        if (!$storage instanceof INotifyStorage) {
123
+            $output->writeln('<error>Mount of type "' . $mount->getBackend()->getText() . '" does not support active update notifications</error>');
124
+            return 1;
125
+        }
126
+
127
+        $verbose = $input->getOption('verbose');
128
+
129
+        $path = trim($input->getOption('path'), '/');
130
+        $notifyHandler = $storage->notify($path);
131
+        $this->selfTest($storage, $notifyHandler, $verbose, $output);
132
+        $notifyHandler->listen(function (IChange $change) use ($mount, $verbose, $output) {
133
+            if ($verbose) {
134
+                $this->logUpdate($change, $output);
135
+            }
136
+            if ($change instanceof IRenameChange) {
137
+                $this->markParentAsOutdated($mount->getId(), $change->getTargetPath());
138
+            }
139
+            $this->markParentAsOutdated($mount->getId(), $change->getPath());
140
+        });
141
+    }
142
+
143
+    private function createStorage(StorageConfig $mount) {
144
+        $class = $mount->getBackend()->getStorageClass();
145
+        return new $class($mount->getBackendOptions());
146
+    }
147
+
148
+    private function markParentAsOutdated($mountId, $path) {
149
+        $parent = dirname($path);
150
+        if ($parent === '.') {
151
+            $parent = '';
152
+        }
153
+        $this->updateQuery->execute([$parent, $mountId]);
154
+    }
155
+
156
+    private function logUpdate(IChange $change, OutputInterface $output) {
157
+        switch ($change->getType()) {
158
+            case INotifyStorage::NOTIFY_ADDED:
159
+                $text = 'added';
160
+                break;
161
+            case INotifyStorage::NOTIFY_MODIFIED:
162
+                $text = 'modified';
163
+                break;
164
+            case INotifyStorage::NOTIFY_REMOVED:
165
+                $text = 'removed';
166
+                break;
167
+            case INotifyStorage::NOTIFY_RENAMED:
168
+                $text = 'renamed';
169
+                break;
170
+            default:
171
+                return;
172
+        }
173
+
174
+        $text .= ' ' . $change->getPath();
175
+        if ($change instanceof IRenameChange) {
176
+            $text .= ' to ' . $change->getTargetPath();
177
+        }
178
+
179
+        $output->writeln($text);
180
+    }
181
+
182
+    private function selfTest(IStorage $storage, INotifyHandler $notifyHandler, $verbose, OutputInterface $output) {
183
+        usleep(100 * 1000); //give time for the notify to start
184
+        $storage->file_put_contents('/.nc_test_file.txt', 'test content');
185
+        $storage->mkdir('/.nc_test_folder');
186
+        $storage->file_put_contents('/.nc_test_folder/subfile.txt', 'test content');
187
+
188
+        usleep(100 * 1000); //time for all changes to be processed
189
+        $changes = $notifyHandler->getChanges();
190
+
191
+        $storage->unlink('/.nc_test_file.txt');
192
+        $storage->unlink('/.nc_test_folder/subfile.txt');
193
+        $storage->rmdir('/.nc_test_folder');
194
+
195
+        usleep(100 * 1000); //time for all changes to be processed
196
+        $notifyHandler->getChanges(); // flush
197
+
198
+        $foundRootChange = false;
199
+        $foundSubfolderChange = false;
200
+
201
+        foreach ($changes as $change) {
202
+            if ($change->getPath() === '/.nc_test_file.txt' || $change->getPath() === '.nc_test_file.txt') {
203
+                $foundRootChange = true;
204
+            } else if ($change->getPath() === '/.nc_test_folder/subfile.txt' || $change->getPath() === '.nc_test_folder/subfile.txt') {
205
+                $foundSubfolderChange = true;
206
+            }
207
+        }
208
+
209
+        if ($foundRootChange && $foundSubfolderChange && $verbose) {
210
+            $output->writeln('<info>Self-test successful</info>');
211
+        } else if ($foundRootChange && !$foundSubfolderChange) {
212
+            $output->writeln('<error>Error while running self-test, change is subfolder not detected</error>');
213
+        } else if (!$foundRootChange) {
214
+            $output->writeln('<error>Error while running self-test, no changes detected</error>');
215
+        }
216
+    }
217 217
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Command/Create.php 1 patch
Indentation   +178 added lines, -178 removed lines patch added patch discarded remove patch
@@ -42,182 +42,182 @@
 block discarded – undo
42 42
 use Symfony\Component\Console\Output\OutputInterface;
43 43
 
44 44
 class Create extends Base {
45
-	/**
46
-	 * @var GlobalStoragesService
47
-	 */
48
-	private $globalService;
49
-
50
-	/**
51
-	 * @var UserStoragesService
52
-	 */
53
-	private $userService;
54
-
55
-	/**
56
-	 * @var IUserManager
57
-	 */
58
-	private $userManager;
59
-
60
-	/** @var BackendService */
61
-	private $backendService;
62
-
63
-	/** @var IUserSession */
64
-	private $userSession;
65
-
66
-	function __construct(GlobalStoragesService $globalService,
67
-						 UserStoragesService $userService,
68
-						 IUserManager $userManager,
69
-						 IUserSession $userSession,
70
-						 BackendService $backendService
71
-	) {
72
-		parent::__construct();
73
-		$this->globalService = $globalService;
74
-		$this->userService = $userService;
75
-		$this->userManager = $userManager;
76
-		$this->userSession = $userSession;
77
-		$this->backendService = $backendService;
78
-	}
79
-
80
-	protected function configure() {
81
-		$this
82
-			->setName('files_external:create')
83
-			->setDescription('Create a new mount configuration')
84
-			->addOption(
85
-				'user',
86
-				null,
87
-				InputOption::VALUE_OPTIONAL,
88
-				'user to add the mount configuration for, if not set the mount will be added as system mount'
89
-			)
90
-			->addArgument(
91
-				'mount_point',
92
-				InputArgument::REQUIRED,
93
-				'mount point for the new mount'
94
-			)
95
-			->addArgument(
96
-				'storage_backend',
97
-				InputArgument::REQUIRED,
98
-				'storage backend identifier for the new mount, see `occ files_external:backends` for possible values'
99
-			)
100
-			->addArgument(
101
-				'authentication_backend',
102
-				InputArgument::REQUIRED,
103
-				'authentication backend identifier for the new mount, see `occ files_external:backends` for possible values'
104
-			)
105
-			->addOption(
106
-				'config',
107
-				'c',
108
-				InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
109
-				'Mount configuration option in key=value format'
110
-			)
111
-			->addOption(
112
-				'dry',
113
-				null,
114
-				InputOption::VALUE_NONE,
115
-				'Don\'t save the created mount, only list the new mount'
116
-			);
117
-		parent::configure();
118
-	}
119
-
120
-	protected function execute(InputInterface $input, OutputInterface $output) {
121
-		$user = $input->getOption('user');
122
-		$mountPoint = $input->getArgument('mount_point');
123
-		$storageIdentifier = $input->getArgument('storage_backend');
124
-		$authIdentifier = $input->getArgument('authentication_backend');
125
-		$configInput = $input->getOption('config');
126
-
127
-		$storageBackend = $this->backendService->getBackend($storageIdentifier);
128
-		$authBackend = $this->backendService->getAuthMechanism($authIdentifier);
129
-
130
-		if (!Filesystem::isValidPath($mountPoint)) {
131
-			$output->writeln('<error>Invalid mountpoint "' . $mountPoint . '"</error>');
132
-			return 1;
133
-		}
134
-		if (is_null($storageBackend)) {
135
-			$output->writeln('<error>Storage backend with identifier "' . $storageIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>');
136
-			return 404;
137
-		}
138
-		if (is_null($authBackend)) {
139
-			$output->writeln('<error>Authentication backend with identifier "' . $authIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>');
140
-			return 404;
141
-		}
142
-		$supportedSchemes = array_keys($storageBackend->getAuthSchemes());
143
-		if (!in_array($authBackend->getScheme(), $supportedSchemes)) {
144
-			$output->writeln('<error>Authentication backend "' . $authIdentifier . '" not valid for storage backend "' . $storageIdentifier . '" (see `occ files_external:backends storage ' . $storageIdentifier . '` for possible values)</error>');
145
-			return 1;
146
-		}
147
-
148
-		$config = [];
149
-		foreach ($configInput as $configOption) {
150
-			if (!strpos($configOption, '=')) {
151
-				$output->writeln('<error>Invalid mount configuration option "' . $configOption . '"</error>');
152
-				return 1;
153
-			}
154
-			list($key, $value) = explode('=', $configOption, 2);
155
-			if (!$this->validateParam($key, $value, $storageBackend, $authBackend)) {
156
-				$output->writeln('<error>Unknown configuration for backends "' . $key . '"</error>');
157
-				return 1;
158
-			}
159
-			$config[$key] = $value;
160
-		}
161
-
162
-		$mount = new StorageConfig();
163
-		$mount->setMountPoint($mountPoint);
164
-		$mount->setBackend($storageBackend);
165
-		$mount->setAuthMechanism($authBackend);
166
-		$mount->setBackendOptions($config);
167
-
168
-		if ($user) {
169
-			if (!$this->userManager->userExists($user)) {
170
-				$output->writeln('<error>User "' . $user . '" not found</error>');
171
-				return 1;
172
-			}
173
-			$mount->setApplicableUsers([$user]);
174
-		}
175
-
176
-		if ($input->getOption('dry')) {
177
-			$this->showMount($user, $mount, $input, $output);
178
-		} else {
179
-			$this->getStorageService($user)->addStorage($mount);
180
-			if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN) {
181
-				$output->writeln('<info>Storage created with id ' . $mount->getId() . '</info>');
182
-			} else {
183
-				$output->writeln($mount->getId());
184
-			}
185
-		}
186
-		return 0;
187
-	}
188
-
189
-	private function validateParam($key, &$value, Backend $storageBackend, AuthMechanism $authBackend) {
190
-		$params = array_merge($storageBackend->getParameters(), $authBackend->getParameters());
191
-		foreach ($params as $param) {
192
-			/** @var DefinitionParameter $param */
193
-			if ($param->getName() === $key) {
194
-				if ($param->getType() === DefinitionParameter::VALUE_BOOLEAN) {
195
-					$value = ($value === 'true');
196
-				}
197
-				return true;
198
-			}
199
-		}
200
-		return false;
201
-	}
202
-
203
-	private function showMount($user, StorageConfig $mount, InputInterface $input, OutputInterface $output) {
204
-		$listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager);
205
-		$listInput = new ArrayInput([], $listCommand->getDefinition());
206
-		$listInput->setOption('output', $input->getOption('output'));
207
-		$listInput->setOption('show-password', true);
208
-		$listCommand->listMounts($user, [$mount], $listInput, $output);
209
-	}
210
-
211
-	protected function getStorageService($userId) {
212
-		if (!empty($userId)) {
213
-			$user = $this->userManager->get($userId);
214
-			if (is_null($user)) {
215
-				throw new NoUserException("user $userId not found");
216
-			}
217
-			$this->userSession->setUser($user);
218
-			return $this->userService;
219
-		} else {
220
-			return $this->globalService;
221
-		}
222
-	}
45
+    /**
46
+     * @var GlobalStoragesService
47
+     */
48
+    private $globalService;
49
+
50
+    /**
51
+     * @var UserStoragesService
52
+     */
53
+    private $userService;
54
+
55
+    /**
56
+     * @var IUserManager
57
+     */
58
+    private $userManager;
59
+
60
+    /** @var BackendService */
61
+    private $backendService;
62
+
63
+    /** @var IUserSession */
64
+    private $userSession;
65
+
66
+    function __construct(GlobalStoragesService $globalService,
67
+                            UserStoragesService $userService,
68
+                            IUserManager $userManager,
69
+                            IUserSession $userSession,
70
+                            BackendService $backendService
71
+    ) {
72
+        parent::__construct();
73
+        $this->globalService = $globalService;
74
+        $this->userService = $userService;
75
+        $this->userManager = $userManager;
76
+        $this->userSession = $userSession;
77
+        $this->backendService = $backendService;
78
+    }
79
+
80
+    protected function configure() {
81
+        $this
82
+            ->setName('files_external:create')
83
+            ->setDescription('Create a new mount configuration')
84
+            ->addOption(
85
+                'user',
86
+                null,
87
+                InputOption::VALUE_OPTIONAL,
88
+                'user to add the mount configuration for, if not set the mount will be added as system mount'
89
+            )
90
+            ->addArgument(
91
+                'mount_point',
92
+                InputArgument::REQUIRED,
93
+                'mount point for the new mount'
94
+            )
95
+            ->addArgument(
96
+                'storage_backend',
97
+                InputArgument::REQUIRED,
98
+                'storage backend identifier for the new mount, see `occ files_external:backends` for possible values'
99
+            )
100
+            ->addArgument(
101
+                'authentication_backend',
102
+                InputArgument::REQUIRED,
103
+                'authentication backend identifier for the new mount, see `occ files_external:backends` for possible values'
104
+            )
105
+            ->addOption(
106
+                'config',
107
+                'c',
108
+                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
109
+                'Mount configuration option in key=value format'
110
+            )
111
+            ->addOption(
112
+                'dry',
113
+                null,
114
+                InputOption::VALUE_NONE,
115
+                'Don\'t save the created mount, only list the new mount'
116
+            );
117
+        parent::configure();
118
+    }
119
+
120
+    protected function execute(InputInterface $input, OutputInterface $output) {
121
+        $user = $input->getOption('user');
122
+        $mountPoint = $input->getArgument('mount_point');
123
+        $storageIdentifier = $input->getArgument('storage_backend');
124
+        $authIdentifier = $input->getArgument('authentication_backend');
125
+        $configInput = $input->getOption('config');
126
+
127
+        $storageBackend = $this->backendService->getBackend($storageIdentifier);
128
+        $authBackend = $this->backendService->getAuthMechanism($authIdentifier);
129
+
130
+        if (!Filesystem::isValidPath($mountPoint)) {
131
+            $output->writeln('<error>Invalid mountpoint "' . $mountPoint . '"</error>');
132
+            return 1;
133
+        }
134
+        if (is_null($storageBackend)) {
135
+            $output->writeln('<error>Storage backend with identifier "' . $storageIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>');
136
+            return 404;
137
+        }
138
+        if (is_null($authBackend)) {
139
+            $output->writeln('<error>Authentication backend with identifier "' . $authIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>');
140
+            return 404;
141
+        }
142
+        $supportedSchemes = array_keys($storageBackend->getAuthSchemes());
143
+        if (!in_array($authBackend->getScheme(), $supportedSchemes)) {
144
+            $output->writeln('<error>Authentication backend "' . $authIdentifier . '" not valid for storage backend "' . $storageIdentifier . '" (see `occ files_external:backends storage ' . $storageIdentifier . '` for possible values)</error>');
145
+            return 1;
146
+        }
147
+
148
+        $config = [];
149
+        foreach ($configInput as $configOption) {
150
+            if (!strpos($configOption, '=')) {
151
+                $output->writeln('<error>Invalid mount configuration option "' . $configOption . '"</error>');
152
+                return 1;
153
+            }
154
+            list($key, $value) = explode('=', $configOption, 2);
155
+            if (!$this->validateParam($key, $value, $storageBackend, $authBackend)) {
156
+                $output->writeln('<error>Unknown configuration for backends "' . $key . '"</error>');
157
+                return 1;
158
+            }
159
+            $config[$key] = $value;
160
+        }
161
+
162
+        $mount = new StorageConfig();
163
+        $mount->setMountPoint($mountPoint);
164
+        $mount->setBackend($storageBackend);
165
+        $mount->setAuthMechanism($authBackend);
166
+        $mount->setBackendOptions($config);
167
+
168
+        if ($user) {
169
+            if (!$this->userManager->userExists($user)) {
170
+                $output->writeln('<error>User "' . $user . '" not found</error>');
171
+                return 1;
172
+            }
173
+            $mount->setApplicableUsers([$user]);
174
+        }
175
+
176
+        if ($input->getOption('dry')) {
177
+            $this->showMount($user, $mount, $input, $output);
178
+        } else {
179
+            $this->getStorageService($user)->addStorage($mount);
180
+            if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN) {
181
+                $output->writeln('<info>Storage created with id ' . $mount->getId() . '</info>');
182
+            } else {
183
+                $output->writeln($mount->getId());
184
+            }
185
+        }
186
+        return 0;
187
+    }
188
+
189
+    private function validateParam($key, &$value, Backend $storageBackend, AuthMechanism $authBackend) {
190
+        $params = array_merge($storageBackend->getParameters(), $authBackend->getParameters());
191
+        foreach ($params as $param) {
192
+            /** @var DefinitionParameter $param */
193
+            if ($param->getName() === $key) {
194
+                if ($param->getType() === DefinitionParameter::VALUE_BOOLEAN) {
195
+                    $value = ($value === 'true');
196
+                }
197
+                return true;
198
+            }
199
+        }
200
+        return false;
201
+    }
202
+
203
+    private function showMount($user, StorageConfig $mount, InputInterface $input, OutputInterface $output) {
204
+        $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager);
205
+        $listInput = new ArrayInput([], $listCommand->getDefinition());
206
+        $listInput->setOption('output', $input->getOption('output'));
207
+        $listInput->setOption('show-password', true);
208
+        $listCommand->listMounts($user, [$mount], $listInput, $output);
209
+    }
210
+
211
+    protected function getStorageService($userId) {
212
+        if (!empty($userId)) {
213
+            $user = $this->userManager->get($userId);
214
+            if (is_null($user)) {
215
+                throw new NoUserException("user $userId not found");
216
+            }
217
+            $this->userSession->setUser($user);
218
+            return $this->userService;
219
+        } else {
220
+            return $this->globalService;
221
+        }
222
+    }
223 223
 }
Please login to merge, or discard this patch.