From f11c812d9313b0e79ab03372b705ce8c21a09348 Mon Sep 17 00:00:00 2001 From: Lucas Thurston Date: Sun, 16 Feb 2025 05:49:55 -0800 Subject: [PATCH 1/5] [WIP] This is a breaking change that should affect no one. Specifically, instead of setting `whitelist` and `alwaysOverrideWithWhitelist` instead set `allowedList` and `alwaysOverrideWithAllowedList`." --- .editorconfig | 2 +- Classes/Service/EmailService.php | 228 +++++++++++++++++-------------- 2 files changed, 127 insertions(+), 103 deletions(-) diff --git a/.editorconfig b/.editorconfig index 2a804cd..97b434a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,7 +10,7 @@ insert_final_newline = true # Matches multiple files with brace expansion notation # Set default charset -[*.{php}] +[*.php] charset = utf-8 indent_style = tab diff --git a/Classes/Service/EmailService.php b/Classes/Service/EmailService.php index 7631d9e..afe60d1 100644 --- a/Classes/Service/EmailService.php +++ b/Classes/Service/EmailService.php @@ -1,5 +1,6 @@ configurationManager = $configurationManager; $allSettings = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS); - if(isset($allSettings['email'])) { + if (isset($allSettings['email'])) { $this->settings = $allSettings['email']; } } @@ -227,32 +229,34 @@ public function injectConfigurationManager(ConfigurationManagerInterface $config * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager * @return void */ - public function injectObjectManager(ObjectManagerInterface $objectManager) { + public function injectObjectManager(ObjectManagerInterface $objectManager) + { $this->objectManager = $objectManager; } /** * Gets called after dependency injections. */ - public function initializeObject() { - // Build whitelist - if(isset($this->settings['whitelist'])) { - $whitelist = GeneralUtility::trimExplode(',', $this->settings['whitelist']); - foreach($whitelist as $whitelistConf) { - $parts = GeneralUtility::trimExplode(':', $whitelistConf); + public function initializeObject() + { + # TODO: specify actual TYPO3_CONF_VARS path + $allowedList = $this->settings['allowedList'] ?: Arr::safePath($GLOBALS, 'TYPO3_CONF_VARS.EXTCONF.cicbase.email.allowedList'); + if ($allowedList) { + foreach ($allowedList as $allowListConf) { + $parts = GeneralUtility::trimExplode(':', $allowListConf); if (count($parts) != 2) continue; - $this->addToWhitelist($parts[1], $parts[0]); + $this->addToAllowedList($parts[1], $parts[0]); } } - if(isset($this->settings['alwaysOverrideWithWhitelist'])) { - $this->alwaysOverrideWithWhitelist = $this->settings['alwaysOverrideWithWhitelist']; - } - if(isset($this->settings['defaultSender'])) { + $this->alwaysOverrideWithAllowedList = (bool)$this->settings['alwaysOverrideWithAllowedList'] ?: + Arr::safePath($GLOBALS, 'TYPO3_CONF_VARS.EXTCONF.cicbase.email.alwaysOverrideWithAllowedList'); + + if (isset($this->settings['defaultSender'])) { $this->defaultSender = array($this->settings['defaultSender']['email'] => $this->settings['defaultSender']['name']); } - if(isset($this->settings['templates'])) { - foreach($this->settings['templates'] as $templateName => $templateConfig) { - if(isset($templateConfig['templateFile']) && isset($templateConfig['subject'])) { + if (isset($this->settings['templates'])) { + foreach ($this->settings['templates'] as $templateName => $templateConfig) { + if (isset($templateConfig['templateFile']) && isset($templateConfig['subject'])) { $this->templates[$templateName] = $templateConfig; } else { throw new \Exception("All email templates need a 'subject' and a 'templateFile' field at a minimum. See CIC\\Cicbase\\Service\\EmailService for more details."); @@ -267,26 +271,27 @@ public function initializeObject() { * set already. Exceptions are thrown if we can't find some of these * variables, which usually means there's an error with the typoscript. * - * @param string $templateName As written in typoscript. Must exist in typoscript. - * @param array $recipients array(email => name, email => name) - * @param array $templateVariables Variables to pass to the template view. - * @param array $sender array(email => name, email => name) - * @throws \Exception + * @param string $templateName As written in typoscript. Must exist in typoscript. + * @param array $recipients array(email => name, email => name) + * @param array $templateVariables Variables to pass to the template view. + * @param array $sender array(email => name, email => name) * @return \TYPO3\CMS\Core\Mail\MailMessage + * @throws \Exception */ - public function createMessage($templateName, array $recipients, array $templateVariables = NULL, array $sender = NULL) { - if(!$this->templateExists($templateName)) { + public function createMessage(string $templateName, array $recipients, array $templateVariables = NULL, array $sender = NULL) + { + if (!$this->templateExists($templateName)) { throw new \Exception("You need to add $templateName name to the email templates in typoscript. See CIC\\Cicbase\\Service\\EmailService for more details."); } $recipients = $this->cleanRecipients($recipients); $sender = $this->cleanSender($templateName, $sender); - if(!$sender) { + if (!$sender) { throw new \Exception("Can't send an email without it being from someone. Please provide a sender. See CIC\\Cicbase\\Service\\EmailService for more details."); } $body = $this->buildMessageBody($templateName, $templateVariables); - if($body == '') { + if ($body == '') { throw new \Exception("Can't send an email without a body. Please check your typoscript and template path. See CIC\\Cicbase\\Service\\EmailService for more details."); } $subject = $this->getTemplateSubject($templateName); @@ -309,7 +314,8 @@ public function createMessage($templateName, array $recipients, array $templateV * @param string $contentType * @return \Swift_Mime_Attachment */ - public function createAttachment($path, $contentType = NULL) { + public function createAttachment(string $path, string $contentType = NULL) + { $attachment = \Swift_Attachment::fromPath($path, $contentType); return $attachment; } @@ -319,12 +325,13 @@ public function createAttachment($path, $contentType = NULL) { * * Gets the raw file string for a template key "{ext}.{templateKey}" * - * @see getAvailableTemplateKeys() - * * @param string $templateKey * @return string + * @see getAvailableTemplateKeys() + * */ - public function getTemplateBodyFromKey($templateKey) { + public function getTemplateBodyFromKey(string $templateKey) + { $parts = explode('.', $templateKey); $ext = $parts[0]; $key = $parts[1]; @@ -350,12 +357,13 @@ public function getTemplateBodyFromKey($templateKey) { * * Gets the email subject for a template key "{ext}.{templateKey}" * - * @see getAvailableTemplateKeys() - * * @param string $templateKey * @return string + * @see getAvailableTemplateKeys() + * */ - public function getSubjectFromKey($templateKey) { + public function getSubjectFromKey(string $templateKey) + { $parts = explode('.', $templateKey); $ext = $parts[0]; $key = $parts[1]; @@ -373,7 +381,8 @@ public function getSubjectFromKey($templateKey) { * * @return array */ - public function getAvailableTemplateKeys() { + public function getAvailableTemplateKeys() + { $exts = array(); $keys = array(); @@ -391,7 +400,9 @@ public function getAvailableTemplateKeys() { $whereAllowed = function ($templateDefinition, $templateKey) { return !isset($templateDefinition['noOverride']) || !$templateDefinition['noOverride']; }; - $keyTrimmer = function ($key) { return rtrim($key, '.'); }; + $keyTrimmer = function ($key) { + return rtrim($key, '.'); + }; foreach ($exts as $extKey) { $extConf = $this->getTyposcriptForExtension($extKey); if (!is_array($extConf)) continue; @@ -414,17 +425,18 @@ public function getAvailableTemplateKeys() { } /** - * Checks whitelist settings to determine appropriate recipients + * Checks allowedList settings to determine appropriate recipients * * @param array $recipients * @return array */ - protected function cleanRecipients(array $recipients) { - if($this->hasWhitelist()) { - if($this->alwaysOverrideWithWhitelist) { - return $this->whitelist; + protected function cleanRecipients(array $recipients) + { + if ($this->hasAllowedList()) { + if ($this->alwaysOverrideWithAllowedlist) { + return $this->allowedList; } else { - return array_intersect_assoc($this->whitelist, $recipients); + return array_intersect_assoc($this->allowedList, $recipients); } } else { return $recipients; @@ -436,19 +448,20 @@ protected function cleanRecipients(array $recipients) { * @param array $sender * @return bool|array */ - protected function cleanSender($templateName, array $sender = NULL) { - if($sender) { + protected function cleanSender(string $templateName, array $sender = NULL) + { + if ($sender) { return $sender; } - if(isset($this->settings['templates'][$templateName]) && isset($this->settings['templates'][$templateName]['sender'])) { + if (isset($this->settings['templates'][$templateName]) && isset($this->settings['templates'][$templateName]['sender'])) { $senderInfo = $this->settings['templates'][$templateName]['sender']; return array($senderInfo['email'] => $senderInfo['name']); } - if($this->hasDefaultSender()) { + if ($this->hasDefaultSender()) { return $this->defaultSender; } $systemDefault = MailUtility::getSystemFrom(); - if($systemDefault) { + if ($systemDefault) { return $systemDefault; } return FALSE; @@ -457,12 +470,13 @@ protected function cleanSender($templateName, array $sender = NULL) { /** * Renders the message using the template specified in typoscript. * - * @param $templateName + * @param string $templateName * @param array $templateVariables * @return string */ - protected function buildMessageBody($templateName, array $templateVariables = NULL) { - if(!$this->templateExists($templateName)) return ''; + protected function buildMessageBody(string $templateName, array $templateVariables = NULL) + { + if (!$this->templateExists($templateName)) return ''; /** @var \TYPO3\CMS\Fluid\View\StandaloneView $emailView */ $emailView = $this->objectManager->get('TYPO3\CMS\Fluid\View\StandaloneView'); @@ -475,7 +489,7 @@ protected function buildMessageBody($templateName, array $templateVariables = NU $templatePathAndFilename = $this->getTemplatePath($templateName); $emailView->setTemplatePathAndFilename($templatePathAndFilename); } - if($templateVariables) { + if ($templateVariables) { $emailView->assignMultiple($templateVariables); } return $emailView->render(); @@ -488,8 +502,9 @@ protected function buildMessageBody($templateName, array $templateVariables = NU * @param string $templateName * @return string */ - protected function getTemplatePath($templateName) { - return isset($this->foundTemplatePaths[$templateName]) ? $this->foundTemplatePaths[$templateName] : ''; + protected function getTemplatePath(string $templateName) + { + return $this->foundTemplatePaths[$templateName] ?? ''; } /** @@ -500,9 +515,10 @@ protected function getTemplatePath($templateName) { * @param $templateName * @return string */ - protected function getTemplateSubject($templateName) { - if($this->templateExists($templateName)) { - if(array_key_exists($templateName, $this->foundSubjectOverrides)) { + protected function getTemplateSubject(string $templateName) + { + if ($this->templateExists($templateName)) { + if (array_key_exists($templateName, $this->foundSubjectOverrides)) { return $this->foundSubjectOverrides[$templateName]; } else { return $this->templates[$templateName]['subject']; @@ -515,7 +531,8 @@ protected function getTemplateSubject($templateName) { * @param string $templateName * @return bool */ - protected function templateExists($templateName) { + protected function templateExists(string $templateName) + { if (!isset($this->templates[$templateName])) return FALSE; if (!isset($this->templates[$templateName]['templateFile'])) return FALSE; if (isset($this->foundTemplateOverrides[$templateName])) return TRUE; @@ -528,7 +545,7 @@ protected function templateExists($templateName) { if ($record) { $overrideSubject = $record->getSubject(); - if(strlen($overrideSubject) != 0) $this->foundSubjectOverrides[$templateName] = $overrideSubject; + if (strlen($overrideSubject) != 0) $this->foundSubjectOverrides[$templateName] = $overrideSubject; $this->foundTemplateOverrides[$templateName] = $record->getBody(); return TRUE; } @@ -550,7 +567,8 @@ protected function templateExists($templateName) { * * @return array */ - protected function getTemplateRootPaths() { + protected function getTemplateRootPaths() + { return self::grabRootPathsFromExtConf($this->configurationManager->getConfiguration( ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK )); @@ -561,7 +579,8 @@ protected function getTemplateRootPaths() { * @param array $templateDefinition * @return bool|string */ - protected static function findRealTemplateFile(array $rootPaths, array $templateDefinition) { + protected static function findRealTemplateFile(array $rootPaths, array $templateDefinition) + { $templateFile = $templateDefinition['templateFile']; foreach ($rootPaths as $possiblePath) { $rootPath = GeneralUtility::getFileAbsFileName($possiblePath); @@ -577,7 +596,8 @@ protected static function findRealTemplateFile(array $rootPaths, array $template * @param array $extbaseFrameworkConfiguration * @return array */ - protected static function grabRootPathsFromExtConf(array $extbaseFrameworkConfiguration) { + protected static function grabRootPathsFromExtConf(array $extbaseFrameworkConfiguration) + { $rootPaths = array(); if ( !empty($extbaseFrameworkConfiguration['view']['templateRootPaths']) @@ -591,16 +611,19 @@ protected static function grabRootPathsFromExtConf(array $extbaseFrameworkConfig } /** - * @param $ext + * @param string $ext * @return array */ - protected function getTyposcriptForExtension($ext) { + protected function getTyposcriptForExtension(string $ext) + { $allTyposcript = $this->configurationManager->getConfiguration( ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT ); if (!isset($allTyposcript['plugin.']["tx_$ext."])) return FALSE; - $keyTrimmer = function ($key) { return rtrim($key, '.'); }; + $keyTrimmer = function ($key) { + return rtrim($key, '.'); + }; $extConf = $allTyposcript['plugin.']["tx_$ext."]; Arr::walkKeysRecursive($extConf, $keyTrimmer); return $extConf; @@ -610,45 +633,50 @@ protected function getTyposcriptForExtension($ext) { /** * @return bool */ - public function hasWhitelist() { - return (bool) count($this->whitelist); + public function hasAllowedList() + { + return (bool) count($this->allowedList); } /** * @return bool */ - public function hasDefaultSender() { + public function hasDefaultSender() + { return (bool) count($this->defaultSender); } /** - * Adds an email to the whitelist. + * Adds an email to the allowedList. * * @param string $name * @param string $email */ - public function addToWhitelist($name, $email) { - $this->whitelist[$email] = $name; + public function addToAllowedList(string $name, string $email) + { + $this->allowedList[$email] = $name; } /** - * @param array $whitelist + * @param array $allowedList */ - public function setWhitelist($whitelist) { - $this->whitelist = $whitelist; + public function setAllowedList(array $allowedList) + { + $this->allowedList = $allowedList; } /** * @return array */ - public function getWhitelist() { - return $this->whitelist; + public function getAllowedList(): array + { + return $this->allowedList; } /** * This method sends an email without using much of the typoscript configurations. * - * It only checks the whitelist really and doesn't use template configurations in typoscript. + * It only checks the allowedList really and doesn't use template configurations in typoscript. * * @param array $recipients recipient of the email in the format array('recipient@domain.tld' => 'Recipient Name') * @param array $sender sender of the email in the format array('sender@domain.tld' => 'Sender Name') @@ -659,8 +687,8 @@ public function getWhitelist() { * @return boolean TRUE on success, otherwise false * @deprecated For all new T3 6.x extensions, you should not use this method anymore. */ - public function sendTemplateEmail(array $recipients, array $sender, $subject, $templateName, array $templateVariables = null, array $attachments = null) { - + public function sendTemplateEmail(array $recipients, array $sender, string $subject, string $templateName, array $templateVariables = null, array $attachments = null) + { $recipients = $this->cleanRecipients($recipients); $sender = $this->cleanSender($sender); @@ -671,7 +699,7 @@ public function sendTemplateEmail(array $recipients, array $sender, $subject, $t $templateRootPath = GeneralUtility::getFileAbsFileName($extbaseFrameworkConfiguration['view']['templateRootPath']); $templatePathAndFilename = $templateRootPath . '/Email/' . $templateName; $emailView->setTemplatePathAndFilename($templatePathAndFilename); - if($templateVariables) { + if ($templateVariables) { $emailView->assignMultiple($templateVariables); } $emailBody = $emailView->render(); @@ -682,7 +710,7 @@ public function sendTemplateEmail(array $recipients, array $sender, $subject, $t ->setSubject($subject); if ($attachments) { - foreach($attachments as $att) { + foreach ($attachments as $att) { $message->attach($att); } } @@ -695,10 +723,6 @@ public function sendTemplateEmail(array $recipients, array $sender, $subject, $t $message->send(); - return $message->isSent(); } } - - -?> \ No newline at end of file From 6f8120de0be3c4aca767414053365739eafc9e83 Mon Sep 17 00:00:00 2001 From: Lucas Thurston Date: Tue, 22 Apr 2025 14:57:04 -0700 Subject: [PATCH 2/5] [B] Fix issues with allowedList and alwaysOverride --- Classes/Service/EmailService.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Classes/Service/EmailService.php b/Classes/Service/EmailService.php index afe60d1..f3de667 100644 --- a/Classes/Service/EmailService.php +++ b/Classes/Service/EmailService.php @@ -239,17 +239,17 @@ public function injectObjectManager(ObjectManagerInterface $objectManager) */ public function initializeObject() { - # TODO: specify actual TYPO3_CONF_VARS path $allowedList = $this->settings['allowedList'] ?: Arr::safePath($GLOBALS, 'TYPO3_CONF_VARS.EXTCONF.cicbase.email.allowedList'); if ($allowedList) { - foreach ($allowedList as $allowListConf) { + $allowedListArray = GeneralUtility::trimExplode(';', $allowedList); + foreach ($allowedListArray as $allowListConf) { $parts = GeneralUtility::trimExplode(':', $allowListConf); if (count($parts) != 2) continue; $this->addToAllowedList($parts[1], $parts[0]); } } - $this->alwaysOverrideWithAllowedList = (bool)$this->settings['alwaysOverrideWithAllowedList'] ?: - Arr::safePath($GLOBALS, 'TYPO3_CONF_VARS.EXTCONF.cicbase.email.alwaysOverrideWithAllowedList'); + $this->alwaysOverrideWithAllowedList = (bool) ($this->settings['alwaysOverrideWithAllowedList'] ?: + Arr::safePath($GLOBALS, 'TYPO3_CONF_VARS.EXTCONF.cicbase.email.alwaysOverrideWithAllowedList')); if (isset($this->settings['defaultSender'])) { $this->defaultSender = array($this->settings['defaultSender']['email'] => $this->settings['defaultSender']['name']); @@ -433,7 +433,8 @@ public function getAvailableTemplateKeys() protected function cleanRecipients(array $recipients) { if ($this->hasAllowedList()) { - if ($this->alwaysOverrideWithAllowedlist) { + + if ($this->alwaysOverrideWithAllowedList) { return $this->allowedList; } else { return array_intersect_assoc($this->allowedList, $recipients); @@ -635,7 +636,7 @@ protected function getTyposcriptForExtension(string $ext) */ public function hasAllowedList() { - return (bool) count($this->allowedList); + return count($this->allowedList) > 0; } /** @@ -643,7 +644,7 @@ public function hasAllowedList() */ public function hasDefaultSender() { - return (bool) count($this->defaultSender); + return count($this->defaultSender) > 0; } /** From 4b831af1833fa5295a174073136b90565d38a863 Mon Sep 17 00:00:00 2001 From: Lucas Thurston Date: Wed, 10 Dec 2025 13:44:04 -0800 Subject: [PATCH 3/5] [E] Provide more exception detail outside of prod envs --- Classes/Domain/Repository/FileRepository.php | 36 +++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/Classes/Domain/Repository/FileRepository.php b/Classes/Domain/Repository/FileRepository.php index 0618872..f1fc432 100644 --- a/Classes/Domain/Repository/FileRepository.php +++ b/Classes/Domain/Repository/FileRepository.php @@ -7,6 +7,8 @@ use TYPO3\CMS\Core\Utility\ArrayUtility; use Aws\S3\S3Client; use Aws\Credentials\Credentials; +use \TYPO3\CMS\Core\Core\ApplicationContext; +use \TYPO3\CMS\Core\Utility\GeneralUtility; /*************************************************************** * Copyright notice @@ -119,7 +121,7 @@ protected function getCache() try { $cache = $this->cacheManager->getCache('cicbase_cache'); } catch (\TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException $e) { - throw new \Exception ('Unable to load the cicbase cache.'); + throw new \Exception ($this->getExceptionMessage($e, 'Unable to load the cicbase cache.')); } return $cache; } @@ -283,7 +285,10 @@ protected function moveToAWSDestination($relativeDestinationPath, $destinationFi 'Key' => $source . '/' . $fileObject->getFilename() ]); } catch (\Exception $e) { - return new \TYPO3\CMS\Extbase\Error\Error('Unable to save file to AWS S3', 1336600878); + return new \TYPO3\CMS\Extbase\Error\Error( + $this->getExceptionMessage($e, 'Unable to save file to AWS S3'), + 1336600878 + ); } } else { try { @@ -297,7 +302,10 @@ protected function moveToAWSDestination($relativeDestinationPath, $destinationFi $fileObject->setPath($relativeDestinationPath); $fileObject->setAwsBucket($destinationBucket); } catch (\Exception $e) { - return new \TYPO3\CMS\Extbase\Error\Error('Unable to save file to AWS S3', 1336600875); + return new \TYPO3\CMS\Extbase\Error\Error( + $this->getExceptionMessage($e, 'Unable to save file to AWS S3'), + 1336600875 + ); } } } @@ -322,7 +330,9 @@ protected function moveToDestination($relativeDestinationPath, $destinationFilen } catch (\Exception $e) { // This is a 'compile-time' error, not a run-time one. // Throwing an exception is appropriate. - throw new \Exception ('Cannot create directory for storing files: ' . $absoluteDestinationPath); + throw new \Exception ( + $this->getExceptionMessage($e, 'Cannot create directory for storing files: ' . $absoluteDestinationPath) + ); } } $source = $fileObject->getPath(); @@ -381,4 +391,22 @@ public function initializeObject() $this->defaultQuerySettings->setStoragePageIds(explode(',', $configuration['storagePids'][$this->objectType])); } } + + /** + * Get the exception message along with additional message, if in testing or development context + * + * @param \Exception $exception The exception object + * @param string $message Additional message to be appended + * @return string The combined message if in testing or development context, otherwise just the additional message + */ + private function getExceptionMessage(\Exception $exception, string $message) + { + $applicationContext = GeneralUtility::getApplicationContext(); + if($applicationContext->isTesting() || $applicationContext->isDevelopment()) { + $exceptionMessage = $exception->getMessage(); + return $message . " Exception message: ". $exceptionMessage; + } + + return $message; + } } From 94e613a5bc8c9714ed1149f7df80f0368f65be66 Mon Sep 17 00:00:00 2001 From: Lucas Thurston Date: Fri, 12 Dec 2025 05:43:42 -0800 Subject: [PATCH 4/5] [C] Ignore .idea --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index f0f6368..26554b9 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ @eaDir +.idea From 4381e0691e280e2bdcb4eb2aff25b9564305fbc9 Mon Sep 17 00:00:00 2001 From: Lucas Thurston Date: Fri, 12 Dec 2025 05:43:50 -0800 Subject: [PATCH 5/5] [C] Make S3 credentials optional --- Classes/Domain/Repository/FileRepository.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Classes/Domain/Repository/FileRepository.php b/Classes/Domain/Repository/FileRepository.php index f1fc432..db3a4cc 100644 --- a/Classes/Domain/Repository/FileRepository.php +++ b/Classes/Domain/Repository/FileRepository.php @@ -38,7 +38,6 @@ class FileRepository extends \TYPO3\CMS\Extbase\Persistence\Repository protected $baseStoragePath = 'fileadmin/cicbase/documents'; protected $holdStoragePath = 'typo3temp/cicbase/documents'; - protected $AWSEnabled = true; protected $cicbaseConfiguration = []; /** @@ -222,15 +221,21 @@ protected function getRelativeDestinationPath(\CIC\Cicbase\Domain\Model\File $fi */ protected function initializeS3() { - return new S3Client([ + $args = [ 'version' => 'latest', 'region' => $this->cicbaseConfiguration['AWSRegion'], - 'credentials' => [ + //'debug' => true + ]; + + // Credentials are optional, access could be set by IAM roles + if($this->cicbaseConfiguration['AWSKey'] || $this->cicbaseConfiguration['AWSSecret']) { + $args['credentials'] = [ 'key' => $this->cicbaseConfiguration['AWSKey'], 'secret' => $this->cicbaseConfiguration['AWSSecret'] - ], - //'debug' => true - ]); + ]; + } + + return new S3Client($args); } /** @@ -246,8 +251,6 @@ protected function moveToAWSDestination($relativeDestinationPath, $destinationFi // make sure we have adequate configuration. if (!$this->cicbaseConfiguration['AWSTemporaryBucketName'] || !$this->cicbaseConfiguration['AWSPermanentBucketName'] || - !$this->cicbaseConfiguration['AWSKey'] || - !$this->cicbaseConfiguration['AWSSecret'] || !$this->cicbaseConfiguration['AWSRegion'] ) { throw new \Exception ('AWS File Storage is enabled, yet it is not properly configured in the extension manager');