diff options
author | Robin Appelman <robin@icewind.nl> | 2018-06-04 14:17:49 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2018-06-04 16:18:03 +0200 |
commit | ac26175a178aab3bcf989387adc92af36c19afa5 (patch) | |
tree | 3b79887a1df50f67bcba043929a39eccf42244d0 /lib/private | |
parent | 3f82ed377cd3b951d760c28b3c8e4cb9cd21b39c (diff) | |
download | nextcloud-server-ac26175a178aab3bcf989387adc92af36c19afa5.tar.gz nextcloud-server-ac26175a178aab3bcf989387adc92af36c19afa5.zip |
add azure unit tests with azurite
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Files/ObjectStore/Azure.php | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/lib/private/Files/ObjectStore/Azure.php b/lib/private/Files/ObjectStore/Azure.php index 0868f92eac8..899c826ec19 100644 --- a/lib/private/Files/ObjectStore/Azure.php +++ b/lib/private/Files/ObjectStore/Azure.php @@ -22,6 +22,7 @@ namespace OC\Files\ObjectStore; use MicrosoftAzure\Storage\Blob\BlobRestProxy; +use MicrosoftAzure\Storage\Common\Exceptions\ServiceException; use OCP\Files\ObjectStore\IObjectStore; class Azure implements IObjectStore { @@ -33,6 +34,10 @@ class Azure implements IObjectStore { private $accountKey; /** @var BlobRestProxy|null */ private $blobClient = null; + /** @var string|null */ + private $endpoint = null; + /** @var bool */ + private $autoCreate = false; /** * @param array $parameters @@ -41,6 +46,12 @@ class Azure implements IObjectStore { $this->containerName = $parameters['container']; $this->accountName = $parameters['account_name']; $this->accountKey = $parameters['account_key']; + if (isset($parameters['endpoint'])) { + $this->endpoint = $parameters['endpoint']; + } + if (isset($parameters['autocreate'])) { + $this->autoCreate = $parameters['autocreate']; + } } /** @@ -48,8 +59,24 @@ class Azure implements IObjectStore { */ private function getBlobClient() { if (!$this->blobClient) { - $connectionString = "DefaultEndpointsProtocol=https;AccountName=" . $this->accountName . ";AccountKey=" . $this->accountKey; + $protocol = $this->endpoint ? substr($this->endpoint, 0, strpos($this->endpoint, ':')) : 'https'; + $connectionString = "DefaultEndpointsProtocol=" . $protocol . ";AccountName=" . $this->accountName . ";AccountKey=" . $this->accountKey; + if ($this->endpoint) { + $connectionString .= ';BlobEndpoint=' . $this->endpoint; + } $this->blobClient = BlobRestProxy::createBlobService($connectionString); + + if ($this->autoCreate) { + try { + $this->blobClient->createContainer($this->containerName); + } catch (ServiceException $e) { + if ($e->getCode() === 409) { + // already exists + } else { + throw $e; + } + } + } } return $this->blobClient; } |