Beispiel #1
0
        protected override void ProcessRecord()
        {
            try
            {
                if (_settingsReaders.Count > 0)
                {
                    var settingsLines = new List <string>();

                    foreach (var reader in _settingsReaders)
                    {
                        settingsLines.AddRange(reader.ReadSettings());
                    }
                    var settings = _parser.Parse(settingsLines, overrideSettingsReader.ReadSettings(), Section, Delimiter);

                    this.WriteObject(settings);
                }
            }
            catch (Exception e)
            {
                ThrowTerminatingError(
                    new ErrorRecord(
                        e,
                        "ParsedSettings",
                        ErrorCategory.NotSpecified,
                        this)
                    );
            }
        }
Beispiel #2
0
        public void SettingsParser_Parse_SettingsWithReservedKey_ReturnsExpectedResult()
        {
            var sp     = new SettingsParser();
            var reader = GetSettingsFileReader(SettingsWithReservedKey);

            sp.Parse(reader.ReadSettings(), "Dev", '|');
        }
Beispiel #3
0
        public void SettingsParser_Parse_with_invalid_section_throws_exception()
        {
            var sp     = new SettingsParser();
            var reader = GetSettingsFileReader(Basic);

            sp.Parse(reader.ReadSettings(), "AAAA", '|');
        }
Beispiel #4
0
        public void SettingsParser_Parse_TGSettings_ReturnsExpectedResult()
        {
            var sp       = new SettingsParser();
            var reader   = GetSettingsFileReader(TGSettings);
            var settings = sp.Parse(reader.ReadSettings(), "DEV", '|');

            Assert.IsNotNull(settings);
        }
Beispiel #5
0
        public void SettingsParser_Parse_RepeatSettings_ReturnsExpectedResult()
        {
            var sp       = new SettingsParser();
            var reader   = GetSettingsFileReader(RepeatSectionSettings);
            var settings = sp.Parse(reader.ReadSettings(), "Live", '|');

            Assert.IsNotNull(settings);
            Assert.AreEqual(6, settings.Keys.Count);
        }
Beispiel #6
0
        public void SettingsParser_Parse_AdvancedSettings_for_environment_profile_ReturnsExpectedResult(string section)
        {
            var sp       = new SettingsParser();
            var reader   = GetSettingsFileReader(AdvancedSettings);
            var settings = sp.Parse(reader.ReadSettings(), section, '|');

            Assert.IsNotNull(settings);
            Assert.AreEqual(section, settings["environment.profile"][0]);
            Assert.AreEqual(section, settings["Profile"][0]);
        }
Beispiel #7
0
        public void ParseTheContentToObject()
        {
            File.WriteAllText(".\\test.json", "{Website:\"cue\",Database:\"cue_db\",YesNo:true,Auto:\"Manual\"}");
            var commandLine = @"-Website:cue -Database:cue_db -YesNo:true";

            var p = new SettingsParser();
            var r = p.Parse <TestSettings>(new FileInfo(".\\test.json"), commandLine, "test");

            Assert.AreEqual("cue_db", r.Database);
            Assert.AreEqual("cue", r.Website);
            Assert.IsTrue(r.YesNo);
            Assert.AreEqual(SampleEnum.Manual, r.Auto);
        }
Beispiel #8
0
        public void ParseTheContentToObject()
        {
            File.WriteAllText(".\\test.json","{Website:\"cue\",Database:\"cue_db\",YesNo:true,Auto:\"Manual\"}");
            var commandLine = @"-Website:cue -Database:cue_db -YesNo:true";

            var p = new SettingsParser();
            var r = p.Parse<TestSettings>(new FileInfo(".\\test.json"), commandLine, "test");

            Assert.AreEqual("cue_db",r.Database);
            Assert.AreEqual("cue",r.Website);
            Assert.IsTrue(r.YesNo);
            Assert.AreEqual(SampleEnum.Manual, r.Auto);
        }
Beispiel #9
0
        public void SettingsParser_Parse_DelimitedReturnsMultipleValues()
        {
            var sp       = new SettingsParser();
            var reader   = GetSettingsFileReader(MultipleSettings);
            var settings = sp.Parse(reader.ReadSettings(), "Live", '|');

            Assert.IsNotNull(settings);
            Assert.AreEqual(6, settings.Keys.Count);
            Assert.AreEqual("Other", settings.Keys.ElementAt(1));
            Assert.AreEqual("2", settings["Other"][0]);
            Assert.AreEqual("3", settings["Other"][1]);
            Assert.AreEqual("2|3", settings["Quoted"][0]);
            Assert.AreEqual("", settings["Nothing"][0]);
        }
