UNPKG

@azure/msal-node-extensions

Version:

![npm (scoped)](https://img.shields.io/npm/v/@azure/msal-node-extensions) ![npm](https://img.shields.io/npm/dw/@azure/msal-node-extensions)

95 lines (92 loc) 3.22 kB
/*! @azure/msal-node-extensions v1.5.9 2025-03-25 */ 'use strict'; import path from 'path'; import { Constants, Platform } from './Constants.mjs'; import { PersistenceError } from '../error/PersistenceError.mjs'; /* * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ class Environment { static get homeEnvVar() { return this.getEnvironmentVariable(Constants.ENVIRONMENT.HOME); } static get lognameEnvVar() { return this.getEnvironmentVariable(Constants.ENVIRONMENT.LOGNAME); } static get userEnvVar() { return this.getEnvironmentVariable(Constants.ENVIRONMENT.USER); } static get lnameEnvVar() { return this.getEnvironmentVariable(Constants.ENVIRONMENT.LNAME); } static get usernameEnvVar() { return this.getEnvironmentVariable(Constants.ENVIRONMENT.USERNAME); } static getEnvironmentVariable(name) { return process.env[name] || ""; } static getEnvironmentPlatform() { return process.platform; } static isWindowsPlatform() { return this.getEnvironmentPlatform() === Platform.WINDOWS; } static isLinuxPlatform() { return this.getEnvironmentPlatform() === Platform.LINUX; } static isMacPlatform() { return this.getEnvironmentPlatform() === Platform.MACOS; } static isLinuxRootUser() { if (typeof process.getuid !== "function") { return false; } return process.getuid() === Constants.LINUX_ROOT_USER_GUID; } static getUserRootDirectory() { return !this.isWindowsPlatform() ? this.getUserHomeDirOnUnix() : this.getUserHomeDirOnWindows(); } static getUserHomeDirOnWindows() { return this.getEnvironmentVariable(Constants.ENVIRONMENT.LOCAL_APPLICATION_DATA); } static getUserHomeDirOnUnix() { if (this.isWindowsPlatform()) { throw PersistenceError.createNotSupportedError("Getting the user home directory for unix is not supported in windows"); } if (this.homeEnvVar) { return this.homeEnvVar; } let username = null; if (this.lognameEnvVar) { username = this.lognameEnvVar; } else if (this.userEnvVar) { username = this.userEnvVar; } else if (this.lnameEnvVar) { username = this.lnameEnvVar; } else if (this.usernameEnvVar) { username = this.usernameEnvVar; } if (this.isMacPlatform()) { return username ? path.join("/Users", username) : null; } else if (this.isLinuxPlatform()) { if (this.isLinuxRootUser()) { return "/root"; } else { return username ? path.join("/home", username) : null; } } else { throw PersistenceError.createNotSupportedError("Getting the user home directory for unix is not supported in windows"); } } } export { Environment }; //# sourceMappingURL=Environment.mjs.map