From afc07e7c6824f1b564d8e6197f07e0aee5e83d95 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 2 May 2019 07:21:49 +0000 Subject: [PATCH 1/6] Add service to connect to redis. Add command to test service with the HubCounter service. #206 --- config/services.yaml | 6 +++++ src/Command/TestHubCounterCommand.php | 39 +++++++++++++++++++++++++++ src/Service/HubCounter.php | 9 +++---- src/Service/RedisClient.php | 29 ++++++++++++++++++++ 4 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 src/Command/TestHubCounterCommand.php create mode 100644 src/Service/RedisClient.php diff --git a/config/services.yaml b/config/services.yaml index 154d6708..269d1a48 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -75,6 +75,12 @@ services: $ip_address: "%env(APNS_REDIS_IP_ADDRESS)%" $port: "%env(APNS_REDIS_PORT)%" + App\Service\RedisClient: + arguments: + $scheme: "%env(REDIS_CLIENT_SCHEME)%" + $host: "%env(REDIS_CLIENT_HOST)%" + $port: "%env(REDIS_CLIENT_PORT)%" + Catalyst\APIBundle\Security\APIKeyUserProvider: arguments: $em: "@doctrine.orm.entity_manager" diff --git a/src/Command/TestHubCounterCommand.php b/src/Command/TestHubCounterCommand.php new file mode 100644 index 00000000..e08c11dd --- /dev/null +++ b/src/Command/TestHubCounterCommand.php @@ -0,0 +1,39 @@ +setName('test:hubcounter') + ->setDescription('Test hubcounter service. Currently tests addAvailableRider and getAvailableRiderCount.') + ->setHelp('Test hubcounter service. Currently tests addAvailableRider and getAvailableRiderCount.') + ->addArgument('hub_id', InputArgument::REQUIRED, 'Hub ID'); + } + + public function __construct(HubCounter $hc) + { + $this->hc = $hc; + + parent::__construct(); + } + + public function execute(InputInterface $input, OutputInterface $output) + { + $hub_id = $input->getArgument('hub_id'); + + $this->hc->addAvailableRider($hub_id); + + $available_rc = $this->hc->getAvailableRiderCount($hub_id); + + echo "Available Riders in Hub: " . $available_rc . "\n"; + } +} diff --git a/src/Service/HubCounter.php b/src/Service/HubCounter.php index 6fa52819..13388ecc 100644 --- a/src/Service/HubCounter.php +++ b/src/Service/HubCounter.php @@ -15,13 +15,10 @@ class HubCounter protected $em; protected $redis; - public function __construct(EntityManagerInterface $em) + public function __construct(EntityManagerInterface $em, RedisClient $rc) { $this->em = $em; - - // TODO: make it read redis settings from config - // build a service maybe? - $this->redis = new Predis\Client(); + $this->redis = $rc->getRedisClient(); } // get rider key based on id @@ -45,7 +42,7 @@ class HubCounter return $value; // not in cache - $hub = $em->getRepository(Hub::class)->find($hub_id); + $hub = $this->em->getRepository(Hub::class)->find($hub_id); $riders = $hub->getActiveRiders(); $rider_count = count($riders); diff --git a/src/Service/RedisClient.php b/src/Service/RedisClient.php new file mode 100644 index 00000000..1c3c35b8 --- /dev/null +++ b/src/Service/RedisClient.php @@ -0,0 +1,29 @@ +scheme = $scheme; + $this->host = $host; + $this->port = $port; + } + + public function getRedisClient() + { + $this->redis = new PredisClient([ + "scheme"=>$this->scheme, + "host"=>$this->host, + "port"=>$this->port]); + return $this->redis; + } +} From a166a5f09ace24b8e6b5f47189e9a6037eda1c69 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 3 May 2019 07:15:43 +0000 Subject: [PATCH 2/6] 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; } } From b6591fe28e1e0ca71d218e183c49248cb04b6860 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 3 May 2019 09:29:00 +0000 Subject: [PATCH 3/6] Add redis environment variables. #206 --- .env.dist | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.env.dist b/.env.dist index 2829219e..44bfbf42 100644 --- a/.env.dist +++ b/.env.dist @@ -28,3 +28,11 @@ RT_SHORTCODE=1234 MQTT_IP_ADDRESS=localhost MQTT_PORT=8883 MQTT_CERT=/location/of/cert/file.crt + +# redis client +REDIS_CLIENT_SCHEME=tcp +REDIS_CLIENT_HOST=127.0.0.1 +REDIS_CLIENT_PORT=6379 +REDIS_CLIENT_CERTFILE=/location/of/cert/file.crt +REDIS_CLIENT_PASSWORD=foobared +# From 161601ece5897ff8beb7f778ce9d036af7468f64 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 6 May 2019 01:25:04 +0000 Subject: [PATCH 4/6] Remove the cert file parameter for the redis client. #206 --- .env.dist | 1 - config/services.yaml | 1 - src/Service/RedisClient.php | 7 ++----- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.env.dist b/.env.dist index 44bfbf42..4c0b202a 100644 --- a/.env.dist +++ b/.env.dist @@ -33,6 +33,5 @@ MQTT_CERT=/location/of/cert/file.crt REDIS_CLIENT_SCHEME=tcp REDIS_CLIENT_HOST=127.0.0.1 REDIS_CLIENT_PORT=6379 -REDIS_CLIENT_CERTFILE=/location/of/cert/file.crt REDIS_CLIENT_PASSWORD=foobared # diff --git a/config/services.yaml b/config/services.yaml index 27efa248..bf607603 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -80,7 +80,6 @@ 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" diff --git a/src/Service/RedisClient.php b/src/Service/RedisClient.php index 9339a252..43323e0f 100644 --- a/src/Service/RedisClient.php +++ b/src/Service/RedisClient.php @@ -10,16 +10,14 @@ class RedisClient protected $scheme; protected $host; protected $port; - protected $cert_file; protected $password; protected $env_flag; - public function __construct($scheme, $host, $port, $cert_file, $password, $env_flag) + public function __construct($scheme, $host, $port, $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; } @@ -39,8 +37,7 @@ class RedisClient "scheme"=>$this->scheme, "host"=>$this->host, "port"=>$this->port, - "ssl"=>["cafile"=>$cert_file, "verify_peer"=>true], - "password"=>$password]); + "password"=>$this->password]); } return $this->redis; } From 712d54abc51114e9dd0d416645837fc3b7add94c Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 8 May 2019 00:22:57 +0000 Subject: [PATCH 5/6] Change link to Google Maps API in the job order form. #206 --- templates/job-order/form.html.twig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/job-order/form.html.twig b/templates/job-order/form.html.twig index 352ba4e4..1d3e0275 100644 --- a/templates/job-order/form.html.twig +++ b/templates/job-order/form.html.twig @@ -893,7 +893,8 @@ {% endblock %} {% block scripts %} - + +