Skip to content

fastly:maintenance CLI improvement #742

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions Console/Command/SuperUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,20 @@ private function updateSuIps()
throw new \Exception(__($msg));
}
$aclId = $acl->id;
$aclItems = $this->api->aclItemsList($aclId);
$comment = 'Added for Maintenance Mode';

$this->deleteIps($aclItems, $aclId);
do {

// Per default, Fastly returns 100 IP addresses in one call - we fetch until we clear all of them
$aclItems = $this->api->aclItemsList($aclId);
if (!$aclItems) {
break;
}
$numberOfItems = count($aclItems);
$this->output->writeln('<info>' . "Deleting $numberOfItems IP addresses" . '</info>');
$this->deleteIps($aclItems, $aclId);

} while (true);

$updatedIpList = [];
foreach ($ipList as $ip) {
Expand Down Expand Up @@ -269,6 +279,8 @@ private function updateSuIps()
$updatedIpList[] = $ipInformation;
}

$numberOfUpdatedIp = count($updatedIpList);
$this->output->writeln('<info>' . "Updating list with $numberOfUpdatedIp IP addresses" . '</info>');
$this->api->bulkAclItems($aclId, $updatedIpList);

$this->sendWebHook('*Admin IPs list has been updated*');
Expand Down
12 changes: 9 additions & 3 deletions Model/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1448,13 +1448,19 @@ public function bulkAclItems($aclId, $aclItems)
{
$url = $this->_getApiServiceUri() . 'acl/' . rawurlencode($aclId ?? '') . '/entries' ;

// per documentation, maximum payload for bulk API is 1000
$chunkedItems = array_chunk($aclItems, 1000);
// per documentation, the maximum payload for bulk API is 1000, but it can cause connection timeout
$chunkedItems = array_chunk($aclItems, 200);

foreach ($chunkedItems as $items) {
$payload['entries'] = $items;

$this->_fetch($url, Request::METHOD_PATCH, json_encode($payload));
$isSuccess = $this->_fetch($url, Request::METHOD_PATCH, json_encode($payload));

if (!$isSuccess) {
$errorMessage = $this->errorMessage ?? '';

throw new \Exception('Error while doing bulk ACL items update: ' . $errorMessage);
}
}
}

Expand Down