public void TestResolveProfileName() { var envVar = "ACMESHARP_VAULT_PROFILE"; Environment.SetEnvironmentVariable(envVar, ""); Assert.IsTrue(string.IsNullOrEmpty(Environment.GetEnvironmentVariable(envVar))); var profileName = VaultProfileManager.ResolveProfileName(); if (SysHelper.IsElevatedAdmin()) { Assert.AreEqual(VaultProfileManager.PROFILE_DEFAULT_SYS_NAME, profileName); } else { Assert.AreEqual(VaultProfileManager.PROFILE_DEFAULT_USER_NAME, profileName); } Environment.SetEnvironmentVariable(envVar, "FooBar"); Assert.AreEqual("FooBar", Environment.GetEnvironmentVariable(envVar)); profileName = VaultProfileManager.ResolveProfileName(); Assert.AreEqual("FooBar", profileName); profileName = VaultProfileManager.ResolveProfileName(); Assert.AreEqual("FooBar", profileName); profileName = VaultProfileManager.ResolveProfileName("FooBaz"); Assert.AreEqual("FooBaz", profileName); Environment.SetEnvironmentVariable(envVar, ""); Assert.IsTrue(string.IsNullOrEmpty(Environment.GetEnvironmentVariable(envVar))); profileName = VaultProfileManager.ResolveProfileName("FooBaz"); Assert.AreEqual("FooBaz", profileName); }
public static IVault GetVault(string profileName = null) { if (CustomVaultGetter != null) { return(CustomVaultGetter()); } profileName = VaultProfileManager.ResolveProfileName(profileName); if (string.IsNullOrEmpty(profileName)) { throw new InvalidOperationException("unable to resolve effective profile name"); } var profile = VaultProfileManager.GetProfile(profileName); if (profile == null) { throw new InvalidOperationException("unable to resolve effective profile") .With(nameof(profileName), profileName); } var provider = VaultExtManager.GetProvider(profile.ProviderName, null); if (provider == null) { throw new InvalidOperationException("unable to resolve Vault Provider") .With(nameof(profileName), profileName) .With(nameof(profile.ProviderName), profile.ProviderName); } return(provider.GetVault(profile.VaultParameters)); }
protected override void ProcessRecord() { if (ListProfiles) { WriteObject(VaultProfileManager.GetProfileNames(), true); } else { var profileName = VaultProfileManager.ResolveProfileName(ProfileName); WriteObject(VaultProfileManager.GetProfile(profileName)); } }