From 9e7bc54bfd5f0655f8dcc1fef09b075f827746fd Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 5 Nov 2024 17:46:23 +0100 Subject: [PATCH] wip #7175 @0.25 --- src/app/Magic/Models/ExternalServer.php | 34 ++++++++++++++++++++----- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/app/Magic/Models/ExternalServer.php b/src/app/Magic/Models/ExternalServer.php index c20b7d1..4988026 100644 --- a/src/app/Magic/Models/ExternalServer.php +++ b/src/app/Magic/Models/ExternalServer.php @@ -30,12 +30,13 @@ class ExternalServer extends CubistMagicAbstractModel implements IServer $this->addField('name', Text::class, __('Nom'), ['column' => true]); $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('host', Text::class, __('Hôte'), ['default' => '', 'column' => true, 'column_label' => __('Serveur'), 'column_function_name' => 'getServerColumn', 'column_type' => 'model_function', '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'), ['default' => 'eu-west-3', 'when' => ['protocol' => 'S3']]); - $this->addField('endpoint', URL::class, __('Endpoint'), ['when' => ['protocol' => 'S3Compatible']]); + $this->addField('s3_provider', SelectFromArray::class, __('Fournisseur de services S3'), ['default' => 'AWS', 'options' => ['AWS' => 'AWS (Amazon Web Services)', 'Minio' => 'MinIO'], 'when' => ['protocol' => 'S3']]); + $this->addField('region', Text::class, __('Région'), ['default' => 'eu-west-3', 'when' => ['s3_provider' => 'AWS', 'protocol' => $this->getS3Protocols()]]); + $this->addField('endpoint', URL::class, __('Endpoint'), ['when' => ['s3_provider' => 'Minio', 'protocol' => $this->getS3Protocols()]]); $this->addField('access_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()]]); @@ -43,6 +44,27 @@ class ExternalServer extends CubistMagicAbstractModel implements IServer $this->addField('base_url', Text::class, __('URL de base'), ['default' => 'https://', 'column' => true, 'column_type' => 'model_function', 'column_function_name' => 'getBaseURL']); } + public function getServerColumn() + { + $base = trim($this->getBasePath(), '/'); + if ($this->getProtocol() === 'S3') { + if ($this->s3_provider === 'AWS') { + $res = $this->getRegion(); + } else { + $res = $this->getEndpoint(); + } + $res = trim($res, '/'); + $res .= '/' . $this->getBucket() . '/' . $base; + return $res; + } else if (stristr($this->getProtocol(), 'ftp')) { + return trim($this->getHost() . '/' . $base, '/'); + } else { + return $base; + } + + } + + public static function getAllServers() { if (null === static::$_servers) { @@ -65,12 +87,12 @@ class ExternalServer extends CubistMagicAbstractModel implements IServer protected function getS3Protocols() { - return ['S3', 'S3Compatible']; + return ['S3']; } protected function getProtocols() { - 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')]; + 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') . '(' . __('Et solutions compatibles') . ')']; } protected function getFTPProtocols() @@ -110,8 +132,6 @@ class ExternalServer extends CubistMagicAbstractModel implements IServer return new SFTP($this); } else if ($this->getProtocol() === 'S3') { return new S3($this); - } else if ($this->getProtocol() === 'S3Compatible') { - return new S3Compatible($this); } return null; } -- 2.39.5