From 1424858323a337b08683d353c858bee2f3d7b227 Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Thu, 22 Jun 2023 12:42:51 +0200 Subject: [PATCH] WebUI: Use Cockpit's os-release implementation Cockpit already provides a way to read the `/etc/os-release` file. --- ui/webui/src/components/app.jsx | 7 ++-- .../localization/InstallationLanguage.jsx | 6 ++-- ui/webui/src/helpers/product.js | 33 ------------------- 3 files changed, 5 insertions(+), 41 deletions(-) delete mode 100644 ui/webui/src/helpers/product.js diff --git a/ui/webui/src/components/app.jsx b/ui/webui/src/components/app.jsx index a2b3ba875f9..2f5f841511a 100644 --- a/ui/webui/src/components/app.jsx +++ b/ui/webui/src/components/app.jsx @@ -23,6 +23,8 @@ import { Page, } from "@patternfly/react-core"; +import { read_os_release as readOsRelease } from "os-release.js"; + import { AddressContext, LanguageContext } from "./Common.jsx"; import { AnacondaHeader } from "./AnacondaHeader.jsx"; import { AnacondaWizard } from "./AnacondaWizard.jsx"; @@ -35,7 +37,6 @@ import { PayloadsClient } from "../apis/payloads"; import { readBuildstamp, getIsFinal } from "../helpers/betanag.js"; import { readConf } from "../helpers/conf.js"; -import { getOsReleaseByKey } from "../helpers/product.js"; export const Application = () => { const [address, setAddress] = useState(); @@ -70,9 +71,7 @@ export const Application = () => { ex => console.error("Failed to parse anaconda buildstamp file") ); - getOsReleaseByKey("PRETTY_NAME").then( - setPrettyName - ); + readOsRelease().then(osRelease => setPrettyName(osRelease.PRETTY_NAME)); }, []); const onAddNotification = (notificationProps) => { diff --git a/ui/webui/src/components/localization/InstallationLanguage.jsx b/ui/webui/src/components/localization/InstallationLanguage.jsx index eeb0dcdb0af..149ea5456cf 100644 --- a/ui/webui/src/components/localization/InstallationLanguage.jsx +++ b/ui/webui/src/components/localization/InstallationLanguage.jsx @@ -34,6 +34,7 @@ import { } from "@patternfly/react-core"; import { EmptyStatePanel } from "cockpit-components-empty-state.jsx"; +import { read_os_release as readOsRelease } from "os-release.js"; import { AddressContext, LanguageContext } from "../Common.jsx"; import { setLocale } from "../../apis/boss.js"; @@ -53,7 +54,6 @@ import { setLangCookie } from "../../helpers/language.js"; import { AnacondaPage } from "../AnacondaPage.jsx"; -import { getOsReleaseByKey } from "../../helpers/product.js"; import "./InstallationLanguage.scss"; @@ -321,9 +321,7 @@ export const InstallationLanguage = ({ idPrefix, setIsFormValid, onAddErrorNotif const [distributionName, setDistributionName] = useState(""); useEffect(() => { - getOsReleaseByKey("NAME").then( - setDistributionName - ); + readOsRelease().then(osRelease => setDistributionName(osRelease.NAME)); }, []); return ( diff --git a/ui/webui/src/helpers/product.js b/ui/webui/src/helpers/product.js deleted file mode 100644 index 74e82f5cfa3..00000000000 --- a/ui/webui/src/helpers/product.js +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2023 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with This program; If not, see . - */ -import cockpit from "cockpit"; - -export const getOsReleaseByKey = (key) => { - const confFile = cockpit.file("/etc/os-release"); - console.log(confFile); - - return confFile - .read() - .then((content) => - content - .split(/\r?\n/) - ?.find((item) => item?.includes(key)) - .split("=")[1] - .replace(/['"]+/g, "") - ) - .finally(confFile.close); -};