-
Notifications
You must be signed in to change notification settings - Fork 576
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Glide cloud sources to allow Glide and S3 integration
- Loading branch information
Showing
3 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace A17\Twill\Services\Cloud; | ||
|
||
use Aws\S3\S3Client; | ||
use Illuminate\Support\Str; | ||
use League\Flysystem\Filesystem; | ||
use League\Flysystem\AwsS3v3\AwsS3Adapter; | ||
|
||
class Aws | ||
{ | ||
public function filesystemFactory($source) | ||
{ | ||
$config = $this->getConfigFor($source); | ||
|
||
$client = new S3Client($config); | ||
|
||
$adapter = new AwsS3Adapter($client, $config['bucket'], $config['root']); | ||
|
||
return new Filesystem($adapter); | ||
} | ||
|
||
public function getConfigFor($disk) | ||
{ | ||
return [ | ||
'credentials' => [ | ||
'key' => $this->config($disk, 'key'), | ||
|
||
'secret' => $this->config($disk, 'secret'), | ||
], | ||
|
||
'region' => $this->config($disk, 'region'), | ||
|
||
'root' => $this->config($disk, 'root', ''), | ||
|
||
'bucket' => $this->config($disk, 'bucket'), | ||
|
||
'version' => $this->config($disk, 'version', 'latest'), | ||
]; | ||
} | ||
|
||
public function config($disk, $key, $default = null) | ||
{ | ||
$env1 = Str::upper(Str::snake($disk)); | ||
|
||
$env2 = $env1 === 'AWS' ? 'S3' : 'AWS'; | ||
|
||
$envSuffix = Str::upper($key); | ||
|
||
if (filled($value = config("filesystems.disks.{$disk}.{$key}"))) { | ||
return $value; | ||
} | ||
|
||
return env("{$env1}_{$envSuffix}", env("{$env2}_{$envSuffix}", $default)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace A17\Twill\Services\Cloud; | ||
|
||
use Exception; | ||
|
||
class Azure | ||
{ | ||
public function filesystemFactory($prefix) | ||
{ | ||
throw new Exception('Azure is not implemented yey.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace A17\Twill\Services\Cloud; | ||
|
||
use Exception; | ||
|
||
class Glide | ||
{ | ||
function makeCloudSource($source = null) | ||
{ | ||
if (blank($source)) { | ||
throw new Exception( | ||
'Glide source was not set, please set your GLIDE_SOURCE environment variable or pass the source.' | ||
); | ||
} | ||
|
||
if ($source == 's3' || $source == 'aws') { | ||
return app(Aws::class)->filesystemFactory($source); | ||
} | ||
|
||
if ($source == 'azure') { | ||
return app(Azure::class)->filesystemFactory($source); | ||
} | ||
|
||
return $source; | ||
} | ||
} |
11f0f50
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can I make Glide use S3 actually?
I have my disks like this:
's3_private' = [], 's3_public' = []
and my default disk is 's3_private'
The implementation makes me thing that you expect the user to have an 's3' disk defined in config/filesystems.php?
Should Twill have a config telling it's cloud to be used for Glide and the GLIDE_SOURCE to be given the disk to use?