Completed
Push — master ( 5411d6...5ed052 )
by Morris
27:22 queued 13:15
created
lib/private/Files/ObjectStore/S3ConnectionTrait.php 2 patches
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -25,96 +25,96 @@
 block discarded – undo
25 25
 use Aws\S3\S3Client;
26 26
 
27 27
 trait S3ConnectionTrait {
28
-	/** @var array */
29
-	protected $params;
30
-
31
-	/** @var S3Client */
32
-	protected $connection;
33
-
34
-	/** @var string */
35
-	protected $id;
36
-
37
-	/** @var string */
38
-	protected $bucket;
39
-
40
-	/** @var int */
41
-	protected $timeout;
42
-
43
-	protected $test;
44
-
45
-	protected function parseParams($params) {
46
-		if (empty($params['key']) || empty($params['secret']) || empty($params['bucket'])) {
47
-			throw new \Exception("Access Key, Secret and Bucket have to be configured.");
48
-		}
49
-
50
-		$this->id = 'amazon::' . $params['bucket'];
51
-
52
-		$this->test = isset($params['test']);
53
-		$this->bucket = $params['bucket'];
54
-		$this->timeout = (!isset($params['timeout'])) ? 15 : $params['timeout'];
55
-		$params['region'] = empty($params['region']) ? 'eu-west-1' : $params['region'];
56
-		$params['hostname'] = empty($params['hostname']) ? 's3.' . $params['region'] . '.amazonaws.com' : $params['hostname'];
57
-		if (!isset($params['port']) || $params['port'] === '') {
58
-			$params['port'] = (isset($params['use_ssl']) && $params['use_ssl'] === false) ? 80 : 443;
59
-		}
60
-		$this->params = $params;
61
-	}
62
-
63
-
64
-	/**
65
-	 * Returns the connection
66
-	 *
67
-	 * @return S3Client connected client
68
-	 * @throws \Exception if connection could not be made
69
-	 */
70
-	protected function getConnection() {
71
-		if (!is_null($this->connection)) {
72
-			return $this->connection;
73
-		}
74
-
75
-		$scheme = (isset($this->params['use_ssl']) && $this->params['use_ssl'] === false) ? 'http' : 'https';
76
-		$base_url = $scheme . '://' . $this->params['hostname'] . ':' . $this->params['port'] . '/';
77
-
78
-		$options = [
79
-			'version' => isset($this->params['version']) ? $this->params['version'] : 'latest',
80
-			'credentials' => [
81
-				'key' => $this->params['key'],
82
-				'secret' => $this->params['secret'],
83
-			],
84
-			'endpoint' => $base_url,
85
-			'region' => $this->params['region'],
86
-			'use_path_style_endpoint' => isset($this->params['use_path_style']) ? $this->params['use_path_style'] : false
87
-		];
88
-		if (isset($this->params['proxy'])) {
89
-			$options['request.options'] = ['proxy' => $this->params['proxy']];
90
-		}
91
-		$this->connection = new S3Client($options);
92
-
93
-		if (!$this->connection->isBucketDnsCompatible($this->bucket)) {
94
-			throw new \Exception("The configured bucket name is invalid: " . $this->bucket);
95
-		}
96
-
97
-		if (!$this->connection->doesBucketExist($this->bucket)) {
98
-			try {
99
-				$this->connection->createBucket(array(
100
-					'Bucket' => $this->bucket
101
-				));
102
-				$this->testTimeout();
103
-			} catch (S3Exception $e) {
104
-				\OCP\Util::logException('files_external', $e);
105
-				throw new \Exception('Creation of bucket failed. ' . $e->getMessage());
106
-			}
107
-		}
108
-
109
-		return $this->connection;
110
-	}
111
-
112
-	/**
113
-	 * when running the tests wait to let the buckets catch up
114
-	 */
115
-	private function testTimeout() {
116
-		if ($this->test) {
117
-			sleep($this->timeout);
118
-		}
119
-	}
28
+    /** @var array */
29
+    protected $params;
30
+
31
+    /** @var S3Client */
32
+    protected $connection;
33
+
34
+    /** @var string */
35
+    protected $id;
36
+
37
+    /** @var string */
38
+    protected $bucket;
39
+
40
+    /** @var int */
41
+    protected $timeout;
42
+
43
+    protected $test;
44
+
45
+    protected function parseParams($params) {
46
+        if (empty($params['key']) || empty($params['secret']) || empty($params['bucket'])) {
47
+            throw new \Exception("Access Key, Secret and Bucket have to be configured.");
48
+        }
49
+
50
+        $this->id = 'amazon::' . $params['bucket'];
51
+
52
+        $this->test = isset($params['test']);
53
+        $this->bucket = $params['bucket'];
54
+        $this->timeout = (!isset($params['timeout'])) ? 15 : $params['timeout'];
55
+        $params['region'] = empty($params['region']) ? 'eu-west-1' : $params['region'];
56
+        $params['hostname'] = empty($params['hostname']) ? 's3.' . $params['region'] . '.amazonaws.com' : $params['hostname'];
57
+        if (!isset($params['port']) || $params['port'] === '') {
58
+            $params['port'] = (isset($params['use_ssl']) && $params['use_ssl'] === false) ? 80 : 443;
59
+        }
60
+        $this->params = $params;
61
+    }
62
+
63
+
64
+    /**
65
+     * Returns the connection
66
+     *
67
+     * @return S3Client connected client
68
+     * @throws \Exception if connection could not be made
69
+     */
70
+    protected function getConnection() {
71
+        if (!is_null($this->connection)) {
72
+            return $this->connection;
73
+        }
74
+
75
+        $scheme = (isset($this->params['use_ssl']) && $this->params['use_ssl'] === false) ? 'http' : 'https';
76
+        $base_url = $scheme . '://' . $this->params['hostname'] . ':' . $this->params['port'] . '/';
77
+
78
+        $options = [
79
+            'version' => isset($this->params['version']) ? $this->params['version'] : 'latest',
80
+            'credentials' => [
81
+                'key' => $this->params['key'],
82
+                'secret' => $this->params['secret'],
83
+            ],
84
+            'endpoint' => $base_url,
85
+            'region' => $this->params['region'],
86
+            'use_path_style_endpoint' => isset($this->params['use_path_style']) ? $this->params['use_path_style'] : false
87
+        ];
88
+        if (isset($this->params['proxy'])) {
89
+            $options['request.options'] = ['proxy' => $this->params['proxy']];
90
+        }
91
+        $this->connection = new S3Client($options);
92
+
93
+        if (!$this->connection->isBucketDnsCompatible($this->bucket)) {
94
+            throw new \Exception("The configured bucket name is invalid: " . $this->bucket);
95
+        }
96
+
97
+        if (!$this->connection->doesBucketExist($this->bucket)) {
98
+            try {
99
+                $this->connection->createBucket(array(
100
+                    'Bucket' => $this->bucket
101
+                ));
102
+                $this->testTimeout();
103
+            } catch (S3Exception $e) {
104
+                \OCP\Util::logException('files_external', $e);
105
+                throw new \Exception('Creation of bucket failed. ' . $e->getMessage());
106
+            }
107
+        }
108
+
109
+        return $this->connection;
110
+    }
111
+
112
+    /**
113
+     * when running the tests wait to let the buckets catch up
114
+     */
115
+    private function testTimeout() {
116
+        if ($this->test) {
117
+            sleep($this->timeout);
118
+        }
119
+    }
120 120
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -47,13 +47,13 @@  discard block
 block discarded – undo
47 47
 			throw new \Exception("Access Key, Secret and Bucket have to be configured.");
48 48
 		}