Beispiel #10
0
        public void SettingsParser_Parse_Servers_ReturnsExpectedResult()
        {
            var sp       = new SettingsParser();
            var reader   = GetSettingsFileReader(Servers);
            var settings = sp.Parse(reader.ReadSettings(), "icevm069", '|');

            Assert.IsNotNull(settings);
            Assert.AreEqual(7, settings.Keys.Count);
            Assert.AreEqual(@"icevm069", settings["server.name"][0]);
            Assert.AreEqual(@"d", settings["local.root.drive.letter"][0]);
            Assert.AreEqual(@"_releasetemp", settings["deployment.working.folder"][0]);
            Assert.AreEqual(@"d:\_releasetemp", settings["local.temp.working.folder"][0]);
            Assert.AreEqual(@"\\icevm069\_releasetemp", settings["remote.temp.working.folder"][0]);
        }
Beispiel #11
0
        public void SettingsParser_Parse_BasicSettings_ReturnsExpectedResult()
        {
            var sp       = new SettingsParser();
            var reader   = GetSettingsFileReader(Basic);
            var settings = sp.Parse(reader.ReadSettings(), "Dev", '|');

            Assert.IsNotNull(settings);
            Assert.AreEqual(5, settings.Keys.Count);
            Assert.AreEqual("Wotsit", settings.Keys.ElementAt(0));
            Assert.AreEqual("Thing", settings.Keys.ElementAt(1));
            Assert.AreEqual("other", settings.Keys.ElementAt(2));
            Assert.AreEqual("5", settings["Wotsit"][0]);
            Assert.AreEqual("3", settings["Thing"][0]);
            Assert.AreEqual("4", settings["other"][0]);
        }
Beispiel #12
0
        public void SettingsParser_Parse_SettingsXmlWithInheritanceAt3Levels_ReturnsExpectedResult()
        {
            var sp       = new SettingsParser();
            var reader   = GetSettingsFileReader(SettingsWithInheritanceXml);
            var settings = sp.Parse(reader.ReadSettings(), "Prod", '|');

            Assert.IsNotNull(settings);
            Assert.AreEqual(5, settings.Keys.Count);
            Assert.AreEqual("Wotsit", settings.Keys.ElementAt(0));
            Assert.AreEqual("Thing", settings.Keys.ElementAt(1));
            Assert.AreEqual("Other", settings.Keys.ElementAt(2));
            Assert.AreEqual("10", settings["Wotsit"][0]);
            Assert.AreEqual("30", settings["Thing"][0]);
            Assert.AreEqual("200", settings["Other"][0]);
        }
Beispiel #13
0
        public void SettingsParser_Parse_AdvancedSettings_ReturnsExpectedResult(string settingsFileName)
        {
            var sp       = new SettingsParser();
            var reader   = GetSettingsFileReader(settingsFileName);
            var settings = sp.Parse(reader.ReadSettings(), new String[0], "Dev", '|');

            Assert.IsNotNull(settings);
            Assert.AreEqual(6, settings.Keys.Count);
            Assert.AreEqual("Wotsit", settings.Keys.ElementAt(0));
            Assert.AreEqual("Thing", settings.Keys.ElementAt(1));
            Assert.AreEqual("Other", settings.Keys.ElementAt(2));
            Assert.AreEqual("3  4 5", settings["Wotsit"][0]);
            Assert.AreEqual("3  4", settings["Thing"][0]);
            Assert.AreEqual("4", settings["Other"][0]);
        }
Beispiel #14
0
        public void SettingsParser_Parse_settings_with_inheritance_with_valid_section_parses_settings()
        {
            var sp = new SettingsParser {
                AppendReservedSettings = true
            };
            var reader1   = GetSettingsFileReader(SettingsWithInheritance);
            var reader2   = GetSettingsFileReader(SettingsWithInheritanceSeparateFile);
            var lines     = reader1.ReadSettings().Concat(reader2.ReadSettings());
            var overrides = new[]
            {
                "Dev",
                "\tpackage.name	",
                "\tpackage.build	1",
                "\tpackage.date	20150709-0948"
            };

            sp.Parse(lines, overrides, "Dev", '|');
        }
