Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/engine/PhabricatorS3FileStorageEngine.php
Show All 19 Lines | public function getEngineIdentifier() { | ||||
return 'amazon-s3'; | return 'amazon-s3'; | ||||
} | } | ||||
public function getEnginePriority() { | public function getEnginePriority() { | ||||
return 100; | return 100; | ||||
} | } | ||||
public function canWriteFiles() { | public function canWriteFiles() { | ||||
$bucket = PhabricatorEnv::getEnvConfig('storage.s3.bucket'); | $bucket = PhabricatorEnv::getEnvConfigStr('storage.s3.bucket'); | ||||
$access_key = PhabricatorEnv::getEnvConfig('amazon-s3.access-key'); | $access_key = PhabricatorEnv::getEnvConfigStr('amazon-s3.access-key'); | ||||
$secret_key = PhabricatorEnv::getEnvConfig('amazon-s3.secret-key'); | $secret_key = PhabricatorEnv::getEnvConfigStr('amazon-s3.secret-key'); | ||||
$endpoint = PhabricatorEnv::getEnvConfig('amazon-s3.endpoint'); | $endpoint = PhabricatorEnv::getEnvConfigStr('amazon-s3.endpoint'); | ||||
$region = PhabricatorEnv::getEnvConfig('amazon-s3.region'); | $region = PhabricatorEnv::getEnvConfigStr('amazon-s3.region'); | ||||
return (strlen($bucket) && | return $bucket !== '' && | ||||
strlen($access_key) && | $access_key !== '' && | ||||
strlen($secret_key) && | $secret_key !== '' && | ||||
strlen($endpoint) && | $endpoint !== '' && | ||||
strlen($region)); | $region !== ''; | ||||
valerio.bozzolan: ↑ I also removed the parentheses since they were totally usefulness and just an additional risk… | |||||
} | } | ||||
/* -( Managing File Data )------------------------------------------------- */ | /* -( Managing File Data )------------------------------------------------- */ | ||||
/** | /** | ||||
* Writes file data into Amazon S3. | * Writes file data into Amazon S3. | ||||
*/ | */ | ||||
public function writeFile($data, array $params) { | public function writeFile($data, array $params) { | ||||
$s3 = $this->newS3API(); | $s3 = $this->newS3API(); | ||||
// Generate a random name for this file. We add some directories to it | // Generate a random name for this file. We add some directories to it | ||||
// (e.g. 'abcdef123456' becomes 'ab/cd/ef123456') to make large numbers of | // (e.g. 'abcdef123456' becomes 'ab/cd/ef123456') to make large numbers of | ||||
// files more browsable with web/debugging tools like the S3 administration | // files more browsable with web/debugging tools like the S3 administration | ||||
// tool. | // tool. | ||||
$seed = Filesystem::readRandomCharacters(20); | $seed = Filesystem::readRandomCharacters(20); | ||||
$parts = array(); | $parts = array(); | ||||
$parts[] = 'phabricator'; | $parts[] = 'phabricator'; | ||||
$instance_name = PhabricatorEnv::getEnvConfig('cluster.instance'); | $instance_name = PhabricatorEnv::getEnvConfigStr('cluster.instance'); | ||||
if (strlen($instance_name)) { | if ($instance_name !== '') { | ||||
$parts[] = $instance_name; | $parts[] = $instance_name; | ||||
} | } | ||||
$parts[] = substr($seed, 0, 2); | $parts[] = substr($seed, 0, 2); | ||||
$parts[] = substr($seed, 2, 2); | $parts[] = substr($seed, 2, 2); | ||||
$parts[] = substr($seed, 4); | $parts[] = substr($seed, 4); | ||||
$name = implode('/', $parts); | $name = implode('/', $parts); | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | /* -( Internals )---------------------------------------------------------- */ | ||||
/** | /** | ||||
* Retrieve the S3 bucket name. | * Retrieve the S3 bucket name. | ||||
* | * | ||||
* @task internal | * @task internal | ||||
*/ | */ | ||||
private function getBucketName() { | private function getBucketName() { | ||||
$bucket = PhabricatorEnv::getEnvConfig('storage.s3.bucket'); | $bucket = PhabricatorEnv::getEnvConfigStr('storage.s3.bucket'); | ||||
if (!$bucket) { | if (!$bucket) { | ||||
throw new PhabricatorFileStorageConfigurationException( | throw new PhabricatorFileStorageConfigurationException( | ||||
pht( | pht( | ||||
"No '%s' specified!", | "No '%s' specified!", | ||||
'storage.s3.bucket')); | 'storage.s3.bucket')); | ||||
} | } | ||||
return $bucket; | return $bucket; | ||||
} | } | ||||
/** | /** | ||||
* Create a new S3 API object. | * Create a new S3 API object. | ||||
* | * | ||||
* @task internal | * @task internal | ||||
*/ | */ | ||||
private function newS3API() { | private function newS3API() { | ||||
$access_key = PhabricatorEnv::getEnvConfig('amazon-s3.access-key'); | $access_key = PhabricatorEnv::getEnvConfigStr('amazon-s3.access-key'); | ||||
$secret_key = PhabricatorEnv::getEnvConfig('amazon-s3.secret-key'); | $secret_key = PhabricatorEnv::getEnvConfigStr('amazon-s3.secret-key'); | ||||
$region = PhabricatorEnv::getEnvConfig('amazon-s3.region'); | $region = PhabricatorEnv::getEnvConfigStr('amazon-s3.region'); | ||||
$endpoint = PhabricatorEnv::getEnvConfig('amazon-s3.endpoint'); | $endpoint = PhabricatorEnv::getEnvConfigStr('amazon-s3.endpoint'); | ||||
return id(new PhutilAWSS3Future()) | return id(new PhutilAWSS3Future()) | ||||
->setAccessKey($access_key) | ->setAccessKey($access_key) | ||||
->setSecretKey(new PhutilOpaqueEnvelope($secret_key)) | ->setSecretKey(new PhutilOpaqueEnvelope($secret_key)) | ||||
->setRegion($region) | ->setRegion($region) | ||||
->setEndpoint($endpoint) | ->setEndpoint($endpoint) | ||||
->setBucket($this->getBucketName()); | ->setBucket($this->getBucketName()); | ||||
} | } | ||||
} | } |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0
↑ I also removed the parentheses since they were totally usefulness and just an additional risk to make typos in the last line.