49 49
 
50
-		$this->id = 'amazon::' . $params['bucket'];
50
+		$this->id = 'amazon::'.$params['bucket'];
51 51
 
52 52
 		$this->test = isset($params['test']);
53 53
 		$this->bucket = $params['bucket'];
54 54
 		$this->timeout = (!isset($params['timeout'])) ? 15 : $params['timeout'];
55 55
 		$params['region'] = empty($params['region']) ? 'eu-west-1' : $params['region'];
56
-		$params['hostname'] = empty($params['hostname']) ? 's3.' . $params['region'] . '.amazonaws.com' : $params['hostname'];
56
+		$params['hostname'] = empty($params['hostname']) ? 's3.'.$params['region'].'.amazonaws.com' : $params['hostname'];
57 57
 		if (!isset($params['port']) || $params['port'] === '') {
58 58
 			$params['port'] = (isset($params['use_ssl']) && $params['use_ssl'] === false) ? 80 : 443;
59 59
 		}
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 		}
74 74
 
75 75
 		$scheme = (isset($this->params['use_ssl']) && $this->params['use_ssl'] === false) ? 'http' : 'https';
76
-		$base_url = $scheme . '://' . $this->params['hostname'] . ':' . $this->params['port'] . '/';
76
+		$base_url = $scheme.'://'.$this->params['hostname'].':'.$this->params['port'].'/';
77 77
 
78 78
 		$options = [
79 79
 			'version' => isset($this->params['version']) ? $this->params['version'] : 'latest',
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 		$this->connection = new S3Client($options);
92 92
 
93 93
 		if (!$this->connection->isBucketDnsCompatible($this->bucket)) {
94
-			throw new \Exception("The configured bucket name is invalid: " . $this->bucket);
94
+			throw new \Exception("The configured bucket name is invalid: ".$this->bucket);
95 95
 		}
96 96
 
97 97
 		if (!$this->connection->doesBucketExist($this->bucket)) {
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 				$this->testTimeout();
103 103
 			} catch (S3Exception $e) {
104 104
 				\OCP\Util::logException('files_external', $e);
105
-				throw new \Exception('Creation of bucket failed. ' . $e->getMessage());
105
+				throw new \Exception('Creation of bucket failed. '.$e->getMessage());
106 106
 			}
107 107
 		}
108 108
 
Please login to merge, or discard this patch.