From 76aaa8350837d1f7d7f981732141c1464c131ef1 Mon Sep 17 00:00:00 2001 From: Florian Ajir Date: Fri, 20 Mar 2020 20:45:57 +0100 Subject: [PATCH] minor refactoring --- README.md | 12 ++++++------ src/ProxiesHelper.php | 12 +++++------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index ea96534..7f56e75 100644 --- a/README.md +++ b/README.md @@ -15,17 +15,17 @@ Provides a way to retrieve cloudfront proxies ip ranges with caching mechanism ## Symfony context The initial purpose of this library was to be used in a symfony project, but it's theorically operational in other contexts like a laravel project. -As you can read in the [official documentation](https://symfony.com/doc/current/deployment/proxies.html#but-what-if-the-ip-of-my-reverse-proxy-changes-constantly) -If you are using CloudFront on top of your load balancer symfony does not provide an easy way to trust proxies traffic, as it will only trust the node sitting directly above your application (in this case your load balancer). -You also need to append the IP addresses or ranges of any additional proxy (in this case CloudFront IP ranges) to the array of trusted proxies. +As refered to the [Symfony official documentation](https://symfony.com/doc/current/deployment/proxies.html#but-what-if-the-ip-of-my-reverse-proxy-changes-constantly) , if you are using CloudFront on top of your load balancer symfony does not provide an easy way to trust proxies traffic, as it will only trust the node sitting directly above your application (in this case your load balancer). + +That's why you also need to append the IP addresses or ranges of any additional proxy (in this case CloudFront IP ranges) to the array of trusted proxies. ### Usage -You have to inject a CacheInterface to ProxiesHelper constructor. +You have to inject a CacheInterface instance to the ProxiesHelper constructor. -In this example the FilesystemAdapter is used to store the cloudfront ips for one hour (3600 seconds). +In this example a FilesystemAdapter instance (from symfony/cache) is used to store the cloudfront ips for one hour (3600 seconds). -_Note that filesystem is often the worst choice for caching performances in production (except tmpfs storage)._ +_Note the filesystem cache adapter is often the worst choice for caching performances in production (except on tmpfs storage)._ ```php // public/index.php diff --git a/src/ProxiesHelper.php b/src/ProxiesHelper.php index ac16207..e96c05e 100644 --- a/src/ProxiesHelper.php +++ b/src/ProxiesHelper.php @@ -43,13 +43,11 @@ public function list(): array // fetch the file $data = json_decode(file_get_contents($this->source), true); // filter to keep only cloudfront addresses - $ips = array_values( - array_filter( - array_map(static function ($item) { - return $item['service'] === 'CLOUDFRONT' ? $item['ip_prefix'] : null; - }, $data['prefixes']) - ) - ); + $ips = array_values(array_filter( + array_map(static function (array $item) { + return $item['service'] === 'CLOUDFRONT' ? $item['ip_prefix'] : null; + }, $data['prefixes']) + )); // update cache $cached->set($ips); $this->cachePool->save($cached);