Skip to content
This repository was archived by the owner on Jul 22, 2023. It is now read-only.

Commit ddae75d

Browse files
authored
Merge pull request #24 from mjrider/openstack-support
Openstack support
2 parents 378a3a0 + 767b83f commit ddae75d

13 files changed

+113
-110
lines changed

.travis.yml

+4-19
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ cache:
1919

2020
jobs:
2121
include:
22-
- php: 7.3
22+
- php: 7.4
2323
name: Linting
2424
stage: lint
2525
before_install:
@@ -45,17 +45,11 @@ jobs:
4545
after_script:
4646
- echo Dummy after script
4747
- stage: test
48-
php: 7.4snapshot
49-
allow_failures: true
48+
php: 7.4
5049
- php: 7.3
5150
- php: 7.2
5251
- php: 7.1
5352
- php: 7.0
54-
- php: 5.6
55-
- php: 5.4
56-
dist: trusty
57-
58-
fast_finish: true
5953

6054
before_install:
6155
- env
@@ -64,23 +58,14 @@ before_install:
6458
- echo "extension = memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
6559

6660
install:
67-
- >
68-
if [[ ${TRAVIS_PHP_VERSION} != '5.4' ]] ; then
69-
composer global require jakub-onderka/php-parallel-lint jakub-onderka/php-console-highlighter sensiolabs/security-checker;
70-
fi
61+
- composer global require jakub-onderka/php-parallel-lint jakub-onderka/php-console-highlighter sensiolabs/security-checker;
7162
- "docker run -p 9999:9999 --name minio --rm \
7263
-e 'MINIO_ACCESS_KEY=TRAVISACCESSPHPUNIT' \
7364
-e 'MINIO_SECRET_KEY=wJalrXUtnFEMI/K7MDENG/TRAVISKEYPHPUNIT' \
7465
--detach minio/minio server /data"
7566
- "docker run -d -p 21:21 -p 30000-30009:30000-30009 -e 'PUBLICHOST=localhost' jack12816/ftpd_test"
7667

7768
script:
78-
- >
79-
if [[ ${TRAVIS_PHP_VERSION} == "5.4" ]] ; then
80-
composer remove --dev --no-update --no-interaction league/flysystem-aws-s3-v3 ;
81-
composer remove --dev --no-update --no-interaction mhetreramesh/flysystem-backblaze ;
82-
composer require --dev --no-update --no-interaction league/flysystem-aws-s3-v2 ;
83-
fi
8469
- composer install --prefer-dist
8570

8671
- "if [[ -e ~/.composer/vendor/bin/parallel-lint ]] ; then ~/.composer/vendor/bin/parallel-lint ./src ; fi"
@@ -91,6 +76,6 @@ script:
9176

9277
after_script:
9378
- >
94-
if [[ ${TRAVIS_PHP_VERSION} == "5.4" || ${TRAVIS_PHP_VERSION} == "7.2" ]] ; then
79+
if [[ ${TRAVIS_PHP_VERSION} == "7.0" || ${TRAVIS_PHP_VERSION} == "7.4" ]] ; then
9580
php ~/.ocular/ocular.phar code-coverage:upload --format=php-clover coverage.xml -vvv ;
9681
fi

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ Adapters:
3232

3333
- B2: `mhetreramesh/flysystem-backblaze`
3434
- S3: `league/flysystem-aws-s3-v3`
35-
- S3v2: `league/flysystem-aws-s3-v2`
3635

3736
Caching:
3837

