Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Added minor tweaks for getting the S3 driver working with EMC ViPR ( h…
Browse files Browse the repository at this point in the history
…ttp://www.emc.com/vipr )

Also added the possibility to add a proxy to use for the S3 driver
  • Loading branch information
FireFoxIXI committed Jun 16, 2015
1 parent 3f69510 commit 25597ff
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
14 changes: 14 additions & 0 deletions core/src/plugins/access.s3/class.s3AccessDriver.php
Expand Up @@ -66,6 +66,10 @@ public function detectStreamWrapper($register = false){
}else{
$options["region"] = $this->repository->getOption("REGION");
}
$proxy = $this->repository->getOption("PROXY");
if(!empty($proxy)){
$options['request.options'] = array('proxy' => $proxy);
}
$this->s3Client = S3Client::factory($options);
$this->s3Client->registerStreamWrapper();
}
Expand All @@ -86,6 +90,16 @@ public function initRepository()
ConfService::setConf("PROBE_REAL_SIZE", false);
$this->wrapperClassName = $wrapperData["classname"];
$this->urlBase = $wrapperData["protocol"]."://".$this->repository->getId();

if ($recycle!= "" && !is_dir($this->urlBase. "/" . $recycle . "/")) {
@mkdir($this->urlBase. "/" . $recycle . "/", 0777, true);
if(!is_dir($this->urlBase. "/" . $recycle . "/")) {
throw new AJXP_Exception("Cannot create recycle bin folder. Please check repository configuration or that your folder is writeable!");
} else {
$this->setHiddenAttribute(new AJXP_Node($this->urlBase. "/" . $recycle . "/"));
}
}

if ($recycle != "") {
RecycleBinManager::init($this->urlBase, "/".$recycle);
}
Expand Down
33 changes: 32 additions & 1 deletion core/src/plugins/access.s3/class.s3AccessWrapper.php
Expand Up @@ -192,7 +192,21 @@ public static function copyFileInStream($path, $stream)
public static function changeMode($path, $chmodValue){}

public function rename($from, $to){
if(is_dir($from)){

$fromUrl = parse_url($from);
$repoId = $fromUrl["host"];
$repoObject = ConfService::getRepositoryById($repoId);
$isViPR = $repoObject->getOption("IS_VIPR");
$isDir = false;
if($isViPR === true) {
if(is_dir($from . "/")) {
$from .= '/';
$to .= '/';
$isDir = true;
}
}

if($isDir === true || is_dir($from)){
AJXP_Logger::debug(__CLASS__, __FUNCTION__, "S3 Renaming dir $from to $to");
require_once("aws.phar");

Expand All @@ -215,12 +229,24 @@ public function rename($from, $to){
}else{
$options["region"] = $repoObject->getOption("REGION");
}
$proxy = $repoObject->getOption("PROXY");
if(!empty($proxy)){
$options['request.options'] = array('proxy' => $proxy);
}
$s3Client = S3Client::factory($options);

$bucket = $repoObject->getOption("CONTAINER");
$basePath = $repoObject->getOption("PATH");
$fromKeyname = trim(str_replace("//", "/", $basePath.parse_url($from, PHP_URL_PATH)),'/');
$toKeyname = trim(str_replace("//", "/", $basePath.parse_url($to, PHP_URL_PATH)), '/');
if($isViPR) {
$toKeyname .= '/';
$parts = explode('/', $bucket);
$bucket = $parts[0];
if(isset($parts[1])) {
$fromKeyname = $parts[1] . "/" . $fromKeyname;
}
}

// Perform a batch of CopyObject operations.
$batch = array();
Expand All @@ -234,6 +260,11 @@ public function rename($from, $to){

$currentFrom = $object['Key'];
$currentTo = $toKeyname.substr($currentFrom, strlen($fromKeyname));
if($isViPR) {
if(isset($parts[1])) {
$currentTo = $parts[1] . "/" . $currentTo;
}
}
AJXP_Logger::debug(__CLASS__, __FUNCTION__, "S3 Should move one object ".$currentFrom. " to new key :".$currentTo);
$batch[] = $s3Client->getCommand('CopyObject', array(
'Bucket' => $bucket,
Expand Down
2 changes: 2 additions & 0 deletions core/src/plugins/access.s3/manifest.xml
Expand Up @@ -13,6 +13,8 @@
<param name="REGION" type="select" choices="us-east-1|US Standard (Virginia),us-west-1|US West 1 (Northern California),us-west-2|US West 2 (Oregon),eu-west-1|EU (Ireland), ap-southeast-2|South-East (Sydney), ap-southeast-1|South-East (Singapore),ap-northeast-1|Asia Pacific (Japan),sa-east-1|South America (Sao Paulo),us-gov-west-1|EU Governement Cloud" label="CONF_MESSAGE[Region]" description="CONF_MESSAGE[S3 storage region]" mandatory="true"/>
<param name="STORAGE_URL" type="string" label="CONF_MESSAGE[Storage URL]" description="CONF_MESSAGE[Replace default AWS access points (built from region). Set a full URL, including protocol]" mandatory="false"/>
<param name="CONTAINER" type="string" label="CONF_MESSAGE[Container]" description="CONF_MESSAGE[Root container in the S3 storage]" mandatory="true"/>
<param name="PROXY" type="string" label="CONF_MESSAGE[Proxy]" description="CONF_MESSAGE[If you are using a proxy, for example: 127.0.0.1:80 or username:password@127.0.0.1:8080]" mandatory="false"/>
<param name="IS_VIPR" type="boolean" label="CONF_MESSAGE[Is ViPR]" description="CONF_MESSAGE[If the backend storage is an EMC ViPR storage]" mandatory="false"/>
</server_settings>
<registry_contributions>
<external_file filename="plugins/access.fs/fsTemplatePart.xml" include="client_configs/*" exclude=""/>
Expand Down

0 comments on commit 25597ff

Please sign in to comment.