예제 #1
0
 public function __invoke(Request $req, Response $res, $args = [])
 {
     $vaultName = $args['vaultName'];
     if (!($vault = Vault::get($vaultName))) {
         return $res->withStatus(404);
     }
     $operation = $req->getParam('operation');
     $postData = file_get_contents('php://input');
     $params = json_decode($postData, true);
     try {
         if ($operation === 'add') {
             if (empty($params['Tags'])) {
                 return $res->withStatus(400);
             }
             $vault->addTags($params['Tags']);
             return $res->withStatus(204);
         } elseif ($operation === 'remove') {
             if (empty($params['TagKeys'])) {
                 return $res->withStatus(204);
             }
             $vault->removeTags($params['TagKeys']);
             return $res->withStatus(204);
         }
         return $res->withStatus(400);
     } catch (\Gsandbox\Model\LimitExceededException $e) {
         return $res->limitExceededException();
     }
 }
예제 #2
0
 public function __invoke(Request $req, Response $res, $args = [])
 {
     $vaultName = $args['vaultName'];
     if ($v = Vault::get($vaultName)) {
         $v->delete();
     }
     return $res->withStatus(204);
 }
예제 #3
0
 public function __invoke(Request $req, Response $res, $args = [])
 {
     $vaultName = $args['vaultName'];
     if (!($v = Vault::get($vaultName))) {
         return $res->withStatus(404);
     }
     return $res->withJson($v->serializeArray(), 200, JSON_PRETTY_PRINT);
 }
예제 #4
0
 public function __invoke(Request $req, Response $res, $args = [])
 {
     $vaultName = $args['vaultName'];
     if (!Vault::create($vaultName)) {
         return $res->withStatus(500);
     }
     return $res->withStatus(201);
 }
예제 #5
0
 public function __invoke(Request $req, Response $res, $args = [])
 {
     $accessID = $args['accessID'];
     $GLOBALS['vaultStorePath'] = $GLOBALS['config']['storePath'] . "{$accessID}/vaults/";
     foreach (Vault::all() as $vault) {
         $vault->delete();
     }
     return $res->withStatus(200);
 }
예제 #6
0
 public function __invoke(Request $req, Response $res, $args = [])
 {
     $ret = [];
     foreach (Vault::all() as $vault) {
         $ret[] = $vault->serializeArray();
     }
     $jsonResponse = ['Marker' => null, 'VaultList' => $ret];
     return $res->withJson($jsonResponse, 200, JSON_PRETTY_PRINT);
 }
예제 #7
0
 public function testInvoke()
 {
     $action = new CreateVaultAction();
     $dir = $GLOBALS['vaultStorePath'] . 'testvault';
     $this->assertFalse(is_dir($dir));
     $this->assertFalse(Vault::get('testvault'));
     $res = $action->__invoke($this->getRequest('GET'), new Response(), ['vaultName' => 'testvault']);
     $this->assertEquals(201, $res->getStatusCode());
     $this->assertTrue(is_dir($dir));
     $this->assertTrue(Vault::get('testvault') instanceof Vault);
 }
 public function __invoke(Request $req, Response $res, $args = [])
 {
     $vaultName = $args['vaultName'];
     $multipartID = $args['multipartID'];
     if (!($vault = Vault::get($vaultName))) {
         return $res->withStatus(404);
     }
     if ($m = $vault->getMultipart($multipartID)) {
         $m->delete();
     }
     return $res->withStatus(204);
 }
 public function __invoke(Request $req, Response $res, $args = [])
 {
     $vaultName = $args['vaultName'];
     if (!($vault = Vault::get($vaultName))) {
         return $res->withStatus(404);
     }
     $jsonResponse = ['UploadsList' => []];
     foreach ($vault->getMultiparts() as $m) {
         $jsonResponse['UploadsList'][] = $m->serializeArray();
     }
     return $res->withJson($jsonResponse, 200, JSON_PRETTY_PRINT);
 }
 public function __invoke(Request $req, Response $res, $args = [])
 {
     $vaultName = $args['vaultName'];
     $multipartID = $args['multipartID'];
     if (!($vault = Vault::get($vaultName))) {
         return $res->withStatus(404);
     }
     if (!($m = $vault->getMultipart($multipartID))) {
         return $res->withStatus(404);
     }
     return $res->withJson($m->serializeArray(true), 200, JSON_PRETTY_PRINT);
 }
