php-s3 :: organizing env variables

This commit is contained in:
Marcelo Manzan
2017-11-14 17:33:59 -02:00
parent a155254c50
commit 50d9c111a6
+7 -6
View File
@@ -1,7 +1,8 @@
<?php <?php
$access_key = $_ENV['ACCESS_KEY']; $access_key = $_ENV['AWS_S3_ID'];
$secret_key = $_ENV['SECRET_KEY']; $secret_key = $_ENV['AWS_S3_KEY'];
$bucket = $_ENV['BUCKET']; $bucket = $_ENV['BUCKET_NAME'];
$region = $_ENV['AWS_REGION'];
$path = 'schemas'; $path = 'schemas';
if (!$access_key || !$secret_key || !$bucket) { if (!$access_key || !$secret_key || !$bucket) {
header("HTTP/1.0 501 Credentials not provided!"); header("HTTP/1.0 501 Credentials not provided!");
@@ -9,7 +10,7 @@
} }
include('amazon-s3-php/src/S3.php'); include('amazon-s3-php/src/S3.php');
$client = new S3($access_key, $secret_key, "s3-us-west-2.amazonaws.com"); $client = new S3($access_key, $secret_key, 's3-'.$region.'.amazonaws.com');
$a = (isset($_GET["action"]) ? $_GET["action"] : false); $a = (isset($_GET["action"]) ? $_GET["action"] : false);
switch ($a) { switch ($a) {
@@ -24,11 +25,11 @@
case "save": case "save":
$keyword = (isset($_GET["keyword"]) ? $_GET["keyword"] : ""); $keyword = (isset($_GET["keyword"]) ? $_GET["keyword"] : "");
$data = file_get_contents("php://input"); $data = file_get_contents("php://input");
$client->putObject($bucket, $path.'/'.$keyword, $data, array('Content-Type' => 'text/xml')); $client->putObject($bucket, $path.'/'.$keyword, $data, array('Content-Type' => 'text/xml'));
header("HTTP/1.0 201 Created"); header("HTTP/1.0 201 Created");
break; break;
case "load": case "load":
$keyword = (isset($_GET["keyword"]) ? $_GET["keyword"] : ""); $keyword = (isset($_GET["keyword"]) ? $_GET["keyword"] : "");
$file = $client->getObject($bucket, $path.'/'.$keyword); $file = $client->getObject($bucket, $path.'/'.$keyword);
if ($file->body) { if ($file->body) {
header("Content-type: text/xml"); header("Content-type: text/xml");