Completed
Push — stable8.2 ( 3b3780...cb9d0b )
by Lukas
29s
created

EncryptionWrapper::wrapStorage()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 47
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 47
rs 8.5125
cc 5
eloc 38
nc 3
nop 3
1
<?php
2
/**
3
 * @author Björn Schießle <[email protected]>
4
 *
5
 * @copyright Copyright (c) 2016, ownCloud, Inc.
6
 * @license AGPL-3.0
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
22
23
namespace OC\Encryption;
24
25
26
use OC\Memcache\ArrayCache;
27
use OC\Files\Filesystem;
28
use OC\Files\Storage\Wrapper\Encryption;
29
use OCP\Files\Mount\IMountPoint;
30
use OC\Files\View;
31
use OCP\Files\Storage;
32
use OCP\ILogger;
33
34
/**
35
 * Class EncryptionWrapper
36
 *
37
 * applies the encryption storage wrapper
38
 *
39
 * @package OC\Encryption
40
 */
41
class EncryptionWrapper {
42
43
	/** @var ArrayCache  */
44
	private $arrayCache;
45
46
	/** @var  Manager */
47
	private $manager;
48
49
	/** @var  ILogger */
50
	private $logger;
51
52
	/**
53
	 * EncryptionWrapper constructor.
54
	 *
55
	 * @param ArrayCache $arrayCache
56
	 * @param Manager $manager
57
	 * @param ILogger $logger
58
	 */
59
	public function __construct(ArrayCache $arrayCache,
60
								Manager $manager,
61
								ILogger $logger
62
	) {
63
		$this->arrayCache = $arrayCache;
64
		$this->manager = $manager;
65
		$this->logger = $logger;
66
	}
67
68
	/**
69
	 * Wraps the given storage when it is not a shared storage
70
	 *
71
	 * @param string $mountPoint
72
	 * @param Storage $storage
73
	 * @param IMountPoint $mount
74
	 * @return Encryption|Storage
75
	 */
76
	public function wrapStorage($mountPoint, Storage $storage, IMountPoint $mount) {
77
		$parameters = [
78
			'storage' => $storage,
79
			'mountPoint' => $mountPoint,
80
			'mount' => $mount
81
		];
82
83
		if (!$storage->instanceOfStorage('OC\Files\Storage\Shared')
84
			&& !$storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')
85
			&& !$storage->instanceOfStorage('OC\Files\Storage\OwnCloud')) {
86
87
			$user = \OC::$server->getUserSession()->getUser();
88
			$mountManager = Filesystem::getMountManager();
89
			$uid = $user ? $user->getUID() : null;
90
			$fileHelper = \OC::$server->getEncryptionFilesHelper();
91
			$keyStorage = \OC::$server->getEncryptionKeyStorage();
92
93
			$util = new Util(
94
				new View(),
95
				\OC::$server->getUserManager(),
96
				\OC::$server->getGroupManager(),
97
				\OC::$server->getConfig()
98
			);
99
			$update = new Update(
100
				new View(),
101
				$util,
102
				Filesystem::getMountManager(),
103
				$this->manager,
104
				$fileHelper,
105
				$uid
106
			);
107
			return new Encryption(
108
				$parameters,
109
				$this->manager,
110
				$util,
111
				$this->logger,
112
				$fileHelper,
113
				$uid,
114
				$keyStorage,
115
				$update,
116
				$mountManager,
117
				$this->arrayCache
118
			);
119
		} else {
120
			return $storage;
121
		}
122
	}
123
124
}
125