diff --git a/core/src/plugins/access.s3/S3AccessDriver.php b/core/src/plugins/access.s3/S3AccessDriver.php index 295d201e8d..11cf4d486e 100644 --- a/core/src/plugins/access.s3/S3AccessDriver.php +++ b/core/src/plugins/access.s3/S3AccessDriver.php @@ -99,18 +99,23 @@ public function getS3Service(){ */ public function directoryUsage(AJXP_Node $node){ $client = $this->getS3Service(); - $bucket = $node->getRepository()->getContextOption($node->getContext(), "CONTAINER"); //(isSet($repositoryResolvedOptions["CONTAINER"])?$repositoryResolvedOptions["CONTAINER"]:$this->repository->getOption("CONTAINER")); - $path = rtrim($node->getRepository()->getContextOption($node->getContext(), "PATH"), "/").$node->getPath(); //(isSet($repositoryResolvedOptions["PATH"])?$repositoryResolvedOptions["PATH"]:""); - $objects = $client->getIterator('ListObjects', array( - 'Bucket' => $bucket, - 'Prefix' => $path - )); - - $usage = 0; - foreach ($objects as $object) { - $usage += (double)$object['Size']; + $bucket = $node->getRepository()->getContextOption($node->getContext(), "CONTAINER"); //(isSet($repositoryResolvedOptions["CONTAINER"])?$repositoryResolvedOptions["CONTA$ + $path = rtrim($node->getRepository()->getContextOption($node->getContext(), "PATH"), "/").$node->getPath(); //(isSet($repositoryResolvedOptions["PATH"])?$repositoryRes$ + + $usage = 0; + if(!empty($client)){ + $objects = $client->getIterator('ListObjects', array( + 'Bucket' => $bucket, + 'Prefix' => $path + )); + + + foreach ($objects as $object) { + $usage += (double)$object['Size']; + } } - return $usage; + + return $usage; } diff --git a/core/src/plugins/access.s3/S3AccessWrapper.php b/core/src/plugins/access.s3/S3AccessWrapper.php index 7781903c16..129cbb8019 100644 --- a/core/src/plugins/access.s3/S3AccessWrapper.php +++ b/core/src/plugins/access.s3/S3AccessWrapper.php @@ -108,6 +108,29 @@ protected static function getClientForContext(ContextInterface $ctx, $registerSt require_once("S3Client.php"); $s3Client = new S3Client($config, $repoObject->getId()); $s3Client->registerStreamWrapper(); + + //This attempts to create the bucket if it does not exist, which removes the need for an admin + //to have to have access to the aws system to create the bucket prior to creating a new workspace + $container = $repoObject->getContextOption($ctx, "CONTAINER"); + $region = $repoObject->getContextOption($ctx, "REGION"); + $ctr_exists = $s3Client->doesBucketExist($container,true, config); + + if(!empty($container)){ + if($ctr_exists != 1){ + try{ + // Create a valid bucket and use a LocationConstraint + $result = $s3Client->createBucket(array( + 'Bucket' => $container, + 'LocationConstraint' => $region, + )); + + + } catch (Exception $e) { + //Return a simple message rather than aws standard error message + + } + } + } self::$clients[$repoObject->getId()] = $s3Client; } return self::$clients[$repoObject->getId()];