Loading modules/fastly_streamline_access_admin/src/Commands/FsaAdminCommands.php +37 −9 Changes for modules/fastly_streamline_access_admin/src/Commands/FsaAdminCommands.php: 37 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -96,6 +96,7 @@ class FsaAdminCommands extends DrushCommands { * @param string $ipAddress * IP Address to add to the long lived ACL * * * @command fastly_streamline_access:addLongLived * @aliases fsaal * @usage fastly_streamline_access:addLongLived "ipaddress" Loading Loading @@ -128,19 +129,22 @@ class FsaAdminCommands extends DrushCommands { /** * Summarize ACL information * * @param array $options * * @option allAcls Summarize all ACLs, not just site's * * @command fastly_streamline_access:summary * @aliases fsasum * @usage fastly_streamline_access:summary * Returns IP counts per ACL */ public function summarizeAcl($options = []) { public function summarizeAcl($options = ['allAcls' => FALSE]) { $fastlyInterface = $this->getFastlyInterface(); $aclCounts = []; foreach ($this->getFsaAcls($fastlyInterface) as $acl) { foreach ( $this->getFsaAcls($fastlyInterface, $this->filterAcls($options)) as $acl ) { $count = count($fastlyInterface->getAclMembers($acl->id)); $aclCounts[] = ["name" => $acl->name, "count" => $count]; } Loading @@ -159,18 +163,23 @@ class FsaAdminCommands extends DrushCommands { * @param string $ipAddress * Ip Address to remove from ACLs * * @param array $options * * @option allAcls Summarize all ACLs, not just site's * * @command fastly_streamline_access:remove * @aliases fsar * @usage fastly_streamline_access:remove "W.X.Y.Z" * Will remove any ip W.X.Y.Z from Fastly */ public function removeIp($ipAddress, $options = []) { public function removeIp($ipAddress, $options = ['allAcls' => FALSE]) { $fastlyInterface = $this->getFastlyInterface(); $aclMatches = []; foreach ($this->getFsaAcls($fastlyInterface) as $acl) { foreach ( $this->getFsaAcls($fastlyInterface, $this->filterAcls($options)) as $acl ) { foreach ($fastlyInterface->getAclMembers($acl->id) as $ip) { if ($ip->ip == $ipAddress) { try { Loading Loading @@ -268,17 +277,21 @@ class FsaAdminCommands extends DrushCommands { * @param string $searchTerms * Target search text * * @param array $options * * @option allAcls Summarize all ACLs, not just site's * * @command fastly_streamline_access:search * @aliases fsas * @usage fastly_streamline_access:search "some text" * Will remove any ips from Fastly older than 90 days */ public function searchAcls($searchTerms, $options = []) { public function searchAcls($searchTerms, $options = ['allAcls' => FALSE]) { $fastlyInterface = $this->getFastlyInterface(); //run through all ACLs and IPs - search for matching terms $retIps = []; $acls = $this->getFsaAcls($fastlyInterface); $acls = $this->getFsaAcls($fastlyInterface, $this->filterAcls($options)); foreach ($acls as $acl) { $ips = $fastlyInterface->getAclMembers($acl->id); Loading Loading @@ -334,17 +347,32 @@ class FsaAdminCommands extends DrushCommands { * * @return mixed */ protected function getFsaAcls(FsaFastly $fastlyInterface) { protected function getFsaAcls( FsaFastly $fastlyInterface, bool $filterAcls = TRUE ) { $acls = $fastlyInterface->getAclList(); $ourACLS = $this->getRegisteredACLNames(); if ($filterAcls) { $acls = array_filter( $acls, function ($e) use ($ourACLS) { return in_array($e->name, $ourACLS); } ); } return $acls; } /** * * @param $allAcls * * @return bool */ protected function filterAcls($options): bool { return !empty($options['allAcls']) ? !$options['allAcls'] : TRUE; } } Loading
modules/fastly_streamline_access_admin/src/Commands/FsaAdminCommands.php +37 −9 Changes for modules/fastly_streamline_access_admin/src/Commands/FsaAdminCommands.php: 37 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -96,6 +96,7 @@ class FsaAdminCommands extends DrushCommands { * @param string $ipAddress * IP Address to add to the long lived ACL * * * @command fastly_streamline_access:addLongLived * @aliases fsaal * @usage fastly_streamline_access:addLongLived "ipaddress" Loading Loading @@ -128,19 +129,22 @@ class FsaAdminCommands extends DrushCommands { /** * Summarize ACL information * * @param array $options * * @option allAcls Summarize all ACLs, not just site's * * @command fastly_streamline_access:summary * @aliases fsasum * @usage fastly_streamline_access:summary * Returns IP counts per ACL */ public function summarizeAcl($options = []) { public function summarizeAcl($options = ['allAcls' => FALSE]) { $fastlyInterface = $this->getFastlyInterface(); $aclCounts = []; foreach ($this->getFsaAcls($fastlyInterface) as $acl) { foreach ( $this->getFsaAcls($fastlyInterface, $this->filterAcls($options)) as $acl ) { $count = count($fastlyInterface->getAclMembers($acl->id)); $aclCounts[] = ["name" => $acl->name, "count" => $count]; } Loading @@ -159,18 +163,23 @@ class FsaAdminCommands extends DrushCommands { * @param string $ipAddress * Ip Address to remove from ACLs * * @param array $options * * @option allAcls Summarize all ACLs, not just site's * * @command fastly_streamline_access:remove * @aliases fsar * @usage fastly_streamline_access:remove "W.X.Y.Z" * Will remove any ip W.X.Y.Z from Fastly */ public function removeIp($ipAddress, $options = []) { public function removeIp($ipAddress, $options = ['allAcls' => FALSE]) { $fastlyInterface = $this->getFastlyInterface(); $aclMatches = []; foreach ($this->getFsaAcls($fastlyInterface) as $acl) { foreach ( $this->getFsaAcls($fastlyInterface, $this->filterAcls($options)) as $acl ) { foreach ($fastlyInterface->getAclMembers($acl->id) as $ip) { if ($ip->ip == $ipAddress) { try { Loading Loading @@ -268,17 +277,21 @@ class FsaAdminCommands extends DrushCommands { * @param string $searchTerms * Target search text * * @param array $options * * @option allAcls Summarize all ACLs, not just site's * * @command fastly_streamline_access:search * @aliases fsas * @usage fastly_streamline_access:search "some text" * Will remove any ips from Fastly older than 90 days */ public function searchAcls($searchTerms, $options = []) { public function searchAcls($searchTerms, $options = ['allAcls' => FALSE]) { $fastlyInterface = $this->getFastlyInterface(); //run through all ACLs and IPs - search for matching terms $retIps = []; $acls = $this->getFsaAcls($fastlyInterface); $acls = $this->getFsaAcls($fastlyInterface, $this->filterAcls($options)); foreach ($acls as $acl) { $ips = $fastlyInterface->getAclMembers($acl->id); Loading Loading @@ -334,17 +347,32 @@ class FsaAdminCommands extends DrushCommands { * * @return mixed */ protected function getFsaAcls(FsaFastly $fastlyInterface) { protected function getFsaAcls( FsaFastly $fastlyInterface, bool $filterAcls = TRUE ) { $acls = $fastlyInterface->getAclList(); $ourACLS = $this->getRegisteredACLNames(); if ($filterAcls) { $acls = array_filter( $acls, function ($e) use ($ourACLS) { return in_array($e->name, $ourACLS); } ); } return $acls; } /** * * @param $allAcls * * @return bool */ protected function filterAcls($options): bool { return !empty($options['allAcls']) ? !$options['allAcls'] : TRUE; } }