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)); }
public void TestSetGetProfile() { VaultProfileManager.SetProfile("Test1", "local", vaultParams: new Dictionary <string, object> { ["RootPath"] = "zz:\\no\\such\\path" }); var profiles = VaultProfileManager.GetProfileNames(); Assert.IsNotNull(profiles); Assert.IsTrue(profiles.Count() > 0); Assert.IsTrue(profiles.Contains("Test1")); var p = VaultProfileManager.GetProfile("Test1"); Assert.IsNotNull(p); Assert.AreEqual("Test1", p.Name); Assert.AreEqual("local", p.ProviderName); Assert.IsNotNull(p.VaultParameters); Assert.IsTrue(p.VaultParameters.Count > 0); Assert.IsTrue(p.VaultParameters.ContainsKey("RootPath")); VaultProfileManager.RemoveProfile("Test1"); profiles = VaultProfileManager.GetProfileNames(); Assert.IsNotNull(profiles); Assert.IsFalse(profiles.Contains("Test1")); p = VaultProfileManager.GetProfile("Test1"); Assert.IsNull(p); }
public void TestGetProfiles() { var profiles = VaultProfileManager.GetProfileNames(); Assert.IsNotNull(profiles); Assert.IsTrue(profiles.Count() > 0); var builtinProfiles = profiles.Where(x => x.StartsWith(":")) .Select(x => VaultProfileManager.GetProfile(x)); Assert.IsTrue(builtinProfiles.Count() > 0); }
protected override void ProcessRecord() { if (ListProfiles) { WriteObject(VaultProfileManager.GetProfileNames(), true); } else { var profileName = VaultProfileManager.ResolveProfileName(ProfileName); WriteObject(VaultProfileManager.GetProfile(profileName)); } }
protected override void ProcessRecord() { IVault existingVault = null; var existingProfile = VaultProfileManager.GetProfile(ProfileName); if (existingProfile != null) { try { existingVault = Util.VaultHelper.GetVault(ProfileName); } catch (Exception) { } } if (Remove) { if (existingProfile == null) { return; } if (!Force && existingVault != null && existingVault.TestStorage()) { throw new InvalidOperationException("profile refers to an existing Vault;" + " specify -Force to remove anyway"); } VaultProfileManager.RemoveProfile(ProfileName); } else { if (!Force && existingProfile != null) { throw new InvalidOperationException("existing profile found;" + " specify -Force to overwrite"); } var pp = (IReadOnlyDictionary <string, object> )ProviderParameters.Convert <string, object>(); var vp = (IReadOnlyDictionary <string, object> )VaultParameters.Convert <string, object>(); VaultProfileManager.SetProfile(ProfileName, Provider, pp, vp); } }
public void TestGetDefaultUserProfile() { var p = VaultProfileManager.GetProfile(":user"); var p1 = VaultProfileManager.GetProfile(":USER"); var p2 = VaultProfileManager.GetProfile(":UsEr"); Assert.AreSame(p, p1); Assert.AreSame(p, p2); Assert.AreEqual("local", p.ProviderName); Assert.IsNotNull(p.VaultParameters); var pp = p.VaultParameters; Assert.IsTrue(pp.Count > 0); Assert.IsTrue(pp.ContainsKey("RootPath")); var rootPath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "ACMESharp", "userVault"); Assert.AreEqual(rootPath, pp["RootPath"]); }