Пример #1
0
        public AuthenticationRepo(YamlSettings yamlSettings, DataKeys dataKeys, AuthSkeleton authSkeleton)
        {
            _yamlSettings = yamlSettings;
            _dataKeys     = dataKeys;
            _authSkeleton = authSkeleton;
            _auths        = new List <Auth>();

            var data = YamlConfigurationFileParser.Parse(_yamlSettings.YamlDataFile);

            foreach (KeyValuePair <string, YamlSequenceNode> entry in data)
            {
                if (entry.Key.Contains(_dataKeys.AuthKey))
                {
                    foreach (YamlMappingNode node in entry.Value) // Auths
                    {
                        Auth auth = new Auth();
                        foreach (var item in node.Children) // each auth
                        {
                            var key   = item.Key.ToString();
                            var value = item.Value;

                            if (key.Equals(_authSkeleton.UserName))
                            {
                                auth.UserName = value.ToString();
                            }
                            else if (key.Equals(_authSkeleton.Password))
                            {
                                auth.Password = value.ToString();
                            }
                        }
                        _auths.Add(auth);
                    }
                }
            }
        }
Пример #2
0
        public YamlSettings ConvertToYaml()
        {
            YamlSettings yaml = Convert <YamlSettings>();

            yaml.MetaCritic = MetaCritic.Convert <YamlMetaCritic>();
            yaml.Weights    = Weights.Convert <YamlWeights>();
            return(yaml);
        }
Пример #3
0
        public void GetsSetting()
        {
            var settings = new YamlSettings("TestFiles\\Config.yaml");

            var result = settings.Get("TestSetting1");

            Assert.AreEqual("TestSetting1Value", result);
        }
Пример #4
0
        public void GetsAllSettings()
        {
            var settings = new YamlSettings("TestFiles\\Config.yaml");

            var result = settings.GetAll();

            Assert.AreEqual("TestSetting1Value", result["TestSetting1"]);
            Assert.AreEqual("TestSetting2Value", result["TestSetting2"]);
        }
Пример #5
0
        public void GivenInvalidFileLocation_ThenItThrows()
        {
            var settings = new YamlSettings {
                Location = "foo.yml"
            };
            var options = MockRepository.Of <IOptionsMonitor <YamlSettings> >().First(x => x.CurrentValue == settings);
            var source  = new YamlJobSource(options);

            var exception = Assert.Throws <FileNotFoundException>(() => source.GetJobs());

            exception.Should().NotBeNull();
        }
Пример #6
0
        public CustomerRepo(YamlSettings yamlSettings, DataKeys dataKeys, CustomerSkeleton customerSkeleton)
        {
            _customers        = new List <Customer>();
            _yamlSettings     = yamlSettings;
            _dataKeys         = dataKeys;
            _customerSkeleton = customerSkeleton;

            var data = YamlConfigurationFileParser.Parse(_yamlSettings.YamlDataFile);

            foreach (KeyValuePair <string, YamlSequenceNode> entry in data)
            {
                if (entry.Key.Contains(_dataKeys.CustomerKey))
                {
                    foreach (YamlMappingNode node in entry.Value) // customers
                    {
                        Customer customer = new Customer();
                        foreach (var item in node.Children) // each customer
                        {
                            var key   = item.Key.ToString();
                            var value = item.Value;

                            if (key.Equals(_customerSkeleton.Id))
                            {
                                customer.Id = value.ToString();
                            }
                            else if (key.Equals(_customerSkeleton.Name))
                            {
                                customer.Name = value.ToString();
                            }
                            else if (key.Equals(_customerSkeleton.EmpNum))
                            {
                                customer.EmpNum = value.ToString();
                            }
                            else if (key.Equals(_customerSkeleton.Tags))
                            {
                                var tags = Regex.Replace(value.ToString(), @"[\[\]\s+]", string.Empty).Replace(",", " ");
                                customer.Tags = tags;
                            }
                        }
                        _customers.Add(customer);
                    }
                }
            }
        }
Пример #7
0
        public void GivenValidSource_ThenItReturnsJobs()
        {
            var settings = new YamlSettings {
                Location = "jobs.yml"
            };
            var options = MockRepository.Of <IOptionsMonitor <YamlSettings> >().First(x => x.CurrentValue == settings);
            var source  = new YamlJobSource(options);

            var jobs = source.GetJobs().ToList();

            jobs.Should().NotBeNullOrEmpty();
            jobs.Count.Should().Be(2);

            var job = jobs.First();

            job.Should().NotBeNull();
            job.Name.Should().BeEquivalentTo("Test job A");
            job.Location.Should().BeEquivalentTo("test.ps1");
            job.Type.Should().Be(JobType.Powershell);
            job.Schedule.Should().BeEquivalentTo("* * * * *");
        }
Пример #8
0
        public void InstallServices(IServiceCollection services, IConfiguration configuration)
        {
            services.AddMvc();
            services.AddCors();


            var clientEndPoint = new ClientEndPoint();

            configuration.Bind(nameof(clientEndPoint), clientEndPoint);
            services.AddSingleton <ClientEndPoint>(clientEndPoint);

            var authSkeleton = new AuthSkeleton();

            configuration.Bind(nameof(authSkeleton), authSkeleton);
            services.AddSingleton <AuthSkeleton>(authSkeleton);

            var customerSkeleton = new CustomerSkeleton();

            configuration.Bind(nameof(customerSkeleton), customerSkeleton);
            services.AddSingleton <CustomerSkeleton>(customerSkeleton);

            var dataKeys = new DataKeys();

            configuration.Bind(nameof(dataKeys), dataKeys);
            services.AddSingleton <DataKeys>(dataKeys);

            var yamlSettings = new YamlSettings();

            configuration.Bind(nameof(yamlSettings), yamlSettings);
            services.AddSingleton <YamlSettings>(yamlSettings);

            var jwtSettings = new JwtSettings();

            configuration.Bind(nameof(jwtSettings), jwtSettings);
            services.AddSingleton <JwtSettings>(jwtSettings);

            var tokenValidationParameters = new TokenValidationParameters
            {
                ValidateIssuerSigningKey = true,
                IssuerSigningKey         = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(jwtSettings.Secret)),
                ValidateIssuer           = false,
                ValidateAudience         = false,
                RequireExpirationTime    = false,
                ValidateLifetime         = true
            };

            services.AddSingleton(tokenValidationParameters);
            services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultScheme             = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(x =>
            {
                x.SaveToken = true;
                x.TokenValidationParameters = tokenValidationParameters;
            });

            services.AddSwaggerGen(x =>
            {
                x.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Customer API", Version = "v1"
                });
                var security = new Dictionary <string, IEnumerable <string> >
                {
                    { "Bearer", new string[0] }
                };
                x.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
                {
                    Description = "JWT Authorization header using the Bearer scheme",
                    Name        = "Authorization",
                    In          = ParameterLocation.Header,
                    Type        = SecuritySchemeType.ApiKey,
                    Scheme      = "Bearer"
                });
                x.AddSecurityRequirement(new OpenApiSecurityRequirement()
                {
                    {
                        new OpenApiSecurityScheme
                        {
                            Reference = new OpenApiReference
                            {
                                Type = ReferenceType.SecurityScheme,
                                Id   = "Bearer"
                            },
                            Scheme = "oauth2",
                            Name   = "Bearer",
                            In     = ParameterLocation.Header
                        },
                        new List <string>()
                    }
                });
            });
        }
Пример #9
0
 public HttpServer(YamlSettings settings)
 {
     this.settings = settings;
 }