Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/engine/PhabricatorS3FileStorageEngine.php
Show All 25 Lines | /* -( Engine Metadata )---------------------------------------------------- */ | ||||
public function canWriteFiles() { | public function canWriteFiles() { | ||||
$bucket = PhabricatorEnv::getEnvConfig('storage.s3.bucket'); | $bucket = PhabricatorEnv::getEnvConfig('storage.s3.bucket'); | ||||
$access_key = PhabricatorEnv::getEnvConfig('amazon-s3.access-key'); | $access_key = PhabricatorEnv::getEnvConfig('amazon-s3.access-key'); | ||||
$secret_key = PhabricatorEnv::getEnvConfig('amazon-s3.secret-key'); | $secret_key = PhabricatorEnv::getEnvConfig('amazon-s3.secret-key'); | ||||
$endpoint = PhabricatorEnv::getEnvConfig('amazon-s3.endpoint'); | $endpoint = PhabricatorEnv::getEnvConfig('amazon-s3.endpoint'); | ||||
$region = PhabricatorEnv::getEnvConfig('amazon-s3.region'); | $region = PhabricatorEnv::getEnvConfig('amazon-s3.region'); | ||||
return (strlen($bucket) && | return phutil_nonempty_string($bucket) && | ||||
strlen($access_key) && | phutil_nonempty_string($access_key) && | ||||
strlen($secret_key) && | phutil_nonempty_string($secret_key) && | ||||
strlen($endpoint) && | phutil_nonempty_string($endpoint) && | ||||
strlen($region)); | phutil_nonempty_string($region); | ||||
} | } | ||||
/* -( 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::getEnvConfig('cluster.instance'); | ||||
if (strlen($instance_name)) { | if (phutil_nonempty_string($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 103 Lines • Show Last 20 Lines |
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