From a166a5f09ace24b8e6b5f47189e9a6037eda1c69 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 3 May 2019 07:15:43 +0000 Subject: [PATCH] Add support for connecting to redis with an ssl file and password. #206 --- config/services.yaml | 3 +++ src/Service/RedisClient.php | 28 +++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/config/services.yaml b/config/services.yaml index 269d1a48..27efa248 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -80,6 +80,9 @@ services: $scheme: "%env(REDIS_CLIENT_SCHEME)%" $host: "%env(REDIS_CLIENT_HOST)%" $port: "%env(REDIS_CLIENT_PORT)%" + $cert_file: "%env(REDIS_CLIENT_CERTFILE)%" + $password: "%env(REDIS_CLIENT_PASSWORD)%" + $env_flag: "dev" Catalyst\APIBundle\Security\APIKeyUserProvider: arguments: diff --git a/src/Service/RedisClient.php b/src/Service/RedisClient.php index 1c3c35b8..9339a252 100644 --- a/src/Service/RedisClient.php +++ b/src/Service/RedisClient.php @@ -10,20 +10,38 @@ class RedisClient protected $scheme; protected $host; protected $port; + protected $cert_file; + protected $password; + protected $env_flag; - public function __construct($scheme, $host, $port) + public function __construct($scheme, $host, $port, $cert_file, $password, $env_flag) { $this->scheme = $scheme; $this->host = $host; $this->port = $port; + $this->cert_file = $cert_file; + $this->password = $password; + $this->env_flag = $env_flag; } public function getRedisClient() { - $this->redis = new PredisClient([ - "scheme"=>$this->scheme, - "host"=>$this->host, - "port"=>$this->port]); + if ($this->env_flag == 'dev') + { + $this->redis = new PredisClient([ + "scheme"=>$this->scheme, + "host"=>$this->host, + "port"=>$this->port]); + } + else + { + $this->redis = new PredisClient([ + "scheme"=>$this->scheme, + "host"=>$this->host, + "port"=>$this->port, + "ssl"=>["cafile"=>$cert_file, "verify_peer"=>true], + "password"=>$password]); + } return $this->redis; } }