diff --git a/storage-s3/config.php b/storage-s3/config.php index e655240..e7b1eaf 100644 --- a/storage-s3/config.php +++ b/storage-s3/config.php @@ -27,6 +27,33 @@ function getOptions() { 'label' => $__('S3 Folder Path'), 'configuration' => array('size'=>40), )), + 'storage_type' => new ChoiceField(array( + 'label' => $__('Storage Type'), + 'configuration' => array('data-name'=>'storage_type'), + 'choices' => array( + 'amazon_s3' => $__('Amazon S3 Storage'), + 's3_compatible' => $__('S3 Compatible Storage'), + ), + 'default' => 'amazon_s3', + )), + 'rest-endpoint' => new TextboxField(array( + 'label' => $__('REST Endpoint'), + 'hint' => $__('Specify S3-compatible API endpoint (ex: https://s3.wasabisys.com)'), + 'configuration' => array('size'=> 40, 'length'=> 80), + 'visibility' => new VisibilityConstraint( + new Q(array('storage_type__eq'=> 's3_compatible')), + VisibilityConstraint::HIDDEN + ), + )), + 'rest-region' => new TextboxField(array( + 'label' => $__('REST Region'), + 'hint' => $__('Specify S3-compatible API Region (ex:us-east-1)'), + 'configuration' => array('size'=>30), + 'visibility' => new VisibilityConstraint( + new Q(array('storage_type__eq'=> 's3_compatible')), + VisibilityConstraint::HIDDEN + ), + )), 'aws-region' => new ChoiceField(array( 'label' => $__('AWS Region'), 'choices' => array( @@ -58,6 +85,11 @@ function getOptions() { 'us-gov-west-1' => 'AWS GovCloud (US-West)', ), 'default' => '', + //'visibility' => 'amazon_s3', // Visibilidad condicional + 'visibility' => new VisibilityConstraint( + new Q(array('storage_type__eq'=> 'amazon_s3')), + VisibilityConstraint::HIDDEN + ), )), 'acl' => new ChoiceField(array( 'label' => $__('Default ACL for Attachments'), @@ -98,8 +130,30 @@ function pre_save(&$config, &$errors) { ?: Crypto::decrypt($this->get('secret-access-key'), SECRET_SALT, $this->getNamespace()), ); - if ($config['aws-region']) - $credentials['region'] = $config['aws-region']; + + if ($config['storage_type'] === 's3_compatible') { + // Si el campo rest-endpoint está vacío, añade un error + if (empty($config['rest-endpoint'])) { + $this->getForm()->getField('rest-endpoint')->addError( + __('REST Endpoint is required for S3 Compatible Storage')); + $errors['err'] = __('Please complete the required fields.'); + } elseif (!filter_var($config['rest-endpoint'], FILTER_VALIDATE_URL)) { + $this->getForm()->getField('rest-endpoint')->addError( + __('Please enter a valid URL for the REST Endpoint')); + $errors['err'] = __('Please enter a valid URL.'); + } + + if (empty($config['rest-region'])) { + $this->getForm()->getField('rest-region')->addError( + __('REST Region is required for S3 Compatible Storage')); + $errors['err'] = __('Please complete the required fields.'); + } + $credentials['endpoint'] = $config['rest-endpoint']; + $credentials['region'] = $config['rest-region']; + }else{ + if ($config['aws-region']) + $credentials['region'] = $config['aws-region']; + } if (!$credentials['credentials']['secret']) $this->getForm()->getField('secret-access-key')->addError( diff --git a/storage-s3/plugin.php b/storage-s3/plugin.php index eb33fa7..a97c1f2 100644 --- a/storage-s3/plugin.php +++ b/storage-s3/plugin.php @@ -2,10 +2,10 @@ return array( 'id' => 'storage:s3', - 'version' => '0.5', + 'version' => '0.6', 'ost_version' => '1.17', # Require osTicket v1.17+ 'name' => /* trans */ 'Attachments hosted in Amazon S3', - 'author' => 'Jared Hancock, Kevin Thorne', + 'author' => 'Jared Hancock, Kevin Thorne, Victor Manuel Agudelo', 'description' => /* trans */ 'Enables storing attachments in Amazon S3', 'url' => 'http://www.osticket.com/plugins/storage-s3', 'requires' => array( diff --git a/storage-s3/storage.php b/storage-s3/storage.php index 3a717bb..aa44382 100644 --- a/storage-s3/storage.php +++ b/storage-s3/storage.php @@ -36,11 +36,18 @@ function __construct($meta) { 'secret' => Crypto::decrypt(static::$config['secret-access-key'], SECRET_SALT, $this->getConfig()->getNamespace()) ); - if (static::$config['aws-region']) - $credentials['region'] = static::$config['aws-region']; + + if (static::$config['storage_type'] == 's3_compatible'){ + $credentials['endpoint'] = static::$config['rest-endpoint']; + $credentials['region'] = static::$config['rest-region']; + }else{ + if (static::$config['aws-region']) + $credentials['region'] = static::$config['aws-region']; + } + $credentials['version'] = self::$version; - $credentials['signature_version'] = self::$sig_vers; + $credentials['signature_version'] = self::$sig_vers; $this->client = new S3Client($credentials); }