Skip to content

Commit

Permalink
Use cockpit lib for manifest configuration parsing
Browse files Browse the repository at this point in the history
We recently introduced `get_manifest_config_matchlist()` to do this,
drop the copied parser.
  • Loading branch information
martinpitt committed Jun 6, 2024
1 parent aa13846 commit 35de0f4
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
*/

import cockpit from 'cockpit';
import { read_os_release } from "os-release.js";
import { read_os_release } from "os-release";
import { get_manifest_config_matchlist } from "utils";

/**
* Application-wide constants
Expand All @@ -41,30 +41,15 @@ const VMS_CONFIG = {
StorageMigrationSupported: true,
};

function try_fields(dict, fields, def) {
for (let i = 0; i < fields.length; i++) {
if (fields[i] && dict[fields[i]] !== undefined)
return dict[fields[i]];
}
return undefined;
}

export async function load_config() {
const config = cockpit.manifests.machines?.config;
const os_release = await read_os_release();
const matches = [os_release.PLATFORM_ID, os_release.ID];

function get_config(name) {
if (config) {
let val = config[name];
if (typeof val === 'object' && val !== null)
val = try_fields(val, [os_release.PLATFORM_ID, os_release.ID]);
if (val !== undefined)
VMS_CONFIG[name] = val;
}
for (const key in VMS_CONFIG) {
const val = get_manifest_config_matchlist("machines", key, undefined, matches);
if (val !== undefined)
VMS_CONFIG[key] = val;
}

for (const f in VMS_CONFIG)
get_config(f);
}

export default VMS_CONFIG;

0 comments on commit 35de0f4

Please sign in to comment.