forked from artefactual/atom
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds Storage Service integration to AtoM for the purpose of downloading AIPs and objects from within those AIPs. AIP and Object downloading is only available to users in specific user groups - by default this is the administrator group only. A new Storage Service settings menu appears when the Storage Service plugin is enabled, This settings menu is used to set the storage service API connection details and to activate the feature. When the feature is enabled and the user's group is specified in the storage service plugin's security.yml file, two new links will appear on the detail page from which the user can initiate download of the specific object, or the entire AIP. Modifications have been made to AtoM so that the UUID and paths are stored in the DB during Archivematica's DIP Upload process. The UUID and paths are used when requesting the files from the Storage Service API. Co-authored-by: David Juhasz <[email protected]>
- Loading branch information
Showing
17 changed files
with
591 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ form .field > div | |
} | ||
|
||
form .field > h3 | ||
form .field > label | ||
{ | ||
/* Reset h3 */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
plugins/arStorageServicePlugin/config/arStorageServicePluginConfiguration.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Access to Memory (AtoM) software. | ||
* | ||
* Access to Memory (AtoM) is free software: you can redistribute it and/or | ||
* modify it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the License, | ||
* or (at your option) any later version. | ||
* | ||
* Access to Memory (AtoM) is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
* Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* Access to Memory (AtoM). If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
class arStorageServicePluginConfiguration extends sfPluginConfiguration | ||
{ | ||
public static | ||
$summary = 'Archivematica Storage Service integration plugin', | ||
$version = '1.0.0'; | ||
|
||
public function initialize() | ||
{ | ||
$enabledModules = sfConfig::get('sf_enabled_modules'); | ||
array_push($enabledModules, 'arStorageServiceSettings', 'arStorageService'); | ||
sfConfig::set('sf_enabled_modules', $enabledModules); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
all: | ||
javascripts: | ||
/plugins/sfDrupalPlugin/vendor/drupal/misc/jquery.once.js: | ||
/plugins/sfDrupalPlugin/vendor/drupal/misc/collapse: | ||
/plugins/sfDrupalPlugin/vendor/drupal/misc/form: |
104 changes: 104 additions & 0 deletions
104
plugins/arStorageServicePlugin/lib/arStorageServiceUtils.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Access to Memory (AtoM) software. | ||
* | ||
* Access to Memory (AtoM) is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Access to Memory (AtoM) is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Access to Memory (AtoM). If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
class arStorageServiceUtils | ||
{ | ||
const STORAGE_SERVICE_PACKAGE_PATH = 'file'; | ||
|
||
/** | ||
* Use phpcurl to request a URL and pass the header and stream back to | ||
* the browser. | ||
* | ||
*/ | ||
public static function getFileFromStorageService($url) | ||
{ | ||
$ch = curl_init(); | ||
|
||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); | ||
|
||
curl_setopt($ch, CURLOPT_URL, $url); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 500); | ||
curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($ch, $data) { | ||
echo $data; | ||
|
||
return strlen($data); | ||
}); | ||
|
||
curl_setopt($ch, CURLOPT_HEADERFUNCTION, function($ch, $header) { | ||
header($header); | ||
|
||
return strlen($header); | ||
}); | ||
|
||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // Storage service redirects | ||
curl_setopt($ch, CURLOPT_FAILONERROR, true); | ||
curl_setopt($ch, CURLOPT_HTTPHEADER, array( | ||
sprintf( | ||
'Authorization: ApiKey %s:%s', | ||
(string) QubitSetting::getByName('storage_service_username'), | ||
(string) QubitSetting::getByName('storage_service_api_key') | ||
), | ||
'User-Agent: DRMC', | ||
)); | ||
|
||
curl_exec($ch); | ||
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE); | ||
|
||
curl_close($ch); | ||
|
||
return $status; | ||
} | ||
|
||
/** | ||
* Return true if plugin is enabled and feature is activated. | ||
* | ||
*/ | ||
public static function getAipDownloadEnabled() | ||
{ | ||
$configuration = ProjectConfiguration::getActive(); | ||
|
||
if ($configuration->isPluginEnabled('arStorageServicePlugin') | ||
&& null !== $setting = QubitSetting::getByName('download_aip_enabled')) | ||
{ | ||
return boolval($setting->getValue(array('sourceCulture' => true))); | ||
} | ||
} | ||
|
||
public static function getStorageServiceException($status) | ||
{ | ||
switch ($status) | ||
{ | ||
case '400': | ||
return new QubitApiBadRequestException("Storage service bad request"); | ||
|
||
case '404': | ||
return new QubitApi404Exception("Storage service resource not found"); | ||
|
||
case '401': | ||
return new QubitApiNotAuthorizedException("Storage service resource not authorized"); | ||
|
||
case '403': | ||
return new QubitApiForbiddenException("Storage service resource forbidden"); | ||
|
||
default: | ||
return new Exception(sprintf('Storage service error %s', (string)$status)); | ||
} | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
plugins/arStorageServicePlugin/modules/arStorageService/actions/downloadAction.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Access to Memory (AtoM) software. | ||
* | ||
* Access to Memory (AtoM) is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Access to Memory (AtoM) is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Access to Memory (AtoM). If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
class arStorageServiceDownloadAction extends sfAction | ||
{ | ||
public function execute($request) | ||
{ | ||
$view = sfView::NONE; | ||
|
||
$this->resource = $this->getRoute()->resource; | ||
|
||
// Check that object exists and that it is not the root | ||
if (!isset($this->resource)) | ||
{ | ||
$this->forward404(); | ||
} | ||
|
||
try | ||
{ | ||
$status = $this->downloadAip($request); | ||
} | ||
catch (QubitApi404Exception $e) | ||
{ | ||
$this->response->setStatusCode(404, $e->getMessage()); | ||
throw $e; | ||
} | ||
catch (QubitApiNotAuthorizedException $e) | ||
{ | ||
$this->response->setStatusCode(401, $e->getMessage()); | ||
throw $e; | ||
} | ||
catch (QubitApiForbiddenException $e) | ||
{ | ||
$this->response->setStatusCode(403, $e->getMessage()); | ||
throw $e; | ||
} | ||
catch (QubitApiBadRequestException $e) | ||
{ | ||
$this->response->setStatusCode(400, $e->getMessage()); | ||
throw $e; | ||
} | ||
catch (Exception $e) | ||
{ | ||
$this->response->setStatusCode(500, $e->getMessage()); | ||
throw $e; | ||
} | ||
|
||
return $view; | ||
} | ||
|
||
/** | ||
* Build the request URL for the Storage Service API's 'download' endpoint | ||
* and make the request. Ensure if there is an error that the Storage Service | ||
* return status is passed back to the browser. | ||
* | ||
*/ | ||
protected function downloadAip($request) | ||
{ | ||
if (!arStorageServiceUtils::getAipDownloadEnabled()) | ||
{ | ||
throw new QubitApiForbiddenException('AIP Download disabled'); | ||
} | ||
|
||
if (null === $aipUUID = $this->resource->object->aipUUID) | ||
{ | ||
throw new QubitApiBadRequestException('Missing parameter: aipuuid'); | ||
} | ||
|
||
if (null === $baseUrl = QubitSetting::getByName('storage_service_api_url')) | ||
{ | ||
throw new QubitApiBadRequestException('Missing setting: storage_service_api_url'); | ||
} | ||
|
||
$url = sprintf('%s/%s/%s/download/', | ||
trim($baseUrl, "/"), | ||
arStorageServiceUtils::STORAGE_SERVICE_PACKAGE_PATH, | ||
$aipUUID | ||
); | ||
|
||
// Check return status from Storage Service | ||
if (200 !== $status = arStorageServiceUtils::getFileFromStorageService($url)) | ||
{ | ||
$ex = arStorageServiceUtils::getStorageServiceException($status); | ||
throw $ex; | ||
} | ||
|
||
exit; | ||
} | ||
} |
Oops, something went wrong.