From d98d5e9ee489cc5f9511ef2761e595c4ef4e4e8a Mon Sep 17 00:00:00 2001 From: Jacob Shandling <61553566+jacobshandling@users.noreply.github.com> Date: Tue, 23 Apr 2024 10:23:41 -0700 Subject: [PATCH] =?UTF-8?q?fleetd-chrome:=20Remove=20spot=20conversions=20?= =?UTF-8?q?to=20string;=20all=20results=20are=20now=20converted=20in=20o?= =?UTF-8?q?=E2=80=A6=20(#18223)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up cleanup for #18210 Merging during freeze with approval from @sharon-fdm and @lukeheath as this code only affects `fleetd-chrome`, which is released on its own schedule. --------- Co-authored-by: Jacob Shandling --- ee/fleetd-chrome/src/db.ts | 6 ++++-- ee/fleetd-chrome/src/tables/disk_info.ts | 4 ++-- ee/fleetd-chrome/src/tables/geolocation.test.ts | 6 +++--- ee/fleetd-chrome/src/tables/geolocation.ts | 16 ++++------------ .../src/tables/network_interfaces.ts | 3 ++- .../src/tables/privacy_preferences.ts | 10 +++------- ee/fleetd-chrome/src/tables/system_info.ts | 2 +- 7 files changed, 19 insertions(+), 28 deletions(-) diff --git a/ee/fleetd-chrome/src/db.ts b/ee/fleetd-chrome/src/db.ts index c309b2cdab..3d30057870 100644 --- a/ee/fleetd-chrome/src/db.ts +++ b/ee/fleetd-chrome/src/db.ts @@ -83,10 +83,12 @@ export default class VirtualDatabase { columns.map((_, i) => { let [colName, val] = [columns[i], row[i]]; if (typeof val !== "string") { - if (val.toString) { + if (typeof val === "boolean") { + val = val === true ? "1" : "0"; + } else if (val && val.toString) { val = val.toString(); } else { - this.warnings.push({ + this.warnings?.push({ column: colName, error_message: `Value is not a string and doesn't have a toString method: ${val}`, }); diff --git a/ee/fleetd-chrome/src/tables/disk_info.ts b/ee/fleetd-chrome/src/tables/disk_info.ts index 40c7222202..02bde6fc52 100644 --- a/ee/fleetd-chrome/src/tables/disk_info.ts +++ b/ee/fleetd-chrome/src/tables/disk_info.ts @@ -9,8 +9,8 @@ export default class TableDiskInfo extends Table { const disks = (await chrome.system.storage.getInfo()) as chrome.system.storage.StorageUnitInfo[]; for (let d of disks) { rows.push({ - capacity: d.capacity.toString(), - id: d.id.toString(), + capacity: d.capacity, + id: d.id, name: d.name, type: d.type, }); diff --git a/ee/fleetd-chrome/src/tables/geolocation.test.ts b/ee/fleetd-chrome/src/tables/geolocation.test.ts index 28d6b0f99c..9e121e8b0c 100644 --- a/ee/fleetd-chrome/src/tables/geolocation.test.ts +++ b/ee/fleetd-chrome/src/tables/geolocation.test.ts @@ -72,10 +72,10 @@ describe("geolocation", () => { expect(rows).toEqual({ data: [ { - ip: "", + ip: null, city: "Vancouver", - country: "", - region: "", + country: null, + region: null, }, ], warnings: null, diff --git a/ee/fleetd-chrome/src/tables/geolocation.ts b/ee/fleetd-chrome/src/tables/geolocation.ts index ef8b9fd121..3477669ae0 100644 --- a/ee/fleetd-chrome/src/tables/geolocation.ts +++ b/ee/fleetd-chrome/src/tables/geolocation.ts @@ -4,24 +4,16 @@ export default class TableGeolocation extends Table { name = "geolocation"; columns = ["ip", "city", "country", "region"]; - ensureString(val: unknown): string { - val = val ?? ""; // coerce undefined/null to empty string - if (typeof val !== "string") { - return val.toString(); - } - return val; - } - async generate() { const resp = await fetch("https://ipapi.co/json"); const json = await resp.json(); return { data: [ { - ip: this.ensureString(json.ip), - city: this.ensureString(json.city), - country: this.ensureString(json.country_name), - region: this.ensureString(json.region), + ip: json.ip, + city: json.city, + country: json.country_name, + region: json.region, }, ], }; diff --git a/ee/fleetd-chrome/src/tables/network_interfaces.ts b/ee/fleetd-chrome/src/tables/network_interfaces.ts index 2da372dfaf..ee9d1eeeb1 100644 --- a/ee/fleetd-chrome/src/tables/network_interfaces.ts +++ b/ee/fleetd-chrome/src/tables/network_interfaces.ts @@ -11,7 +11,8 @@ export default class TableNetworkInterfaces extends Table { warnings: [ { column: "mac", - error_message: "chrome.enterprise API is not available for network details", + error_message: + "chrome.enterprise API is not available for network details", }, ], }; diff --git a/ee/fleetd-chrome/src/tables/privacy_preferences.ts b/ee/fleetd-chrome/src/tables/privacy_preferences.ts index 5951508590..35362b0987 100644 --- a/ee/fleetd-chrome/src/tables/privacy_preferences.ts +++ b/ee/fleetd-chrome/src/tables/privacy_preferences.ts @@ -71,14 +71,10 @@ export default class TablePrivacyPreferences extends Table { } else { propertyAPI.get({}, (details: ChromeSettingGetResultDetails) => { if (property === "web_rtc_ip_handling_policy") { - resolve({[property]: details.value}); + resolve({ [property]: details.value }); } else { - // convert bool response to string binary flag - if (details.value === true) { - resolve({ [property]: "1" }); - } else { - resolve({ [property]: "0" }); - } + // bool responses converted to binary flag in upper layer + resolve({ [property]: details.value }); } }); } diff --git a/ee/fleetd-chrome/src/tables/system_info.ts b/ee/fleetd-chrome/src/tables/system_info.ts index d324a0e472..997218a4a3 100644 --- a/ee/fleetd-chrome/src/tables/system_info.ts +++ b/ee/fleetd-chrome/src/tables/system_info.ts @@ -32,7 +32,7 @@ export default class TableSystemInfo extends Table { let warningsArray = []; // @ts-expect-error @types/chrome doesn't yet have instanceID. - const uuid = (await chrome.instanceID.getID()) as string; + const uuid = await chrome.instanceID.getID(); let devMode = false; if (!chrome.enterprise) { const { installType } = await chrome.management.getSelf();