Beispiel #15
0
        public void SettingsParser_Parse_Should_Raise_RevertedValue_Warnings(
            string section,
            int expectedWarnings
            )
        {
            var warnings = new HashSet <string>();
            var sp       = new SettingsParser
            {
                WriteWarning = s => warnings.Add(s)
            };

            var reader   = GetSettingsFileReader(SettingsWithInheritanceAndRevertedValueWarnings);
            var settings = sp.Parse(reader.ReadSettings(), section, '|');

            Assert.IsNotNull(settings);
            CollectionAssert.IsNotEmpty(warnings);
            Assert.AreEqual(expectedWarnings, warnings.Count);
        }
Beispiel #16
0
        public void SettingsParser_Parse_VisaSettings_ReturnsExpectedResult()
        {
            var sp       = new SettingsParser();
            var reader   = GetSettingsFileReader(VisaSettings);
            var settings = sp.Parse(reader.ReadSettings(), "Test", '|');

            Assert.IsNotNull(settings);
            Assert.AreEqual(11, settings.Keys.Count);
            Assert.AreEqual(@"VisaDebitMicroSiteAU", settings["ProjectName"][0]);
            Assert.AreEqual(@"\\reliant", settings["DeployServer"][0]);
            Assert.AreEqual(@"e:\temp", settings["DeploymentPath"][0]);
            Assert.AreEqual(@"\\reliant\e$\releasetemp", settings["RemoteReleaseWorkingFolder"][0]);
            Assert.AreEqual(@"e:\releasetemp", settings["LocalReleaseWorkingFolder"][0]);
            Assert.AreEqual(@"VisaDebitMicroSiteAUadmin", settings["AdminSiteFolder"][0]);
            Assert.AreEqual(@"VisaDebitMicroSiteAUadmin.dev.work", settings["AdminSiteUrl"][0]);
            Assert.AreEqual(@"VisaDebitMicroSiteAUweb", settings["WebSiteFolder"][0]);
            Assert.AreEqual(@"VisaDebitMicroSiteAU.dev.work", settings["WebSiteUrl"][0]);
        }
            public void KeyOnlyParse()
            {
                // Given
                string[] expected = { "hi", "=hello", "\\=abcd", "key\\=val", "     bjorn  \\=   dad" };

                // When
                IReadOnlyDictionary <string, string> args = SettingsParser.Parse(expected);

                // Then
                expected.Length.ShouldBe(args.Count);
                int i = 0;

                foreach (KeyValuePair <string, string> arg in args)
                {
                    expected[i].Replace("\\=", "=").Trim().ShouldBe(arg.Key);
                    arg.Value.ShouldBe("true");
                    i++;
                }
            }
            public void KeyValueParse()
            {
                // Given
                string[] pairs = { "key=value", "k=v", "except=bro", "awesome====123123", "   keytrimmed    =    value trimmed   " };

                // When
                IReadOnlyDictionary <string, string> args = SettingsParser.Parse(pairs);

                // Then
                pairs.Length.ShouldBe(args.Count);
                foreach (KeyValuePair <string, string> arg in args)
                {
                    arg.Value.ShouldNotBeNull("Argument value should not be null.");
                    arg.Key.ShouldNotStartWith(" ", "Arguments key should be trimmed.");
                    arg.Key.ShouldNotEndWith(" ", "Arguments key should be trimmed.");
                    arg.Value.ShouldNotStartWith(" ", "Arguments value should be trimmed.");
                    arg.Value.ShouldNotEndWith(" ", "Arguments value should be trimmed.");
                }
            }
Beispiel #19
0
        public void SettingsParser_Parse_includes_environment_profile(string section, bool include)
        {
            var sp = new SettingsParser
            {
                AppendReservedSettings = include
            };
            var reader   = GetSettingsFileReader(Basic);
            var settings = sp.Parse(reader.ReadSettings(), section, '|');

            Assert.IsNotNull(settings);

            if (include)
            {
                Assert.AreEqual(section, settings["environment.profile"][0]);
            }
            else
            {
                Assert.IsFalse(settings.ContainsKey("environment.profile"));
            }
        }
        public void Should_Parse()
        {
            var assembly         = "c:/some/assembly/path.dll";
            var connectionString = "some_connection_string";
            var container        = "my-container";
            var blob             = "my-blob";
            var tags             = new[] { "tag1", "tag2" };
            var properties       = new Dictionary <string, string>()
            {
                ["property1"] = "value1",
                ["property2"] = "value2",
            };

            var command = $"-a {assembly} -cs {connectionString} -c {container} -b {blob} -t {string.Join(" ", tags)} -p {string.Join(" ", properties.Select(x => $"{x.Key}={x.Value}"))}";

            var result = SettingsParser.Parse(command.Split(' '));

            Check.That(result.Assembly).Equals(assembly);
            Check.That(result.ConnectionString).Equals(connectionString);
            Check.That(result.Container).Equals(container);
            Check.That(result.Blob).Equals(blob);
            Check.That(result.Tags).ContainsExactly(tags);
            Check.That(result.Properties).ContainsExactly(properties);
        }
 public void KeyCollision()
 {
     // Given, When, Then
     Should.Throw <ArgumentException>(
         () => SettingsParser.Parse(new[] { "hello=world", "hello=exception" }));
 }