예제 #11
0
 public function __invoke(Request $req, Response $res, $args = [])
 {
     $vaultName = $args['vaultName'];
     $jobID = $args['jobID'];
     if (!($vault = Vault::get($vaultName))) {
         return $res->resourceNotFoundException();
     }
     if (!($job = $vault->getJob($jobID))) {
         return $res->resourceNotFoundException();
     }
     return $res->withJson($job->serializeArray(true), 200, JSON_PRETTY_PRINT);
 }
예제 #12
0
 public function __invoke(Request $req, Response $res, $args = [])
 {
     $vaultName = $args['vaultName'];
     if (!($vault = Vault::get($vaultName))) {
         return $res->withStatus(404);
     }
     $jsonResponse = ['Marker' => null, 'JobList' => []];
     foreach ($vault->getJobs() as $job) {
         $jsonResponse['JobList'][] = $job->serializeArray();
     }
     return $res->withJson($jsonResponse, 200, JSON_PRETTY_PRINT);
 }
예제 #13
0
 public function __invoke(Request $req, Response $res, $args = [])
 {
     $vaultName = $args['vaultName'];
     $archiveID = $args['archiveID'];
     if (!($v = Vault::get($vaultName))) {
         return $res->withStatus(404);
     }
     if ($archive = $v->getArchive($archiveID)) {
         $archive->delete();
     }
     $v->invalidateInventory();
     return $res->withStatus(204);
 }
예제 #14
0
 public function __invoke(Request $req, Response $res, $args = [])
 {
     $vaultName = $args['vaultName'];
     $jobID = $args['jobID'];
     if (!($v = Vault::get($vaultName))) {
         return $res->withStatus(404);
     }
     if (!($job = $v->getJob($jobID))) {
         return $res->withStatus(404);
     }
     $job->forceCompletion();
     return $res->withStatus(200);
 }
예제 #15
0
 public function __invoke(Request $req, Response $res, $args = [])
 {
     $vaultName = $args['vaultName'];
     if (!($v = Vault::get($vaultName))) {
         return $res->withStatus(404);
     }
     $postData = file_get_contents('php://input');
     $params = json_decode($postData, true);
     $job = $v->createJob($params);
     if (!empty($GLOBALS['config']['throwPolicyEnforcedException']) && $job->getAction() == 'ArchiveRetrieval') {
         return $res->policyEnforcedException();
     }
     return $res->withStatus(202)->withHeader('x-amz-job-id', $job->getId());
 }
 public function __invoke(Request $req, Response $res, $args = [])
 {
     $vaultName = $args['vaultName'];
     if (!($vault = Vault::get($vaultName))) {
         return $res->withStatus(404);
     }
     if (!($partSize = $req->getHeaderLine('x-amz-part-size'))) {
         return $res->withStatus(400)->write('Part size missing.');
     }
     if (!($desc = $req->getHeaderLine('x-amz-archive-description'))) {
         $desc = '';
     }
     $m = $vault->createMultipart($partSize, $desc);
     return $res->withStatus(201)->withHeader('x-amz-multipart-upload-id', $m->getId());
 }
 public function __invoke(Request $req, Response $res, $args = [])
 {
     $vaultName = $args['vaultName'];
     $multipartID = $args['multipartID'];
     if (!($vault = Vault::get($vaultName))) {
         return $res->withStatus(404);
     }
     if (!($m = $vault->getMultipart($multipartID))) {
         return $res->withStatus(404);
     }
     $treeHash = $req->getHeaderLine('x-amz-sha256-tree-hash');
     $archiveSize = $req->getHeaderLine('x-amz-archive-size');
     if (($a = $m->finalize($archiveSize, $treeHash)) === false) {
         return $res->withStatus(400)->write('Finalize failed');
     }
     $vault->invalidateInventory();
     return $res->withStatus(201)->withHeader('x-amz-archive-id', $a->getId());
 }
