Skip to content

Commit 9dbe3ae

Browse files
authored
Merge pull request #387 from lbr38/devel
5.12.0
2 parents f1b4879 + f20b23f commit 9dbe3ae

28 files changed

Lines changed: 736 additions & 960 deletions

File tree

.github/workflows/docs.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ jobs:
1818
python-version: '3.12'
1919

2020
- run: pip install -r documentation/requirements.txt
21-
# - run: pip install mkdocs-material
2221

2322
- run: |
2423
cd documentation

documentation/docs/reference/api.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ Once generated, copy the key and keep it safe. This key is used to authenticate
283283
</tbody>
284284
</table>
285285

286-
### Environment management
286+
### Environment
287287

288288
<table>
289289
<thead>
@@ -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)</td>
400-
<td>List hosts that have the specified package installed, optionally filtered by version</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>
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
@@ -406,6 +406,18 @@ Once generated, copy the key and keep it safe. This key is used to authenticate
406406
```bash
407407
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
408408
```
409+
Strict on both name and version:
410+
```bash
411+
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"
412+
```
413+
Strict package name only:
414+
```bash
415+
curl --fail-with-body -L -s -X GET -H "Authorization: Bearer <APIKEY>" "https://repomanager.mydomain.net/api/v2/hosts/package/nginx?strict-name"
416+
```
417+
Strict version only:
418+
```bash
419+
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"
420+
```
409421
</td>
410422
</tr>
411423
<tr>

www/controllers/Api/Hosts/Hosts.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,21 @@ public function execute(): array
8989
if ($this->uri[4] == 'package' and $this->method == 'GET') {
9090
$version = $this->uri[6] ?? '';
9191

92+
// Use strict filters if strict params are set
93+
$strictName = isset($_GET['strict-name']) ?? false;
94+
$strictVersion = isset($_GET['strict-version']) ?? false;
95+
96+
// If the "strict" query parameter is set, both strictName and strictVersion will be true
97+
if (isset($_GET['strict'])) {
98+
$strictName = true;
99+
$strictVersion = true;
100+
}
101+
92102
if (empty($this->uri[5])) {
93103
throw new Exception('You must specify a package');
94104
}
95105

96-
return ['results' => $hostListingController->getByPackage($this->uri[5], $version)];
106+
return ['results' => $hostListingController->getByPackage($this->uri[5], $version, $strictName, $strictVersion)];
97107
}
98108

