Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 56 additions & 2 deletions storage-s3/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions storage-s3/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
13 changes: 10 additions & 3 deletions storage-s3/storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down