diff options
author | Ondřej Žára <ondras@zarovi.cz> | 2017-11-15 20:16:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-15 20:16:20 +0100 |
commit | c4548249be5b2e656681bfef4d58eedce359df08 (patch) | |
tree | 112480cbe7c66dae0632e1bf9955e3f196e738fc | |
parent | 48913bf78706f5926f8169906d79618ffcbd1299 (diff) | |
parent | 839550377dea29d23c608c9fcf3e1dfcbca45705 (diff) | |
download | wwwsqldesigner-master.zip wwwsqldesigner-master.tar.gz wwwsqldesigner-master.tar.bz2 |
Merge pull request #262 from truckpad/masterHEADorigin/masterorigin/HEADmaster
Support for S3 bucket backend
-rw-r--r-- | .gitmodules | 3 | ||||
m--------- | backend/php-s3/amazon-s3-php | 0 | ||||
-rw-r--r-- | backend/php-s3/index.php | 43 | ||||
-rw-r--r-- | js/config.js | 2 |
4 files changed, 47 insertions, 1 deletions
diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b7d3f0f --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "backend/php-s3/amazon-s3-php"] + path = backend/php-s3/amazon-s3-php + url = https://github.com/ericnorris/amazon-s3-php.git diff --git a/backend/php-s3/amazon-s3-php b/backend/php-s3/amazon-s3-php new file mode 160000 +Subproject bfc42ea0c0b0aac3484f0a9fbc3e9975d730d08 diff --git a/backend/php-s3/index.php b/backend/php-s3/index.php new file mode 100644 index 0000000..1839320 --- /dev/null +++ b/backend/php-s3/index.php @@ -0,0 +1,43 @@ +<?php + $access_key = $_ENV['AWS_S3_ID']; + $secret_key = $_ENV['AWS_S3_KEY']; + $bucket = $_ENV['BUCKET_NAME']; + $region = $_ENV['AWS_REGION']; + $path = 'schemas'; + if (!$access_key || !$secret_key || !$bucket) { + header("HTTP/1.0 501 Credentials not provided!"); + return; + } + + include('amazon-s3-php/src/S3.php'); + $client = new S3($access_key, $secret_key, 's3-'.$region.'.amazonaws.com'); + + $a = (isset($_GET["action"]) ? $_GET["action"] : false); + switch ($a) { + case "list": + $response = $client->getBucket($bucket); + foreach ($response->body->Contents as $content) { + $key = $content->Key; + if (0 === strpos($key, $path.'/') && $key != $path.'/') + echo substr($key, strlen($path)+1)."\n"; + } + break; + case "save": + $keyword = (isset($_GET["keyword"]) ? $_GET["keyword"] : ""); + $data = file_get_contents("php://input"); + $client->putObject($bucket, $path.'/'.$keyword, $data, array('Content-Type' => 'text/xml')); + header("HTTP/1.0 201 Created"); + break; + case "load": + $keyword = (isset($_GET["keyword"]) ? $_GET["keyword"] : ""); + $file = $client->getObject($bucket, $path.'/'.$keyword); + if ($file->body) { + header("Content-type: text/xml"); + echo $file->body; + } else { + header("HTTP/1.0 404 Not Found"); + } + break; + default: header("HTTP/1.0 501 Not Implemented"); + } +?> diff --git a/js/config.js b/js/config.js index 90ec791..20af61c 100644 --- a/js/config.js +++ b/js/config.js @@ -5,7 +5,7 @@ var CONFIG = { AVAILABLE_LOCALES: ["ar", "cs", "de", "el", "en", "eo", "es", "fr", "hu", "it", "ja", "ko", "nl", "pl", "pt_BR", "ro", "ru", "sv", "zh"], DEFAULT_LOCALE: "en", - AVAILABLE_BACKENDS: ["php-mysql", "php-blank", "php-file", "php-sqlite", "php-mysql+file", "php-postgresql", "php-pdo", "perl-file", "php-cubrid", "asp-file", "web2py"], + AVAILABLE_BACKENDS: ["php-mysql", "php-s3", "php-blank", "php-file", "php-sqlite", "php-mysql+file", "php-postgresql", "php-pdo", "perl-file", "php-cubrid", "asp-file", "web2py"], DEFAULT_BACKEND: ["php-mysql"], RELATION_THICKNESS: 2, |