From f32a69057c2d721a37fe9c84a516babe22ff5777 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 5 Nov 2024 15:45:01 +0100 Subject: [PATCH] wip #7175 @0.5 --- src/app/Magic/Models/ExternalServer.php | 42 +++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/src/app/Magic/Models/ExternalServer.php b/src/app/Magic/Models/ExternalServer.php index 456604e..b1d2fd6 100644 --- a/src/app/Magic/Models/ExternalServer.php +++ b/src/app/Magic/Models/ExternalServer.php @@ -11,6 +11,7 @@ use Cubist\Net\Transfer\Driver; use Cubist\Net\Transfer\FTP; use Cubist\Net\Transfer\IServer; use Cubist\Net\Transfer\SFTP; +use Cubist\Net\Transfer\S3; class ExternalServer extends CubistMagicAbstractModel implements IServer { @@ -26,12 +27,17 @@ class ExternalServer extends CubistMagicAbstractModel implements IServer parent::setFields(); $this->addField('name', Text::class, __('Nom'), ['column' => true]); - $this->addField('protocol', SelectFromArray::class, __('Protocole'), ['options' => $this->getProtocols(), 'default' => 'FTP', 'column' => true, 'allows_null' => false]); + $this->addField('protocol', SelectFromArray::class, __('Protocole'), ['options' => $this->getProtocols(), 'default' => 'SFTP', 'column' => true, 'allows_null' => false]); $this->addField('ftp_mode', SelectFromArray::class, __('Mode de transfert'), ['options' => ['0' => __('Mode passif'), '1' => __('Mode actif')], 'default' => '1', 'when' => ['protocol' => $this->getFTPProtocols()], 'allows_null' => false,]); $this->addField('host', Text::class, __('Hôte'), ['default' => '', 'column' => true, 'when' => ['protocol' => $this->getHostProtocols()]]); $this->addField('port', Integer::class, __('Port'), ['hint' => __('Laisser vide pour utiliser le port par défaut'), 'default' => '', 'min' => 1, 'max' => 65536, 'when' => ['protocol' => $this->getPortProtocols()]]); $this->addField('username', Text::class, __('Nom d\'utilisateur'), ['when' => ['protocol' => $this->getUsernameProtocols()]]); $this->addField('password', Password::class, __('Mot de passe'), ['when' => ['protocol' => $this->getPasswordProtocols()]]); + $this->addField('region', Text::class, __('Région'), ['when' => ['protocol' => 'S3']]); + $this->addField('endpoint', URL::class, __('Endpoint'), ['when' => ['protocol' => 'S3Compatible']]); + $this->addField('key', Text::class, __('Clé d\'accès'), ['when' => ['protocol' => $this->getS3Protocols()]]); + $this->addField('secret', Password::class, __('Secret'), ['when' => ['protocol' => $this->getS3Protocols()]]); + $this->addField('bucket', Text::class, __('Bucket'), ['when' => ['protocol' => $this->getS3Protocols()]]); $this->addField('base_path', Text::class, __('Chemin de base'), ['default' => '/']); $this->addField('base_url', Text::class, __('URL de base'), ['default' => 'https://', 'column' => true, 'column_type' => 'model_function', 'column_function_name' => 'getBaseURL']); } @@ -56,9 +62,14 @@ class ExternalServer extends CubistMagicAbstractModel implements IServer return ['name' => $server->name, 'base_url' => $server->getBaseURL() ?: $server->base_path]; } + protected function getS3Protocols() + { + return ['S3', 'S3Compatible']; + } + protected function getProtocols() { - return ['FTP' => __('FTP non sécurisé'), 'FTPS' => __('FTP sécurisé explicite sur TLS'), 'FTPES' => __('FTP sécurisé implicite sur TLS'), 'SFTP' => 'SFTP']; + return ['SFTP' => 'SFTP', 'FTP' => __('FTP non sécurisé'), 'FTPS' => __('FTP sécurisé explicite sur TLS'), 'FTPES' => __('FTP sécurisé implicite sur TLS'), 'S3' => __('Amazon S3'), 'S3Compatible' => __('Serveurs S3 compatibles')]; } protected function getFTPProtocols() @@ -96,6 +107,8 @@ class ExternalServer extends CubistMagicAbstractModel implements IServer return new FTP($this); } else if ($this->getProtocol() === 'SFTP') { return new SFTP($this); + } else if ($this->getProtocol() === 'S3') { + return new S3($this); } return null; } @@ -135,6 +148,31 @@ class ExternalServer extends CubistMagicAbstractModel implements IServer return $this->base_url; } + public function getRegion() + { + return $this->region; + } + + public function getKey() + { + return $this->key; + } + + public function getSecret() + { + return $this->secret; + } + + public function getBucket() + { + return $this->bucket; + } + + public function getEndpoint() + { + return $this->endpoint; + } + public function getSettings() { return ['ftp_mode' => $this->ftp_mode]; -- 2.39.5