예제 #18
0
 public function testMultipleVaults()
 {
     $this->assertTrue(Vault::create('testvault') instanceof Vault);
     $action = new ListVaultsAction();
     $exp = ['Marker' => null, 'VaultList' => [["VaultName" => "testvault", "CreationDate" => "XXX", "LastInventoryDate" => null, "NumberOfArchives" => 0, "SizeInBytes" => 0, "VaultARN" => "FAKEARN/testvault"]]];
     $res = $action->__invoke($this->getRequest('GET'), new Response(), []);
     $this->assertEquals(200, $res->getStatusCode());
     $actual = json_decode($res->getBody(), true);
     $actual['VaultList'][0]['CreationDate'] = 'XXX';
     $this->assertEquals($exp, $actual);
     $this->assertTrue(Vault::create('testvault2') instanceof Vault);
     $exp['VaultList'][] = ["VaultName" => "testvault2", "CreationDate" => "XXX", "LastInventoryDate" => null, "NumberOfArchives" => 0, "SizeInBytes" => 0, "VaultARN" => "FAKEARN/testvault2"];
     $res = $action->__invoke($this->getRequest('GET'), new Response(), []);
     $this->assertEquals(200, $res->getStatusCode());
     $actual = json_decode($res->getBody(), true);
     $actual['VaultList'][0]['CreationDate'] = 'XXX';
     $actual['VaultList'][1]['CreationDate'] = 'XXX';
     $this->assertEquals($exp, $actual);
 }
예제 #19
0
 public function __invoke(Request $req, Response $res, $args = [])
 {
     $vaultName = $args['vaultName'];
     if (!($vault = Vault::get($vaultName))) {
         return $res->withStatus(404);
     }
     if (!($contentLength = $req->getHeaderLine('Content-Length'))) {
         return $res->withStatus(400)->write('Content-Length header missing.');
     }
     $contentLength = (int) $contentLength;
     if (!($desc = $req->getHeaderLine('x-amz-archive-description'))) {
         $desc = '';
     }
     if (!($contentHash = $req->getHeaderLine('x-amz-content-sha256'))) {
         return $res->withStatus(400)->write('Header x-amz-content-sha256 missing.');
     }
     if (!($treeHash = $req->getHeaderLine('x-amz-sha256-tree-hash'))) {
         return $res->withStatus(400)->write('Header x-amz-sha256-tree-hash missing.');
     }
     $putData = file_get_contents('php://input');
     $actualContentLength = strlen($putData);
     if ($actualContentLength != $contentLength) {
         return $res->withStatus(400)->write("invalid content length (expected: {$contentLength} actual: {$actualContentLength})");
     }
     $hash = new TreeHash();
     $hash->update($putData);
     $actualTreeHash = bin2hex($hash->complete());
     if ($treeHash !== $actualTreeHash) {
         return $res->withStatus(400)->write("tree hash mismatch actual:{$actualTreeHash} exp:{$treeHash}");
     }
     if (isset($GLOBALS['config']['uploadThrottle'])) {
         $GLOBALS['config']['uploadThrottle']();
     }
     $a = new Archive(true, $vault);
     $a->setParam('SHA256TreeHash', $treeHash);
     $a->setParam('Size', (int) $contentLength);
     $a->setParam('Description', $desc);
     if (($ret = file_put_contents($a->getFile('data'), $putData)) !== $contentLength) {
         return $res->withStatus(500)->write("Could not write archive data: " . $a->getFile('data'));
     }
     $vault->invalidateInventory();
     return $res->withStatus(201)->withHeader('x-amz-archive-id', $a->getId())->withHeader('x-amz-sha256-tree-hash', $treeHash);
 }
