Skip to content

Commit bb7abc4

Browse files
committed
patch
1 parent 666d608 commit bb7abc4

3 files changed

Lines changed: 31 additions & 4 deletions

File tree

documentation/docs/reference/api.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ Once generated, copy the key and keep it safe. This key is used to authenticate
396396
<tr>
397397
<td>/hosts/package/<code>&lt;PACKAGE&gt;</code>/<code>&lt;VERSION?&gt;</code><br><code>GET</code></td>
398398
<td><code>&lt;APIKEY&gt;</code></td>
399-
<td><code>package</code> (required, in URL)<br><code>version</code> (optional, in URL)<br><code>strict</code> (optional, query parameter)<br><code>strict-name</code> (optional, query parameter)<br><code>strict-version</code> (optional, query parameter)</td>
400-
<td>List hosts that have the specified package installed, optionally filtered by version. By default, package name and version matching can be non-strict. Use <code>strict</code> to enable strict matching for both package name and version, or use <code>strict-name</code> and <code>strict-version</code> independently.</td>
399+
<td><code>package</code> (required, in URL)<br><code>version</code> (optional, in URL)<br><code>strict</code> (optional, query parameter)<br><code>strict-name</code> (optional, query parameter)<br><code>strict-version</code> (optional, query parameter)<br><code>absent</code> (optional, query parameter)</td>
400+
<td>List hosts that have the specified package installed, optionally filtered by version. By default, package name and version matching can be non-strict. Use <code>strict</code> to enable strict matching for both package name and version, or use <code>strict-name</code> and <code>strict-version</code> independently. Set <code>absent</code> to list hosts where the package (and optional version) is not installed.</td>
401401
<td markdown="block">
402402
```bash
403403
curl --fail-with-body -L -s -X GET -H "Authorization: Bearer <APIKEY>" https://repomanager.mydomain.net/api/v2/hosts/package/nginx
@@ -418,6 +418,14 @@ Once generated, copy the key and keep it safe. This key is used to authenticate
418418
```bash
419419
curl --fail-with-body -L -s -X GET -H "Authorization: Bearer <APIKEY>" "https://repomanager.mydomain.net/api/v2/hosts/package/nginx/1.24.0-1?strict-version"
420420
```
421+
Return hosts where package is absent:
422+
```bash
423+
curl --fail-with-body -L -s -X GET -H "Authorization: Bearer <APIKEY>" "https://repomanager.mydomain.net/api/v2/hosts/package/nginx?absent"
424+
```
425+
Return hosts where exact package version is absent:
426+
```bash
427+
curl --fail-with-body -L -s -X GET -H "Authorization: Bearer <APIKEY>" "https://repomanager.mydomain.net/api/v2/hosts/package/nginx/1.24.0-1?absent&strict"
428+
```
421429
</td>
422430
</tr>
423431
<tr>

www/controllers/Api/Hosts/Hosts.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,14 @@ public function execute(): array
9999
$strictVersion = true;
100100
}
101101

102+
// If the "absent" query parameter is set, return hosts on which the package is NOT installed
103+
$absent = isset($_GET['absent']);
104+
102105
if (empty($this->uri[5])) {
103106
throw new Exception('You must specify a package');
104107
}
105108

106-
return ['results' => $hostListingController->getByPackage($this->uri[5], $version, $strictName, $strictVersion)];
109+
return ['results' => $hostListingController->getByPackage($this->uri[5], $version, $strictName, $strictVersion, $absent)];
107110
}
108111

109112
/**

www/controllers/Host/Listing.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ public function getByGroup(string $group): array
7676

7777
/**
7878
* Return hosts that have the specified package
79+
* If $absent is true, return hosts that do NOT have the specified package instead
7980
*/
80-
public function getByPackage(string $name, string $version = '', bool $strictName = false, bool $strictVersion = false): array
81+
public function getByPackage(string $name, string $version = '', bool $strictName = false, bool $strictVersion = false, bool $absent = false): array
8182
{
8283
$data = [];
8384

@@ -96,6 +97,21 @@ public function getByPackage(string $name, string $version = '', bool $strictNam
9697
$hostPackageController = new HostPackage($host['Id']);
9798
$results = $hostPackageController->searchPackage($name, $version, $strictName, $strictVersion);
9899

100+
// If looking for hosts on which the package is absent
101+
if ($absent) {
102+
// If the host has the specified package, continue to the next host
103+
if (!empty($results)) {
104+
continue;
105+
}
106+
107+
$data[] = [
108+
'id' => $host['Id'],
109+
'hostname' => $host['Hostname']
110+
];
111+
112+
continue;
113+
}
114+
99115
// If the host does not have the specified package, continue to the next host
100116
if (empty($results)) {
101117
continue;

0 commit comments

Comments
 (0)