r024: compact Docker inspect output
This commit is contained in:
+16
-7
@@ -197,7 +197,7 @@ function sanitize_log_output(string $text, int $max_chars = 50000): string {
|
||||
/**
|
||||
* Kompakte Container-Inspect-Ausgabe.
|
||||
*/
|
||||
function compact_container_inspect(string $raw): string {
|
||||
function compact_container_inspect(string $raw, string $detail = 'summary'): string {
|
||||
$data = json_decode($raw, true);
|
||||
if (json_last_error() !== JSON_ERROR_NONE || !is_array($data)) {
|
||||
return $raw;
|
||||
@@ -218,17 +218,26 @@ function compact_container_inspect(string $raw): string {
|
||||
'Image' => $data['Config']['Image'] ?? '',
|
||||
'NetworkMode' => $data['HostConfig']['NetworkMode'] ?? '',
|
||||
'Ports' => $data['NetworkSettings']['Ports'] ?? [],
|
||||
'Env' => $data['Config']['Env'] ?? [],
|
||||
'Mounts' => array_map(function ($m) {
|
||||
'RestartCount' => $data['RestartCount'] ?? 0,
|
||||
'Created' => $data['Created'] ?? '',
|
||||
];
|
||||
if ($detail === 'full') {
|
||||
$compact['Env'] = array_map(function ($entry) {
|
||||
if (!is_string($entry) || !str_contains($entry, '=')) return $entry;
|
||||
[$name, $value] = explode('=', $entry, 2);
|
||||
if (preg_match('/(KEY|TOKEN|SECRET|PASS|AUTH|COOKIE|ARL)/i', $name)) {
|
||||
return $name . '=<redacted>';
|
||||
}
|
||||
return $name . '=' . $value;
|
||||
}, $data['Config']['Env'] ?? []);
|
||||
$compact['Mounts'] = array_map(function ($m) {
|
||||
return [
|
||||
'Type' => $m['Type'] ?? '',
|
||||
'Source' => $m['Source'] ?? '',
|
||||
'Destination' => $m['Destination'] ?? '',
|
||||
];
|
||||
}, $data['Mounts'] ?? []),
|
||||
'RestartCount' => $data['RestartCount'] ?? 0,
|
||||
'Created' => $data['Created'] ?? '',
|
||||
];
|
||||
}, $data['Mounts'] ?? []);
|
||||
}
|
||||
return json_encode($compact, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user