예제 #20
0
 public function __invoke(Request $req, Response $res, $args = [])
 {
     $vaultName = $args['vaultName'];
     $jobID = $args['jobID'];
     if (!empty($GLOBALS['config']['throwResourceNotFoundExceptionForGetJobOutput'])) {
         return $res->resourceNotFoundException();
     }
     if (!($vault = Vault::get($vaultName))) {
         return $res->resourceNotFoundException();
     }
     if (!($job = $vault->getJob($jobID))) {
         return $res->resourceNotFoundException();
     }
     if (!$job->hasOutput()) {
         return $res->resourceNotFoundException();
     }
     $range = false;
     $httpRange = false;
     if ($job->getAction() === 'ArchiveRetrieval') {
         $rangeFrom = 0;
         $rangeTo = filesize($job->getArchive()->getFile('data')) - 1;
         if ($rangeHeader = $job->getParam('RetrievalByteRange')) {
             if (!preg_match('@([0-9]+)?-([0-9]+)@', $rangeHeader, $m)) {
                 return $res->withStatus(400);
             }
             $rangeFrom = $m[1];
             $rangeTo = $m[2];
         }
         if ($rangeHeader = $req->getHeaderLine('Range')) {
             if (!preg_match('@([0-9]+)?-([0-9]+)@', $rangeHeader, $m)) {
                 return $res->withStatus(400);
             }
             $httpRange = [$m[1], $m[2]];
             $oRangeFrom = $rangeFrom;
             $oRangeTo = $rangeTo;
             $rangeLen = $m[2] - $m[1] + 1;
             $rangeFrom = $oRangeFrom + $m[1];
             $rangeTo = $oRangeFrom + (int) $m[2];
         }
         $range = [$rangeFrom, $rangeTo];
     }
     return $job->dumpOutput($res, $range, $httpRange);
 }
 public function __invoke(Request $req, Response $res, $args = [])
 {
     $vaultName = $args['vaultName'];
     $multipartID = $args['multipartID'];
     if (!($vault = Vault::get($vaultName))) {
         return $res->withStatus(404);
     }
     if (!($m = $vault->getMultipart($multipartID))) {
         return $res->withStatus(404);
     }
     $contentHash = $req->getHeaderLine('x-amz-content-sha256');
     $treeHash = $req->getHeaderLine('x-amz-sha256-tree-hash');
     $contentRange = $req->getHeaderLine('Content-Range');
     $contentLength = $req->getHeaderLine('Content-Length');
     // 'bytes 0-1048575/*'
     if (!preg_match('@(\\d+)-(\\d+)@', $contentRange, $match)) {
         return $res->withStatus(400)->write('Invalid range');
     }
     $rangeFrom = $match[1];
     $rangeTo = $match[2];
     $putData = file_get_contents('php://input');
     $actualContentLength = strlen($putData);
     if ($actualContentLength != $contentLength) {
         return $res->withStatus(400)->write("invalid content length (expected: {$contentLength} actual: {$actualContentLength})");
     }
     $hash = new TreeHash();
     $hash->update($putData);
     $actualTreeHash = bin2hex($hash->complete());
     if ($treeHash !== $actualTreeHash) {
         return $res->withStatus(400)->write("tree hash mismatch actual:{$actualTreeHash} exp:{$treeHash}");
     }
     if (isset($GLOBALS['config']['uploadThrottle'])) {
         $GLOBALS['config']['uploadThrottle']();
     }
     if (!$m->putPart($rangeFrom, $rangeTo, $contentLength, $putData, $treeHash)) {
         return $res->withStatus(400)->write('putPart failed');
     }
     return $res->withStatus(204)->withHeader('x-amz-sha256-tree-hash', $treeHash);
 }