fleetd-chrome: Remove spot conversions to string; all results are now converted in o… (#18223)

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 <jacob@fleetdm.com>
This commit is contained in:
Jacob Shandling
2024-04-23 10:23:41 -07:00
committed by GitHub
co-authored by Jacob Shandling
parent 0474d72e9a
commit d98d5e9ee4
7 changed files with 19 additions and 28 deletions
+4 -2
View File
@@ -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}`,
});
+2 -2
View File
@@ -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,
});
@@ -72,10 +72,10 @@ describe("geolocation", () => {
expect(rows).toEqual({
data: [
{
ip: "",
ip: null,
city: "Vancouver",
country: "",
region: "",
country: null,
region: null,
},
],
warnings: null,
+4 -12
View File
@@ -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,
},
],
};
@@ -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",
},
],
};
@@ -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 });
}
});
}
+1 -1
View File
@@ -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();