Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Exoscale adapter #99

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
74 changes: 74 additions & 0 deletions src/Storage/Device/Exoscale.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace Utopia\Storage\Device;

use Utopia\Storage\Storage;

class Exoscale extends S3
{
/**
* Exoscale Regions constants
*/
stnguyen90 marked this conversation as resolved.
Show resolved Hide resolved
const CH_GVA_2 = 'ch-gva-2';
const CH_DK_2 = 'ch-dk-2';
const DE_FRA_1 = 'de-fra-1';
const DE_MUC_1 = 'de-muc-1';
const AT_VIE_1 = 'at-vie-1';
const AT_VIE_2 = 'at-vie-2';
const BG_SOF_1 = 'bg-sof-1';

private $regionEndpointMap = [
self::CH_GVA_2 => 'https://sos-ch-gva-2.exo.io',
self::CH_DK_2 => 'https://sos-ch-dk-2.exo.io',
self::DE_FRA_1 => 'https://sos-de-fra-1.exo.io',
self::DE_MUC_1 => 'https://sos-de-muc-1.exo.io',
self::AT_VIE_1 => 'https://sos-at-vie-1.exo.io',
self::AT_VIE_2 => 'https://sos-at-vie-2.exo.io',
self::BG_SOF_1 => 'https://sos-bg-sof-1.exo.io',
];

/**
* Exoscale Constructor
*
* @param string $root
* @param string $apiKey
* @param string $apiSecret
* @param string $bucket
* @param string $region
* @param string $acl
*/
public function __construct(string $root, string $apiKey, string $apiSecret, string $bucket, string $region = self::CH_GVA_2, string $acl = self::ACL_PRIVATE)
{
parent::__construct($root, $apiKey, $apiSecret, $bucket, $region, $acl);

if (isset($this->regionEndpointMap[$region])) {
$this->headers['host'] = $this->regionEndpointMap[$region];
stnguyen90 marked this conversation as resolved.
Show resolved Hide resolved
} else {
throw new \InvalidArgumentException('Invalid or unsupported region');
}
}

/**
* @return string
*/
public function getName(): string
{
return 'Exoscale Storage';
}

/**
* @return string
*/
public function getDescription(): string
{
return 'Exoscale Storage';
}

/**
* @return string
*/
public function getType(): string
{
return Storage::DEVICE_EXOSCALE;
}
}
2 changes: 2 additions & 0 deletions src/Storage/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class Storage

const DEVICE_LINODE = 'linode';

const DEVICE_EXOSCALE = 'exoscale';

/**
* Devices.
*
Expand Down
36 changes: 36 additions & 0 deletions tests/Storage/Device/ExoscaleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Utopia\Tests\Storage\Device;

use Utopia\Storage\Device\Exoscale;
use Utopia\Tests\Storage\S3Base;

class ExoscaleTest extends S3Base
{
protected function init(): void
{
$this->root = '/root';
$apiKey = 'YOUR_EXOSCALE_API_KEY';
$apiSecret = 'YOUR_EXOSCALE_API_SECRET';
$bucket = 'YOUR_EXOSCALE_BUCKET';
$region = Exoscale::CH_GVA_2;
$acl = Exoscale::ACL_PRIVATE;

$this->object = new Exoscale($this->root, $apiKey, $apiSecret, $bucket, $region, $acl);
}

protected function getAdapterName(): string
{
return 'Exoscale Storage';
}

protected function getAdapterType(): string
{
return $this->object->getType();
}

protected function getAdapterDescription(): string
{
return 'Exoscale Storage';
}
}
Loading