private static string GetUserHomeDirOnUnix() { if (SharedUtilities.IsWindowsPlatform()) { throw new NotSupportedException(); } if (!string.IsNullOrEmpty(SharedUtilities.s_homeEnvVar)) { return(SharedUtilities.s_homeEnvVar); } string username = null; if (!string.IsNullOrEmpty(SharedUtilities.s_lognameEnvVar)) { username = s_lognameEnvVar; } else if (!string.IsNullOrEmpty(SharedUtilities.s_userEnvVar)) { username = s_userEnvVar; } else if (!string.IsNullOrEmpty(SharedUtilities.s_lNameEnvVar)) { username = s_lNameEnvVar; } else if (!string.IsNullOrEmpty(SharedUtilities.s_usernameEnvVar)) { username = s_usernameEnvVar; } if (SharedUtilities.IsMacPlatform()) { return(!string.IsNullOrEmpty(username) ? Path.Combine("/Users", username) : null); } else if (SharedUtilities.IsLinuxPlatform()) { if (LinuxNativeMethods.getuid() == LinuxNativeMethods.RootUserId) { return("/root"); } else { return(!string.IsNullOrEmpty(username) ? Path.Combine("/home", username) : null); } } else { throw new NotSupportedException(); } }
static IAzureSession CreateInstance(IDataStore dataStore = null) { string profilePath = Path.Combine( #if NETSTANDARD Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), Resources.AzureDirectoryName); string oldProfilePath = Path.Combine( #endif Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Resources.OldAzureDirectoryName); dataStore = dataStore ?? new DiskDataStore(); string oldCachePath = Path.Combine(profilePath, "TokenCache.dat"); string cachePath = Path.Combine(SharedUtilities.GetUserRootDirectory(), ".IdentityService"); var session = new AdalSession { ClientFactory = new ClientFactory(), AuthenticationFactory = new AuthenticationFactory(), DataStore = dataStore, OldProfileFile = "WindowsAzureProfile.xml", OldProfileFileBackup = "WindowsAzureProfile.xml.bak", ProfileDirectory = profilePath, ProfileFile = "AzureProfile.json", }; var migrated = #if !NETSTANDARD false; #else MigrateSettings(dataStore, oldProfilePath, profilePath); #endif var autoSave = InitializeSessionSettings(dataStore, cachePath, profilePath, ContextAutosaveSettings.AutoSaveSettingsFile, migrated); session.ARMContextSaveMode = autoSave.Mode; session.ARMProfileDirectory = autoSave.ContextDirectory; session.ARMProfileFile = autoSave.ContextFile; session.TokenCacheDirectory = autoSave.CacheDirectory; session.TokenCacheFile = autoSave.CacheFile; InitializeConfigs(session); InitializeDataCollection(session); session.RegisterComponent(HttpClientOperationsFactory.Name, () => HttpClientOperationsFactory.Create()); session.TokenCache = session.TokenCache ?? new AzureTokenCache(); return(session); }
/// <summary> /// Generate the default file location /// </summary> /// <returns>Root directory</returns> internal static string GetUserRootDirectory() { return(!IsWindowsPlatform() ? SharedUtilities.GetUserHomeDirOnUnix() : Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)); }