Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
            }
        }