99109
/**

www/controllers/Group/Group.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function new(string $name): void
6969
$name = Validate::string($name);
7070

7171
// Check that the group name does not contain invalid characters
72-
if (!Validate::alphaNumericHyphen($name, ['.', ' '])) {
72+
if (!Validate::alphaNumericHyphen($name, ['.', ' ', '(', ')', '+'])) {
7373
throw new Exception('Group ' . $name . ' contains invalid characters');
7474
}
7575

www/controllers/Host/Listing.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,13 @@ public function getOutdated(): array
236236
'Hostname' => $host['Hostname'],
237237
'Ip' => $host['Ip'],
238238
'Os' => $host['Os'],
239+
'Os_version' => $host['Os_version'],
239240
'Os_family' => $host['Os_family'],
241+
"Kernel" => $host['Kernel'],
242+
"Arch" => $host['Arch'],
243+
"Type" => $host['Type'],
244+
'Profile' => $host['Profile'],
245+
'Env' => $host['Env'],
240246
'Available_updates' => [
241247
'Total' => count($available),
242248
'Packages' => $available

www/controllers/Host/Update.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,16 @@ public function updateRam(int $id, string $ram) : void
7373

7474
/**
7575
* Update network in database
76-
* TODO: convert stdClass object to array in Api/Host/Host.php and remove object support from this method
7776
*/
78-
public function updateNetwork(int $id, array|object $network) : void
77+
public function updateNetwork(int $id, array $network) : void
7978
{
8079
$data = [];
8180

8281
// Validate network data
8382
foreach ($network as $int => $intData) {
84-
$data[$int]['ipv4'] = Validate::string($intData->ipv4 ?? '');
85-
$data[$int]['ipv6'] = Validate::string($intData->ipv6 ?? '');
86-
$data[$int]['mac'] = Validate::string($intData->mac ?? '');
83+
$data[$int]['ipv4'] = Validate::string($intData['ipv4'] ?? '');
84+
$data[$int]['ipv6'] = Validate::string($intData['ipv6'] ?? '');
85+
$data[$int]['mac'] = Validate::string($intData['mac'] ?? '');
8786
}
8887

8988
// Encode to JSON for database storage

www/controllers/Repo/Metadata/Rpm.php

Lines changed: 13 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Rpm extends Metadata
1010
private $root;
1111
private $createrepo = '/usr/bin/createrepo_c';
1212
private $createrepoArgs = '-v --compress-type=gz --general-compress-type=gz';
13-
private $modifyrepo = '/usr/bin/modifyrepo_c';
13+
// private $modifyrepo = '/usr/bin/modifyrepo_c';
1414

1515
public function setRoot(string $root)
1616
{
@@ -20,34 +20,26 @@ public function setRoot(string $root)
2020
/**
2121
* Create metadata files
2222
*/
23-
public function create()
23+
public function create(): void
2424
{
25-
/**
26-
* Check which of createrepo or createrepo_c is present on the system
27-
*/
25+
// Check which of createrepo or createrepo_c is present on the system
2826
if (!file_exists($this->createrepo)) {
2927
throw new Exception('Could not find createrepo on the system');
3028
}
3129

32-
/**
33-
* Check if root path exists
34-
*/
30+
// Check if root path exists
3531
if (!is_dir($this->root)) {
3632
throw new Exception("Repository root directory '" . $this->root . "' does not exist");
3733
}
3834

39-
/**
40-
* If a comps.xml file exists in the root directory, include it in the metadata
41-
*/
35+
// If a comps.xml file exists in the root directory, include it in the metadata
4236
if (file_exists($this->root . '/comps.xml')) {
4337
$this->createrepoArgs .= ' --groupfile=' . $this->root . '/comps.xml';
4438
}
4539

4640
$this->taskLogSubStepController->new('create-metadata', 'GENERATING REPOSITORY METADATA');
4741

48-
/**
49-
* Create repository metadata
50-
*/
42+
// Create repository metadata
5143
$myprocess = new Process($this->createrepo . ' ' . $this->createrepoArgs . ' ' . $this->root . '/');
5244
$myprocess->setBackground(true);
5345
$myprocess->execute();
@@ -58,9 +50,7 @@ public function create()
5850
*/
5951
$this->taskController->addsubpid($myprocess->getPid());
6052

61-
/**
62-
* Retrieve output from process
63-
*/
53+
// Retrieve output from process
6454
$output = $myprocess->getOutput();
6555

6656
$this->taskLogSubStepController->output($output, 'pre');
@@ -71,112 +61,15 @@ public function create()
7161

7262
$myprocess->close();
7363

74-
/**
75-
* Delete comps.xml as it is no longer needed
76-
*/
77-
if (file_exists($this->root . '/comps.xml')) {
78-
if (!unlink($this->root . '/comps.xml')) {
79-
throw new Exception('Could not delete ' . $this->root . '/comps.xml');
80-
}
81-
}
82-
83-
$this->taskLogSubStepController->completed();
84-
85-
/**
86-
* If a 'modules-temp.yaml' file exists in the root directory, include it in the metadata
87-
* This file has been given a temporary name to avoid being included automatically by createrepo (which seems to fail to parse it correctly)
88-
* So it has to be renamed to modules.yaml and then added to the metadata by modifyrepo
89-
*/
90-
if (file_exists($this->root . '/modules-temp.yaml')) {
91-
$this->taskLogSubStepController->new('add-modules', 'ADDING MODULES.YAML TO REPOSITORY METADATA');
92-
93-
/**
94-
* Rename to modules.yaml
95-
*/
96-
if (!rename($this->root . '/modules-temp.yaml', $this->root . '/modules.yaml')) {
97-
throw new Exception('Could not rename modules-temp.yaml to modules.yaml');
98-
}
99-
100-
/**
101-
* Include modules.yaml in the metadata
102-
*/
103-
$myprocess = new Process($this->modifyrepo . ' ' . $this->root . '/modules.yaml ' . $this->root . '/repodata/');
104-
$myprocess->setBackground(true);
105-
$myprocess->execute();
106-
107-
/**
108-
* Retrieve PID of the launched process
109-
* Then write PID to main PID file
110-
*/
111-
$this->taskController->addsubpid($myprocess->getPid());
112-
113-
/**
114-
* Retrieve output from process
115-
*/
116-
$output = $myprocess->getOutput();
117-
118-
$this->taskLogSubStepController->output($output, 'pre');
119-
120-
if ($myprocess->getExitCode() != 0) {
121-
throw new Exception('Failed to add modules.yaml to repository metadata');
122-
}
123-
124-
$myprocess->close();
125-
126-
/**
127-
* Delete modules.yaml as it is no longer needed
128-
*/
129-
if (file_exists($this->root . '/modules.yaml')) {
130-
if (!unlink($this->root . '/modules.yaml')) {
131-
throw new Exception('Could not delete ' . $this->root . '/modules.yaml');
64+
// Delete temporary metadata files as they are no longer needed
65+
foreach (['comps.xml', 'updateinfo.xml', 'modules.yaml'] as $file) {
66+
if (file_exists($this->root . '/' . $file)) {
67+
if (!unlink($this->root . '/' . $file)) {
68+
throw new Exception('Could not delete ' . $this->root . '/' . $file);
13269
}
13370
}
134-
135-
$this->taskLogSubStepController->completed();
13671
}
13772

138-
/**
139-
* If updateinfo.xml file exists in the root directory, include it in the metadata
140-
*/
141-
if (file_exists($this->root . '/updateinfo.xml')) {
142-
$this->taskLogSubStepController->new('add-updateinfo', 'ADDING UPDATEINFO.XML TO REPOSITORY METADATA');
143-
144-
/**
145-
* Include updateinfo.xml in the metadata
146-
*/
147-
$myprocess = new Process($this->modifyrepo . ' ' . $this->root . '/updateinfo.xml ' . $this->root . '/repodata/');
148-
$myprocess->setBackground(true);
149-
$myprocess->execute();
150-
151-
/**
152-
* Retrieve PID of the launched process
153-
* Then write PID to main PID file
154-
*/
155-
$this->taskController->addsubpid($myprocess->getPid());
156-
157-
/**
158-
* Retrieve output from process
159-
*/
160-
$output = $myprocess->getOutput();
161-
162-
$this->taskLogSubStepController->output($output, 'pre');
163-
164-
if ($myprocess->getExitCode() != 0) {
165-
throw new Exception('Failed to add updateinfo.xml to repository metadata');
166-
}
167-
168-
$myprocess->close();
169-
170-
/**
171-
* Delete updateinfo.xml as it is no longer needed
172-
*/
173-
if (file_exists($this->root . '/updateinfo.xml')) {
174-
if (!unlink($this->root . '/updateinfo.xml')) {
175-
throw new Exception('Could not delete ' . $this->root . '/updateinfo.xml');
176-
}
177-
}
178-
179-
$this->taskLogSubStepController->completed();
180-
}
73+
$this->taskLogSubStepController->completed();
18174
}
18275
}

0 commit comments

Comments
 (0)