diff --git a/lib/gui/app/components/settings/settings.tsx b/lib/gui/app/components/settings/settings.tsx index f072b44cd7..54d68a0b4e 100644 --- a/lib/gui/app/components/settings/settings.tsx +++ b/lib/gui/app/components/settings/settings.tsx @@ -25,6 +25,7 @@ import * as analytics from '../../modules/analytics'; import { open as openExternal } from '../../os/open-external/services/open-external'; import { Modal } from '../../styled-components'; import * as i18next from 'i18next'; +import { etcherProInfo } from '../../utils/etcher-pro-specific'; interface Setting { name: string; @@ -55,7 +56,7 @@ interface SettingsModalProps { toggleModal: (value: boolean) => void; } -const UUID = process.env.BALENA_DEVICE_UUID; +const EPInfo = etcherProInfo(); const InfoBox = (props: any) => ( @@ -117,10 +118,14 @@ export function SettingsModal({ toggleModal }: SettingsModalProps) { ); })} - {UUID !== undefined && ( + {EPInfo !== undefined && ( {i18next.t('settings.systemInformation')} - + {EPInfo.get_serial() === undefined ? ( + + ) : ( + + )} )} | undefined; + public uuid: string; + + constructor(supervisorAddr: string, supervisorKey: string) { + this.supervisorAddr = supervisorAddr; + this.supervisorKey = supervisorKey; + this.uuid = (process.env.BALENA_DEVICE_UUID ?? 'NO-UUID').substring(0, 7); + this.tags = undefined; + this.get_tags().then((tags) => (this.tags = tags)); + } + + async get_tags(): Promise> { + const result = await fetch( + this.supervisorAddr + '/v2/device/tags?apikey=' + this.supervisorKey, + ); + const parsed = await result.json(); + if (parsed['status'] === 'success') { + return Object.assign( + {}, + ...parsed['tags'].map((tag: BalenaTag) => { + return { [tag.name]: tag.value }; + }), + ); + } else { + return {}; + } + } + + public get_serial(): string | undefined { + if (this.tags) { + return this.tags['Serial']; + } else { + return undefined; + } + } +} + +export function etcherProInfo(): EtcherPro | undefined { + const BALENA_SUPERVISOR_ADDRESS = process.env.BALENA_SUPERVISOR_ADDRESS; + const BALENA_SUPERVISOR_API_KEY = process.env.BALENA_SUPERVISOR_API_KEY; + + if (BALENA_SUPERVISOR_ADDRESS && BALENA_SUPERVISOR_API_KEY) { + return new EtcherPro(BALENA_SUPERVISOR_ADDRESS, BALENA_SUPERVISOR_API_KEY); + } + return undefined; +}