composer.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
}
2020
],
2121
"require": {
22-
"php": "~5.4 | ~7.0",
22+
"php": "~7.0",
2323
"arc/web": "^1.1 || ^2.1",
2424
"league/flysystem": "^1.0",
2525
"league/flysystem-cached-adapter": "^1.0"
@@ -29,9 +29,10 @@
2929
"league/flysystem-aws-s3-v3": "1.0.23",
3030
"league/flysystem-rackspace": "1.0.5",
3131
"mhetreramesh/flysystem-backblaze": "1.1.4",
32+
"nimbusoft/flysystem-openstack-swift": "^0.3.1",
33+
"phpcompatibility/php-compatibility": "9.3.5",
3234
"phpunit/phpunit": "~4.0 | ~5.0 | ~6.0",
33-
"predis/predis": "1.1.1",
34-
"phpcompatibility/php-compatibility": "9.3.5"
35+
"predis/predis": "1.1.1"
3536
},
3637
"autoload": {
3738
"files": [
@@ -49,10 +50,10 @@
4950
"suggest": {
5051
"ext-memcached": "memcached cache support",
5152
"ext-phpredis": "phpredis cache support",
52-
"league/flysystem-aws-s3-v2": "For S3 support for php 5.4",
5353
"league/flysystem-aws-s3-v3": "For S3 support",
5454
"mhetreramesh/flysystem-backblaze": "For Backblaze support",
55-
"predis/predis": "predis cache support"
55+
"predis/predis": "predis cache support",
56+
"nimbusoft/flysystem-openstack-swift": "For openstack support"
5657
},
5758
"config": {
5859
"sort-packages": true

examples.md

-7
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ Aws:
2121
Minio:
2222
`s3://acccesstoken:secretkey@fakeregion/bucketname?endpoint=http://locationofminio:port`
2323

24-
### S3v2
25-
Aws:
26-
`s3://accesstoken:secretkey@region/bucketname`
27-
28-
Minio:
29-
`s3://acccesstoken:secretkey@fakeregion/bucketname?endpoint=http://locationofminio:port`
30-
3124
### B2
3225
`b2://exampleuser:examplekey@bucket/`
3326
no futher settings are available

phpcs.xml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?xml version="1.0"?>
22
<ruleset name="Flysystem factory">
3-
<config name="testVersion" value="5.6-7.1"/>
3+
<config name="testVersion" value="7.0-"/>
44

55
<exclude-pattern>vendor</exclude-pattern>
66
<exclude-pattern>*.js</exclude-pattern>
77
<exclude-pattern>*.css</exclude-pattern>
88

9-
<rule ref="PSR2"/>
109
<rule ref="PHPCompatibility"/>
10+
<rule ref="PSR12"/>
11+
1112
</ruleset>

src/Adapter/OpenStack.php

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
namespace MJRider\FlysystemFactory\Adapter;
4+
5+
use OpenStack\OpenStack as OpenStackClient;
6+
use Nimbusoft\Flysystem\OpenStack\SwiftAdapter;
7+
use MJRider\FlysystemFactory\Endpoint;
8+
use GuzzleHttp\MessageFormatter;
9+
10+
/**
11+
* Static factory class for creating an rackspace Adapter
12+
*/
13+
class Openstack implements AdapterFactoryInterface
14+
{
15+
use Endpoint;
16+
17+
/**
18+
* @inheritDoc
19+
*/
20+
public static function create($url)
21+
{
22+
$auth = null;
23+
$region = null;
24+
25+
if (isset($url->query->authendpoint)) {
26+
$auth = urldecode($url->query->authendpoint);
27+
unset($url->query->authendpoint);
28+
}
29+
30+
if (isset($url->query->region)) {
31+
$region = urldecode($url->query->region);
32+
unset($url->query->region);
33+
}
34+
35+
$auth = self::endpointToURL($auth);
36+
37+
$args = [
38+
'authUrl' => $auth,
39+
'user' => [
40+
'name' => urldecode($url->user),
41+
'password' => urldecode($url->pass),
42+
"domain" => [ "id" => "default" ],
43+
],
44+
'scope' => ['project' => ['id' => $url->host ]]
45+
];
46+
47+
if (!is_null($region)) {
48+
$args['region'] = $region;
49+
}
50+
51+
$options = (array) $url->query;
52+
53+
$path = \arc\path::collapse($url->path);
54+
$container = trim(\arc\path::head($path), '/');
55+
$prefix = ltrim(\arc\path::tail($path), '/');
56+
57+
$client = new OpenStackClient($args);
58+
$container = $client->objectStoreV1()->getContainer($container);
59+
60+
$adapter = new SwiftAdapter($container, $prefix);
61+
62+
return $adapter;
63+
}
64+
}

src/Adapter/Rackspace.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use OpenCloud\OpenStack;
66
use League\Flysystem\Rackspace\RackspaceAdapter;
7-
use \MJRider\FlysystemFactory\Endpoint;
7+
use MJRider\FlysystemFactory\Endpoint;
88

99
/**
1010
* Static factory class for creating an rackspace Adapter

src/Adapter/S3.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
namespace MJRider\FlysystemFactory\Adapter;
44

5-
use \arc\url as url;
6-
use \arc\path as path;
7-
use \Aws\S3\S3Client;
8-
use \League\Flysystem\AwsS3v3\AwsS3Adapter;
9-
use \MJRider\FlysystemFactory\Endpoint;
5+
use arc\url as url;
6+
use arc\path as path;
7+
use Aws\S3\S3Client;
8+
use League\Flysystem\AwsS3v3\AwsS3Adapter;
9+
use MJRider\FlysystemFactory\Endpoint;
1010

1111
class S3 implements AdapterFactoryInterface
1212
{
13-
1413
use Endpoint;
1514

1615
protected static function buildArgs($url)

src/Adapter/S3v2.php

-23
This file was deleted.

src/Endpoint.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ trait Endpoint
1717
public static function endpointToURL($endpoint)
1818
{
1919
if (strpos($endpoint, '//') === 0) {
20-
$endpoint = 'https:'.$endpoint;
20+
$endpoint = 'https:' . $endpoint;
2121
} elseif (strpos($endpoint, '://') === false) {
22-
$endpoint = 'https://'.$endpoint;
22+
$endpoint = 'https://' . $endpoint;
2323
}
2424

2525
$url = \arc\url::url($endpoint);

src/functions.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ function create($endpoint)
2424
case 's3':
2525
$adapter = Adapter\S3::create($url);
2626
break;
27-
case 's3v2':
28-
$adapter = Adapter\S3v2::create($url);
29-
break;
3027
case 'b2':
3128
$adapter = Adapter\B2::create($url);
3229
break;
@@ -43,6 +40,9 @@ function create($endpoint)
4340
case 'rackspace':
4441
$adapter = Adapter\Rackspace::create($url);
4542
break;
43+
case 'openstack':
44+
$adapter = Adapter\OpenStack::create($url);
45+
break;
4646
default:
4747
throw new \InvalidArgumentException(sprintf('Unknown scheme [%s]', $url->scheme));
4848
}

tests/Adapter/OpenStackTest.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace MJRider\FlysystemFactory\Adapter;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
class OpenStackTest extends TestCase
8+
{
9+
protected $root = '';
10+
11+
public function setup()
12+
{
13+
$this->root = getenv('TEST_OPENSTACK_LOCATION');
14+
if ($this->root === false) {
15+
$this->markTestSkipped('no openstack endpoint available, test skipped');
16+
}
17+
}
18+
19+
public function testOpenStack()
20+
{
21+
$filesystem = \MJRider\FlysystemFactory\create($this->root);
22+
$this->assertInstanceOf('\League\Flysystem\Filesystem', $filesystem);
23+
$this->assertInstanceOf('\Nimbusoft\Flysystem\OpenStack\SwiftAdapter', $filesystem->getAdapter());
24+
}
25+
}

tests/Adapter/S3v2Test.php

-41
This file was deleted.

0 commit comments

Comments
 (0)