diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..117b490 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +Changelog +========== + +v1.2.0 +------ +- HTTPS support for input & output urls. + +Breaking changes: + +- Upgraded to AWS SDK v3.17.5. The AWS S3 client now requires an aws region, you have to define 's3Region' property +in the ShellCommand's 'customData'. Note this is only required if your input or output urls relies on S3. diff --git a/README.md b/README.md index 47b1ef1..8048066 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,7 @@ This code is not expected to accept arbitrary user input. If you create a ShellC The reason we don't do this in ShellCommand is that escapeshellcmd() neuters pipes and redirection, and escapeshellarg() requires parsing which would introduce its own security risks. Therefore we just punt on security and tell you to sanitize your inputs before creating a ShellCommand. + +Changelog +========= +Read the changelog [here](CHANGELOG.md) diff --git a/composer.json b/composer.json old mode 100644 new mode 100755 index c17f96f..4a5d4cd --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ }, "require": { "php": ">=5.2.0", - "aws/aws-sdk-php": "2.7.17" + "aws/aws-sdk-php": "3.17.5" }, "require-dev": { "phpunit/phpunit": "3.7.*" diff --git a/composer.lock b/composer.lock index 223ac84..83c31af 100644 --- a/composer.lock +++ b/composer.lock @@ -1,53 +1,67 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "0bac799b91386b87833886c35ea58139", + "hash": "16879652e38628767d59bb620313631a", + "content-hash": "dd68cc5b80111b727fd2cdd6bf260ada", "packages": [ { "name": "aws/aws-sdk-php", - "version": "2.7.17", + "version": "3.17.5", "source": { "type": "git", "url": "https://github.com/aws/aws-sdk-php.git", - "reference": "eddf89846ed0f15e8e2b8cbe6d08125eaa20ad80" + "reference": "1cef9b334729b3564c9aef15481a55561c54b53f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/eddf89846ed0f15e8e2b8cbe6d08125eaa20ad80", - "reference": "eddf89846ed0f15e8e2b8cbe6d08125eaa20ad80", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/1cef9b334729b3564c9aef15481a55561c54b53f", + "reference": "1cef9b334729b3564c9aef15481a55561c54b53f", "shasum": "" }, "require": { - "guzzle/guzzle": "~3.7", - "php": ">=5.3.3" + "guzzlehttp/guzzle": "~5.3|~6.0.1|~6.1", + "guzzlehttp/promises": "~1.0", + "guzzlehttp/psr7": "~1.0", + "mtdowling/jmespath.php": "~2.2", + "php": ">=5.5" }, "require-dev": { - "doctrine/cache": "~1.0", + "andrewsville/php-token-reflection": "^1.4", + "aws/aws-php-sns-message-validator": "~1.0", + "behat/behat": "~3.0", + "doctrine/cache": "~1.4", + "ext-dom": "*", + "ext-json": "*", "ext-openssl": "*", - "monolog/monolog": "~1.4", - "phpunit/phpunit": "~4.0", - "symfony/yaml": "~2.1" + "ext-pcre": "*", + "ext-simplexml": "*", + "ext-spl": "*", + "nette/neon": "^2.3", + "phpunit/phpunit": "~4.0|~5.0", + "psr/cache": "^1.0" }, "suggest": { - "doctrine/cache": "Adds support for caching of credentials and responses", - "ext-apc": "Allows service description opcode caching, request and response caching, and credentials caching", - "ext-openssl": "Allows working with CloudFront private distributions and verifying received SNS messages", - "monolog/monolog": "Adds support for logging HTTP requests and responses", - "symfony/yaml": "Eases the ability to write manifests for creating jobs in AWS Import/Export" + "aws/aws-php-sns-message-validator": "To validate incoming SNS notifications", + "doctrine/cache": "To use the DoctrineCacheAdapter", + "ext-curl": "To send requests using cURL", + "ext-openssl": "Allows working with CloudFront private distributions and verifying received SNS messages" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.7-dev" + "dev-master": "3.0-dev" } }, "autoload": { - "psr-0": { - "Aws": "src/" - } + "psr-4": { + "Aws\\": "src/" + }, + "files": [ + "src/functions.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -71,70 +85,44 @@ "s3", "sdk" ], - "time": "2015-01-27 20:14:01" + "time": "2016-04-07 22:44:13" }, { - "name": "guzzle/guzzle", - "version": "v3.9.2", + "name": "guzzlehttp/guzzle", + "version": "6.2.0", "source": { "type": "git", - "url": "https://github.com/guzzle/guzzle3.git", - "reference": "54991459675c1a2924122afbb0e5609ade581155" + "url": "https://github.com/guzzle/guzzle.git", + "reference": "d094e337976dff9d8e2424e8485872194e768662" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle3/zipball/54991459675c1a2924122afbb0e5609ade581155", - "reference": "54991459675c1a2924122afbb0e5609ade581155", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/d094e337976dff9d8e2424e8485872194e768662", + "reference": "d094e337976dff9d8e2424e8485872194e768662", "shasum": "" }, "require": { - "ext-curl": "*", - "php": ">=5.3.3", - "symfony/event-dispatcher": "~2.1" - }, - "replace": { - "guzzle/batch": "self.version", - "guzzle/cache": "self.version", - "guzzle/common": "self.version", - "guzzle/http": "self.version", - "guzzle/inflection": "self.version", - "guzzle/iterator": "self.version", - "guzzle/log": "self.version", - "guzzle/parser": "self.version", - "guzzle/plugin": "self.version", - "guzzle/plugin-async": "self.version", - "guzzle/plugin-backoff": "self.version", - "guzzle/plugin-cache": "self.version", - "guzzle/plugin-cookie": "self.version", - "guzzle/plugin-curlauth": "self.version", - "guzzle/plugin-error-response": "self.version", - "guzzle/plugin-history": "self.version", - "guzzle/plugin-log": "self.version", - "guzzle/plugin-md5": "self.version", - "guzzle/plugin-mock": "self.version", - "guzzle/plugin-oauth": "self.version", - "guzzle/service": "self.version", - "guzzle/stream": "self.version" + "guzzlehttp/promises": "~1.0", + "guzzlehttp/psr7": "~1.1", + "php": ">=5.5.0" }, "require-dev": { - "doctrine/cache": "~1.3", - "monolog/monolog": "~1.0", - "phpunit/phpunit": "3.7.*", - "psr/log": "~1.0", - "symfony/class-loader": "~2.1", - "zendframework/zend-cache": "2.*,<2.3", - "zendframework/zend-log": "2.*,<2.3" + "ext-curl": "*", + "phpunit/phpunit": "~4.0", + "psr/log": "~1.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.9-dev" + "dev-master": "6.2-dev" } }, "autoload": { - "psr-0": { - "Guzzle": "src/", - "Guzzle\\Tests": "tests/" + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -146,13 +134,9 @@ "name": "Michael Dowling", "email": "mtdowling@gmail.com", "homepage": "https://github.com/mtdowling" - }, - { - "name": "Guzzle Community", - "homepage": "https://github.com/guzzle/guzzle/contributors" } ], - "description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients", + "description": "Guzzle is a PHP HTTP client library", "homepage": "http://guzzlephp.org/", "keywords": [ "client", @@ -163,65 +147,220 @@ "rest", "web service" ], - "time": "2014-08-11 04:32:36" + "time": "2016-03-21 20:02:09" }, { - "name": "symfony/event-dispatcher", - "version": "v2.6.3", - "target-dir": "Symfony/Component/EventDispatcher", + "name": "guzzlehttp/promises", + "version": "1.1.0", "source": { "type": "git", - "url": "https://github.com/symfony/EventDispatcher.git", - "reference": "40ff70cadea3785d83cac1c8309514b36113064e" + "url": "https://github.com/guzzle/promises.git", + "reference": "bb9024c526b22f3fe6ae55a561fd70653d470aa8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/40ff70cadea3785d83cac1c8309514b36113064e", - "reference": "40ff70cadea3785d83cac1c8309514b36113064e", + "url": "https://api.github.com/repos/guzzle/promises/zipball/bb9024c526b22f3fe6ae55a561fd70653d470aa8", + "reference": "bb9024c526b22f3fe6ae55a561fd70653d470aa8", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": ">=5.5.0" }, "require-dev": { - "psr/log": "~1.0", - "symfony/config": "~2.0,>=2.0.5", - "symfony/dependency-injection": "~2.6", - "symfony/expression-language": "~2.6", - "symfony/stopwatch": "~2.3" - }, - "suggest": { - "symfony/dependency-injection": "", - "symfony/http-kernel": "" + "phpunit/phpunit": "~4.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.6-dev" + "dev-master": "1.0-dev" } }, "autoload": { - "psr-0": { - "Symfony\\Component\\EventDispatcher\\": "" + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "time": "2016-03-08 01:15:46" + }, + { + "name": "guzzlehttp/psr7", + "version": "1.3.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "31382fef2889136415751badebbd1cb022a4ed72" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/31382fef2889136415751badebbd1cb022a4ed72", + "reference": "31382fef2889136415751badebbd1cb022a4ed72", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "psr/http-message": "~1.0" + }, + "provide": { + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" } }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { - "name": "Symfony Community", - "homepage": "http://symfony.com/contributors" + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "PSR-7 message implementation", + "keywords": [ + "http", + "message", + "stream", + "uri" + ], + "time": "2016-04-13 19:56:01" + }, + { + "name": "mtdowling/jmespath.php", + "version": "2.3.0", + "source": { + "type": "git", + "url": "https://github.com/jmespath/jmespath.php.git", + "reference": "192f93e43c2c97acde7694993ab171b3de284093" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jmespath/jmespath.php/zipball/192f93e43c2c97acde7694993ab171b3de284093", + "reference": "192f93e43c2c97acde7694993ab171b3de284093", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "bin": [ + "bin/jp.php" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "psr-4": { + "JmesPath\\": "src/" }, + "files": [ + "src/JmesPath.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" } ], - "description": "Symfony EventDispatcher Component", - "homepage": "http://symfony.com", - "time": "2015-01-05 14:28:40" + "description": "Declaratively specify how to extract elements from a JSON document", + "keywords": [ + "json", + "jsonpath" + ], + "time": "2016-01-05 18:25:05" + }, + { + "name": "psr/http-message", + "version": "1.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/85d63699f0dbedb190bbd4b0d2b9dc707ea4c298", + "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "time": "2015-05-04 20:22:00" } ], "packages-dev": [ @@ -288,31 +427,33 @@ }, { "name": "phpunit/php-file-iterator", - "version": "1.3.4", + "version": "1.4.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb" + "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/acd690379117b042d1c8af1fafd61bde001bf6bb", - "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/6150bf2c35d3fc379e50c7602b75caceaa39dbf0", + "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0", "shasum": "" }, "require": { "php": ">=5.3.3" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, "autoload": { "classmap": [ - "File/" + "src/" ] }, "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], "license": [ "BSD-3-Clause" ], @@ -329,20 +470,20 @@ "filesystem", "iterator" ], - "time": "2013-10-10 15:34:57" + "time": "2015-06-21 13:08:43" }, { "name": "phpunit/php-text-template", - "version": "1.2.0", + "version": "1.2.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a" + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", - "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", "shasum": "" }, "require": { @@ -351,20 +492,17 @@ "type": "library", "autoload": { "classmap": [ - "Text/" + "src/" ] }, "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], "license": [ "BSD-3-Clause" ], "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -373,20 +511,20 @@ "keywords": [ "template" ], - "time": "2014-01-30 17:20:04" + "time": "2015-06-21 13:50:34" }, { "name": "phpunit/php-timer", - "version": "1.0.5", + "version": "1.0.7", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c" + "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/19689d4354b295ee3d8c54b4f42c3efb69cbc17c", - "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3e82f4e9fc92665fafd9157568e4dcb01d014e5b", + "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b", "shasum": "" }, "require": { @@ -395,13 +533,10 @@ "type": "library", "autoload": { "classmap": [ - "PHP/" + "src/" ] }, "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], "license": [ "BSD-3-Clause" ], @@ -417,7 +552,7 @@ "keywords": [ "timer" ], - "time": "2013-08-02 07:42:54" + "time": "2015-06-21 08:01:12" }, { "name": "phpunit/php-token-stream", @@ -593,50 +728,52 @@ }, { "name": "symfony/yaml", - "version": "v2.6.3", - "target-dir": "Symfony/Component/Yaml", + "version": "v2.8.4", "source": { "type": "git", - "url": "https://github.com/symfony/Yaml.git", - "reference": "82462a90848a52c2533aa6b598b107d68076b018" + "url": "https://github.com/symfony/yaml.git", + "reference": "584e52cb8f788a887553ba82db6caacb1d6260bb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/82462a90848a52c2533aa6b598b107d68076b018", - "reference": "82462a90848a52c2533aa6b598b107d68076b018", + "url": "https://api.github.com/repos/symfony/yaml/zipball/584e52cb8f788a887553ba82db6caacb1d6260bb", + "reference": "584e52cb8f788a887553ba82db6caacb1d6260bb", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": ">=5.3.9" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.6-dev" + "dev-master": "2.8-dev" } }, "autoload": { - "psr-0": { + "psr-4": { "Symfony\\Component\\Yaml\\": "" - } + }, + "exclude-from-classmap": [ + "/Tests/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ - { - "name": "Symfony Community", - "homepage": "http://symfony.com/contributors" - }, { "name": "Fabien Potencier", "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" } ], "description": "Symfony Yaml Component", - "homepage": "http://symfony.com", - "time": "2015-01-03 15:33:07" + "homepage": "https://symfony.com", + "time": "2016-03-04 07:54:35" } ], "aliases": [], diff --git a/src/ShellCommand/ShellCommandRunner.php b/src/ShellCommand/ShellCommandRunner.php index 08d935a..d01e782 100755 --- a/src/ShellCommand/ShellCommandRunner.php +++ b/src/ShellCommand/ShellCommandRunner.php @@ -1,8 +1,6 @@ _downloadHTTP($url, $inputTmpFilePath); break; case '': @@ -278,6 +277,7 @@ private function processOutput($localFilePath, $targetUrl) $this->_uploadToS3($localFilePath, $targetUrl); break; case 'http': + case 'https': $this->_uploadHTTP($localFilePath, $targetUrl); break; case 'capture': @@ -306,32 +306,33 @@ private function _writeLocally($localFilePath, $targetFilePath) private function _uploadToS3($localFilePath, $targetUrl) { - $creds = array('key' => $this->s3Key, 'secret' => $this->s3SecretKey); - // Gather info $urlParts = parse_url($targetUrl); if (!isset($urlParts['host'])) throw new Exception("No host could be parsed from {$targetUrl}."); if (!isset($urlParts['path'])) throw new Exception("No path could be parsed from {$targetUrl}."); - $bucket = $urlParts['host']; - $path = preg_replace('/^\//', '', $urlParts['path']); + $bucket = $urlParts['host']; + $path = preg_replace('/^\//', '', $urlParts['path']); // Upload! - $s3 = S3Client::factory($creds); - $uploader = UploadBuilder::newInstance() - ->setClient($s3) - ->setSource($localFilePath) - ->setBucket($bucket) - ->setKey($path) - ->build() - ; - - try { - $uploader->upload(); - } catch (MultipartUploadException $e) { - $uploader->abort(); - throw $e; + $options = [ + 'region' => 'us-east-1', // hardcoded since Tourbuzz only uses this regions for S3 atm. + 'version' => '2006-03-01', // found in vendor/aws/aws-sdk-php/src/data/s3 + ]; + + // Reference the credentials only* they are passed down. Otherwise S3Client will error. + if ($this->s3Key && $this->s3SecretKey) { + $options['credentials'] = [ + 'key' => $this->s3Key, + 'secret' => $this->s3SecretKey, + ]; } + + S3Client::factory($options)->putObject([ + 'Bucket' => $bucket, + 'Key' => $path, + 'SourceFile' => $localFilePath, + ]); } private function _downloadHTTP($sourceUrl, $localFilePath) diff --git a/test/ShellCommandRunnerTest.php b/test/ShellCommandRunnerTest.php index bb27287..13fb85b 100755 --- a/test/ShellCommandRunnerTest.php +++ b/test/ShellCommandRunnerTest.php @@ -30,7 +30,7 @@ function test1() function testHttpInputScheme() { $scr = ShellCommandRunner::create(ShellCommand::create()); - $tempFile = $scr->processInput("http://www.cnn.com"); + $tempFile = $scr->processInput("http://edition.cnn.com"); $this->assertTrue(file_exists($tempFile)); } @@ -41,7 +41,7 @@ function testInputUrlRewriting() 'inputUrlRewriter' => function($input) use ($sampleFilePath) { return $sampleFilePath; })); - $tempFile = $scr->processInput("http://www.cnn.com"); + $tempFile = $scr->processInput("http://edition.cnn.com"); $this->assertEquals(file_get_contents($sampleFilePath), file_get_contents($tempFile)); }