Path: blob/main/src/vs/platform/externalServices/common/serviceMachineId.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { VSBuffer } from '../../../base/common/buffer.js';6import { generateUuid, isUUID } from '../../../base/common/uuid.js';7import { IEnvironmentService } from '../../environment/common/environment.js';8import { IFileService } from '../../files/common/files.js';9import { IStorageService, StorageScope, StorageTarget } from '../../storage/common/storage.js';1011export async function getServiceMachineId(environmentService: IEnvironmentService, fileService: IFileService, storageService: IStorageService | undefined): Promise<string> {12let uuid: string | null = storageService ? storageService.get('storage.serviceMachineId', StorageScope.APPLICATION) || null : null;13if (uuid) {14return uuid;15}16try {17const contents = await fileService.readFile(environmentService.serviceMachineIdResource);18const value = contents.value.toString();19uuid = isUUID(value) ? value : null;20} catch (e) {21uuid = null;22}2324if (!uuid) {25uuid = generateUuid();26try {27await fileService.writeFile(environmentService.serviceMachineIdResource, VSBuffer.fromString(uuid));28} catch (error) {29//noop30}31}3233storageService?.store('storage.serviceMachineId', uuid, StorageScope.APPLICATION, StorageTarget.MACHINE);3435return uuid;36}373839