Skip to content

Bulk update for ACL items in CLI #741

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

Merged
merged 1 commit into from
Apr 2, 2025
Merged
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
25 changes: 22 additions & 3 deletions Console/Command/SuperUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ private function updateSuIps()

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

$updatedIpList = [];
foreach ($ipList as $ip) {
if ($ip[0] == '!') {
$ip = ltrim($ip, '!');
Expand All @@ -254,9 +255,22 @@ private function updateSuIps()
throw new \Exception(__($msg));
}

$this->api->upsertAclItem($aclId, $ipParts[0], 0, $comment, $subnet);
$ipInformation = [
'op' => 'create',
'ip' => $ipParts[0],
'negated' => 0,
'comment' => $comment
];

if ($subnet) {
$ipInformation['subnet'] = $subnet;
}

$updatedIpList[] = $ipInformation;
}

$this->api->bulkAclItems($aclId, $updatedIpList);

$this->sendWebHook('*Admin IPs list has been updated*');

$msg = 'Admin IPs list has been updated';
Expand Down Expand Up @@ -307,9 +321,14 @@ private function hasIps($acl)
*/
private function deleteIps($aclItems, $aclId)
{
foreach ($aclItems as $key => $value) {
$this->api->deleteAclItem($aclId, $value->id);
$items = [];
foreach ($aclItems as $item) {
$items[] = [
'op' => 'delete',
'id' => $item->id
];
}
$this->api->bulkAclItems($aclId, $items);
}

/**
Expand Down
14 changes: 14 additions & 0 deletions Model/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,20 @@ public function deleteAclItem($aclId, $aclItemId)
return $result;
}

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);

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

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

/**
* Update single ACL entry
*
Expand Down