private SplunkConfig LoadTestConfig(Mock<IFileSystem> mockFileSystem)
 {
     var config = new SplunkConfig();
     mockFileSystem.Setup(fs => fs.FileExists(It.IsAny<string>())).Returns(true);
     mockFileSystem.Setup(fs => fs.ReadFileLines(It.IsAny<string>())).Returns(TestConfigLoader.GetSplunkRC());
     var loader = new SplunkConfigLoader(mockFileSystem.Object);
     loader.Load(config);
     return config;
 }
        public void Load(SplunkConfig config)
        {
            if (!_fileSystem.FileExists(SplunkRCPath))
            {
                throw new FileNotFoundException(".splunkrc file not found", SplunkRCPath);
            }

            var lines = _fileSystem.ReadFileLines(SplunkRCPath);
            GetSettings(lines, config);
        }
        public SplunkPack(IFileSystem fileSystem)
        {
            Guard.AgainstNullArgument("fileSystem", fileSystem);

            Config = new SplunkConfig();
            _fileSystem = fileSystem;
            ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) =>
            {
                return true;
            };
        }
        public void Load(SplunkConfig config)
        {
            if (!_fileSystem.FileExists(SplunkRCPath))
            {
                throw new FileNotFoundException(".splunkrc file not found", SplunkRCPath);
            }

            var lines = _fileSystem.ReadFileLines(SplunkRCPath);

            GetSettings(lines, config);
        }
        private void GetSettings(string[] lines, SplunkConfig config)
        {
            var argList = new List <string>();

            foreach (var line in lines)
            {
                var trimmedLine = line.Trim();

                if (trimmedLine.StartsWith("#", StringComparison.InvariantCulture))
                {
                    continue;
                }

                if (trimmedLine.Length == 0)
                {
                    continue;
                }

                argList.Add(trimmedLine);
            }

            foreach (string arg in argList)
            {
                string[] pair = arg.Split('=');

                switch (pair[0].ToLower().Trim())
                {
                case "scheme":
                    config.Scheme = pair[1].Trim() == "https" ? Scheme.Https : Scheme.Http;
                    break;

                case "host":
                    config.Host = pair[1].Trim();
                    break;

                case "port":
                    config.Port = int.Parse(pair[1].Trim());
                    break;

                case "username":
                    config.Username = pair[1].Trim();
                    break;

                case "password":
                    config.Password = pair[1].Trim();
                    break;
                }
            }
        }
        private void GetSettings(string[] lines, SplunkConfig config)
        {
            var argList = new List<string>();

            foreach (var line in lines)
            {
                var trimmedLine = line.Trim();

                if (trimmedLine.StartsWith("#", StringComparison.InvariantCulture))
                {
                    continue;
                }

                if (trimmedLine.Length == 0)
                {
                    continue;
                }

                argList.Add(trimmedLine);
            }

            foreach (string arg in argList)
            {
                string[] pair = arg.Split('=');

                switch (pair[0].ToLower().Trim())
                {
                    case "scheme":
                        config.Scheme = pair[1].Trim() == "https" ? Scheme.Https : Scheme.Http;
                        break;
                    case "host":
                        config.Host = pair[1].Trim();
                        break;
                    case "port":
                        config.Port = int.Parse(pair[1].Trim());
                        break;
                    case "username":
                        config.Username = pair[1].Trim();
                        break;
                    case "password":
                        config.Password = pair[1].Trim();
                        break;
                }
            }

        }
 public void ThrowsAnExceptionIfTheFileDoesNotExist(Mock<IFileSystem> mockFileSystem, SplunkConfig config)
 {
     mockFileSystem.Setup(f => f.FileExists(It.IsAny<string>())).Returns(false);
     var loader = new SplunkConfigLoader(mockFileSystem.Object, "test");
     Assert.Throws<FileNotFoundException>(() => loader.Load(config));
 }