Beispiel #22
0
        public static void Deploy(string commandLine)
        {
            if (!_coarseLog.IsDebugEnabled)
            {
                Console.WriteLine("Sad Emo Otter says \"DEBUG LOGGING IS OFF - THIS ISN'T GOING TO BE FUN :(\"");
            }

            try
            {
                _coarseLog.Info("****************************************************");
                _coarseLog.Info("DropkicK");
                _coarseLog.Info("****************************************************");
                _coarseLog.Info("");

                DeploymentArguments newArgs = DeploymentCommandLineParser.Parse(commandLine);



                _coarseLog.Info("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
                _coarseLog.InfoFormat("Command:     {0}", newArgs.Command);
                _coarseLog.InfoFormat("Environment: {0}", newArgs.Environment);
                _coarseLog.InfoFormat("Role:        {0}", newArgs.Role);

                //////// DEPLOYMENT STUFF
                FindResult findResult = _finder.Find(newArgs.Deployment);
                Deployment deployment = findResult.Deployment;
                _coarseLog.InfoFormat("Deployment Method: '{0}'", findResult.MethodOfFinding);
                _coarseLog.InfoFormat("Deployment Found:  '{0}'", findResult.Deployment.GetType().Name);

                if (deployment.GetType().Equals(typeof(NullDeployment)))
                {
                    _coarseLog.Fatal("Couldn't find a deployment to run.");
                    return;
                }
                ////////



                ////////// File Checks
                if (!VerifyPathToServerMapsFile(newArgs.PathToServerMapsFile))
                {
                    return;
                }
                if (!VerifyPathToSettingsFile(newArgs.PathToSettingsFile))
                {
                    return;
                }
                ////////////////////

                RoleToServerMap maps = _serverParser.Parse(new FileInfo(newArgs.PathToServerMapsFile));
                newArgs.ServerMappings.Merge(maps);
                DisplayServerMappingsForEnvironment(newArgs.ServerMappings);



                _coarseLog.Info("");
                _coarseLog.Info("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
                _coarseLog.Info("Please review the settings above when you are ready,");
                _coarseLog.Info("  Press 'ctrl+c' to cancel.");

                if (deployment.HardPrompt)
                {
                    bool wrong = true;
                    do
                    {
                        _coarseLog.Info("  Please type the environment name '{0}' to continue.".FormatWith(newArgs.Environment));
                        var environment = Console.ReadLine();
                        if (environment.EqualsIgnoreCase(newArgs.Environment))
                        {
                            wrong = false;
                        }
                    } while (wrong);
                }
                else
                {
                    _coarseLog.Info("  Press enter to kick it out there");
                    Console.ReadKey(true);
                }



                /////// how to clean this up - below
                Type settingsType = deployment.GetType().BaseType.GetGenericArguments()[1];

                var settings = (DropkickConfiguration)_parser.Parse(settingsType, new FileInfo(newArgs.PathToSettingsFile), commandLine,
                                                                    newArgs.Environment);

                settings.Environment = newArgs.Environment;
                deployment.Initialize(settings);

                DeploymentPlanDispatcher.KickItOutThereAlready(deployment, newArgs);
            }
            catch (Exception ex)
            {
                _coarseLog.Debug(commandLine);
                _coarseLog.Error(ex);
            }
        }
Beispiel #23
0
 public void SettingsParser_Parse_InvalidSettings_ReturnsExpectedResult()
 {
     var sp       = new SettingsParser();
     var reader   = GetSettingsFileReader(InvalidSettings);
     var settings = sp.Parse(reader.ReadSettings(), "Dev", '|');
 }