3131
3232use OCA \Files_External \Lib \Auth \AuthMechanism ;
3333use OCA \Files_External \Lib \Backend \Backend ;
34+ use OCA \Files_External \Lib \DefinitionParameter ;
3435use OCA \Files_External \Lib \InsufficientDataForMeaningfulAnswerException ;
3536use OCA \Files_External \Lib \StorageConfig ;
3637use OCA \Files_External \NotFoundException ;
@@ -146,19 +147,19 @@ protected function validate(StorageConfig $storage) {
146147 $ mountPoint = $ storage ->getMountPoint ();
147148 if ($ mountPoint === '' ) {
148149 return new DataResponse (
149- array (
150- 'message ' => (string )$ this ->l10n ->t ('Invalid mount point ' )
151- ) ,
150+ [
151+ 'message ' => (string )$ this ->l10n ->t ('Invalid mount point ' ),
152+ ] ,
152153 Http::STATUS_UNPROCESSABLE_ENTITY
153154 );
154155 }
155156
156157 if ($ storage ->getBackendOption ('objectstore ' )) {
157158 // objectstore must not be sent from client side
158159 return new DataResponse (
159- array (
160- 'message ' => (string )$ this ->l10n ->t ('Objectstore forbidden ' )
161- ) ,
160+ [
161+ 'message ' => (string )$ this ->l10n ->t ('Objectstore forbidden ' ),
162+ ] ,
162163 Http::STATUS_UNPROCESSABLE_ENTITY
163164 );
164165 }
@@ -170,52 +171,52 @@ protected function validate(StorageConfig $storage) {
170171 if ($ backend ->checkDependencies ()) {
171172 // invalid backend
172173 return new DataResponse (
173- array (
174+ [
174175 'message ' => (string )$ this ->l10n ->t ('Invalid storage backend "%s" ' , [
175- $ backend ->getIdentifier ()
176- ])
177- ) ,
176+ $ backend ->getIdentifier (),
177+ ]),
178+ ] ,
178179 Http::STATUS_UNPROCESSABLE_ENTITY
179180 );
180181 }
181182
182183 if (!$ backend ->isVisibleFor ($ this ->service ->getVisibilityType ())) {
183184 // not permitted to use backend
184185 return new DataResponse (
185- array (
186+ [
186187 'message ' => (string )$ this ->l10n ->t ('Not permitted to use backend "%s" ' , [
187- $ backend ->getIdentifier ()
188- ])
189- ) ,
188+ $ backend ->getIdentifier (),
189+ ]),
190+ ] ,
190191 Http::STATUS_UNPROCESSABLE_ENTITY
191192 );
192193 }
193194 if (!$ authMechanism ->isVisibleFor ($ this ->service ->getVisibilityType ())) {
194195 // not permitted to use auth mechanism
195196 return new DataResponse (
196- array (
197+ [
197198 'message ' => (string )$ this ->l10n ->t ('Not permitted to use authentication mechanism "%s" ' , [
198- $ authMechanism ->getIdentifier ()
199- ])
200- ) ,
199+ $ authMechanism ->getIdentifier (),
200+ ]),
201+ ] ,
201202 Http::STATUS_UNPROCESSABLE_ENTITY
202203 );
203204 }
204205
205206 if (!$ backend ->validateStorage ($ storage )) {
206207 // unsatisfied parameters
207208 return new DataResponse (
208- array (
209- 'message ' => (string )$ this ->l10n ->t ('Unsatisfied backend parameters ' )
210- ) ,
209+ [
210+ 'message ' => (string )$ this ->l10n ->t ('Unsatisfied backend parameters ' ),
211+ ] ,
211212 Http::STATUS_UNPROCESSABLE_ENTITY
212213 );
213214 }
214215 if (!$ authMechanism ->validateStorage ($ storage )) {
215216 // unsatisfied parameters
216217 return new DataResponse (
217218 [
218- 'message ' => (string )$ this ->l10n ->t ('Unsatisfied authentication mechanism parameters ' )
219+ 'message ' => (string )$ this ->l10n ->t ('Unsatisfied authentication mechanism parameters ' ),
219220 ],
220221 Http::STATUS_UNPROCESSABLE_ENTITY
221222 );
@@ -272,7 +273,7 @@ protected function updateStorageStatus(StorageConfig &$storage, $testOnly = true
272273 // FIXME: convert storage exceptions to StorageNotAvailableException
273274 $ storage ->setStatus (
274275 StorageNotAvailableException::STATUS_ERROR ,
275- get_class ($ e ). ': ' . $ e ->getMessage ()
276+ get_class ($ e ) . ': ' . $ e ->getMessage ()
276277 );
277278 }
278279 }
@@ -283,14 +284,37 @@ protected function updateStorageStatus(StorageConfig &$storage, $testOnly = true
283284 * @return DataResponse
284285 */
285286 public function index () {
286- $ storages = $ this ->service ->getStorages ();
287+ $ storages = $ this ->formatStoragesForUI ( $ this -> service ->getStorages () );
287288
288289 return new DataResponse (
289290 $ storages ,
290291 Http::STATUS_OK
291292 );
292293 }
293294
295+ protected function formatStoragesForUI (array $ storages ): array {
296+ return array_map (function ($ storage ) {
297+ return $ this ->formatStorageForUI ($ storage );
298+ }, $ storages );
299+ }
300+
301+ protected function formatStorageForUI (StorageConfig $ storage ): StorageConfig {
302+ /** @var DefinitionParameter[] $parameters */
303+ $ parameters = array_merge ($ storage ->getBackend ()->getParameters (), $ storage ->getAuthMechanism ()->getParameters ());
304+
305+ $ options = $ storage ->getBackendOptions ();
306+ foreach ($ options as $ key => $ value ) {
307+ foreach ($ parameters as $ parameter ) {
308+ if ($ parameter ->getName () === $ key && $ parameter ->getType () === DefinitionParameter::VALUE_PASSWORD ) {
309+ $ storage ->setBackendOption ($ key , DefinitionParameter::UNMODIFIED_PLACEHOLDER );
310+ break ;
311+ }
312+ }
313+ }
314+
315+ return $ storage ;
316+ }
317+
294318 /**
295319 * Get an external storage entry.
296320 *
@@ -307,14 +331,14 @@ public function show($id, $testOnly = true) {
307331 } catch (NotFoundException $ e ) {
308332 return new DataResponse (
309333 [
310- 'message ' => (string )$ this ->l10n ->t ('Storage with ID "%d" not found ' , array ( $ id))
334+ 'message ' => (string )$ this ->l10n ->t ('Storage with ID "%d" not found ' , [ $ id]),
311335 ],
312336 Http::STATUS_NOT_FOUND
313337 );
314338 }
315339
316340 return new DataResponse (
317- $ storage ,
341+ $ this -> formatStorageForUI ( $ storage) ,
318342 Http::STATUS_OK
319343 );
320344 }
@@ -332,7 +356,7 @@ public function destroy($id) {
332356 } catch (NotFoundException $ e ) {
333357 return new DataResponse (
334358 [
335- 'message ' => (string )$ this ->l10n ->t ('Storage with ID "%d" not found ' , array ( $ id))
359+ 'message ' => (string )$ this ->l10n ->t ('Storage with ID "%d" not found ' , [ $ id]),
336360 ],
337361 Http::STATUS_NOT_FOUND
338362 );
0 commit comments