S3 proxy cache support + 1 minor analyzer bugfix

This commit is contained in:
Albert Santoni 2015-03-26 12:08:52 -04:00
parent 99d16444d2
commit 271dc266fa
2 changed files with 43 additions and 6 deletions

View File

@ -9,20 +9,33 @@ class Amazon_S3StorageBackend extends StorageBackend
{
private $s3Client;
private $proxyHost;
public function Amazon_S3StorageBackend($securityCredentials)
{
$this->setBucket($securityCredentials['bucket']);
$this->setAccessKey($securityCredentials['api_key']);
$this->setSecretKey($securityCredentials['api_key_secret']);
$this->s3Client = S3Client::factory(array(
$s3Options = array(
'key' => $securityCredentials['api_key'],
'secret' => $securityCredentials['api_key_secret'],
'region' => $securityCredentials['region']
));
}
);
if (array_key_exists("proxy_host", $securityCredentials)) {
$s3Options = array_merge($s3Options, array(
//'base_url' => "http://" . $securityCredentials['proxy_host'],
'base_url' => "http://s3.amazonaws.com",
'scheme' => "http",
//'force_path_style' => true,
'signature' => 'v4'
));
$this->proxyHost = $securityCredentials['proxy_host'];
}
$this->s3Client = S3Client::factory($s3Options);
}
public function getAbsoluteFilePath($resourceId)
{
return $this->s3Client->getObjectUrl($this->getBucket(), $resourceId);
@ -30,9 +43,32 @@ class Amazon_S3StorageBackend extends StorageBackend
public function getSignedURL($resourceId)
{
return $this->s3Client->getObjectUrl($this->getBucket(), $resourceId, '+60 minutes');
$url = $this->s3Client->getObjectUrl($this->getBucket(), $resourceId, '+60 minutes');
//If we're using the proxy cache, we need to modify the request URL after it has
//been generated by the above. (The request signature must be for the amazonaws.com,
//not our proxy, since the proxy translates the host back to amazonaws.com)
if ($this->proxyHost) {
$p = parse_url($url);
$p["host"] = $this->getBucket() . "." . $this->proxyHost;
$p["scheme"] = "http";
//If the path contains the bucket name (which is the case with HTTPS requests to Amazon),
//we need to strip that part out, since we're forcing everything to HTTP. The Amazon S3
//URL convention for HTTP is to prepend the bucket name to the hostname instead of having
//it in the path.
//eg. http://bucket.s3.amazonaws.com/ instead of https://s3.amazonaws.com/bucket/
if (strpos($p["path"], $this->getBucket()) == 1) {
$p["path"] = substr($p["path"], 1 + strlen($this->getBucket()));
}
$url = $p["scheme"] . "://" . $p["host"] . $p["path"] . "?" . $p["query"];
}
//http_build_url() would be nice to use but it requires pecl_http :-(
Logging::info($url);
return $url;
}
public function deletePhysicalFile($resourceId)
{
$bucket = $this->getBucket();

View File

@ -226,6 +226,7 @@ class MessageListener:
else:
raise Exception("Analyzer process terminated unexpectedly.")
'''
results = {}
q = Queue.Queue()
try: