2021-06-18 23:57:02 +01:00
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
2021-04-08 02:03:17 +01:00
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2021-04-25 12:12:50 +01:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2021-04-08 02:03:17 +01:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2021-04-25 12:12:50 +01:00
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
|
|
using Microsoft.AspNetCore.Identity.UI.Services;
|
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
2021-07-05 12:55:52 +01:00
|
|
|
|
using isn.Data;
|
|
|
|
|
|
using isn.Interfaces;
|
|
|
|
|
|
using isn.Services;
|
|
|
|
|
|
using isn.Entities;
|
|
|
|
|
|
using isn.Authorization;
|
|
|
|
|
|
using isn.Data.Roles;
|
2021-06-18 23:57:02 +01:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2021-07-05 12:55:52 +01:00
|
|
|
|
using Unleash;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using Unleash.ClientFactory;
|
|
|
|
|
|
using isnd.Entities;
|
|
|
|
|
|
using Microsoft.Extensions.Options;
|
2021-07-11 22:13:48 +01:00
|
|
|
|
using isnd.Helpers;
|
2021-04-08 02:03:17 +01:00
|
|
|
|
|
2021-07-05 12:55:52 +01:00
|
|
|
|
namespace isn
|
2021-04-08 02:03:17 +01:00
|
|
|
|
{
|
|
|
|
|
|
public class Startup
|
|
|
|
|
|
{
|
2021-04-08 03:08:20 +01:00
|
|
|
|
public Startup(IConfiguration config)
|
2021-04-08 02:03:17 +01:00
|
|
|
|
{
|
|
|
|
|
|
Configuration = config;
|
2021-07-05 12:55:52 +01:00
|
|
|
|
|
2021-04-08 02:03:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IConfiguration Configuration { get; }
|
|
|
|
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
|
|
{
|
2021-04-25 12:12:50 +01:00
|
|
|
|
services.AddDbContext<ApplicationDbContext>(options =>
|
|
|
|
|
|
options.UseNpgsql(
|
|
|
|
|
|
Configuration.GetConnectionString("DefaultConnection")));
|
2021-07-05 12:55:52 +01:00
|
|
|
|
|
2021-04-08 03:08:20 +01:00
|
|
|
|
|
2021-04-25 12:12:50 +01:00
|
|
|
|
services.AddIdentity<ApplicationUser, IdentityRole>()
|
2021-06-18 23:57:02 +01:00
|
|
|
|
.AddRoles<IdentityRole>()
|
|
|
|
|
|
.AddEntityFrameworkStores<ApplicationDbContext>()
|
2021-04-25 12:12:50 +01:00
|
|
|
|
.AddSignInManager()
|
|
|
|
|
|
.AddDefaultUI()
|
|
|
|
|
|
.AddDefaultTokenProviders();
|
|
|
|
|
|
|
2021-04-08 02:03:17 +01:00
|
|
|
|
services.AddMvc();
|
2021-04-08 03:08:20 +01:00
|
|
|
|
|
|
|
|
|
|
services.AddDataProtection();
|
2021-07-05 12:55:52 +01:00
|
|
|
|
|
2021-04-25 12:12:50 +01:00
|
|
|
|
services.AddTransient<IMailer, EmailSender>();
|
|
|
|
|
|
services.AddTransient<IEmailSender, EmailSender>();
|
2021-04-08 03:08:20 +01:00
|
|
|
|
|
2021-06-18 23:57:02 +01:00
|
|
|
|
services.AddAuthorization(options =>
|
|
|
|
|
|
{
|
|
|
|
|
|
options.AddPolicy(Constants.RequireAdminPolicyName,
|
|
|
|
|
|
policy => policy.RequireRole(Constants.AdministratorRoleName));
|
|
|
|
|
|
options.AddPolicy(Constants.RequireValidApiKey, policy =>
|
|
|
|
|
|
policy.Requirements.Add(new ValidApiKeyRequirement()));
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
services.AddSingleton<IAuthorizationHandler, ValidApiKeyRequirementHandler>();
|
2021-07-11 22:13:48 +01:00
|
|
|
|
services.AddSingleton<IUnleash>(s =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var config = s.GetRequiredService<IOptions<UnleashClientSettings>>();
|
|
|
|
|
|
return s.GetRequiredService<Microsoft.AspNetCore.Hosting.IHostingEnvironment>().CreateUnleahClient(config.Value);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// _unleashĈlient = env.CreateUnleahClient(unleashClientSettings.Value);
|
2021-05-02 16:37:03 +01:00
|
|
|
|
var smtpSettingsconf = Configuration.GetSection("Smtp");
|
2021-04-25 12:12:50 +01:00
|
|
|
|
services.Configure<SmtpSettings>(smtpSettingsconf);
|
2021-05-02 16:37:03 +01:00
|
|
|
|
var nugetSettingsconf = Configuration.GetSection("Nuget");
|
2021-05-02 15:22:46 +01:00
|
|
|
|
services.Configure<NugetSettings>(nugetSettingsconf);
|
2021-06-18 23:57:02 +01:00
|
|
|
|
var adminStartupListConf = Configuration.GetSection("AdminList");
|
|
|
|
|
|
services.Configure<AdminStartupList>(adminStartupListConf);
|
2021-07-05 12:55:52 +01:00
|
|
|
|
var unleashConf = Configuration.GetSection("Unleash");
|
|
|
|
|
|
services.Configure<UnleashClientSettings>(unleashConf);
|
2021-06-21 23:38:05 +01:00
|
|
|
|
services.Configure<MigrationsEndPointOptions>(o => o.Path = "~/migrate");
|
2021-04-08 02:03:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-05 12:55:52 +01:00
|
|
|
|
|
|
|
|
|
|
public static IUnleash UnleashĈlient { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-08 02:03:17 +01:00
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
2021-07-05 12:55:52 +01:00
|
|
|
|
public void Configure(IApplicationBuilder app,
|
|
|
|
|
|
Microsoft.AspNetCore.Hosting.IHostingEnvironment env,
|
2021-05-09 01:52:46 +01:00
|
|
|
|
ApplicationDbContext dbContext)
|
2021-04-08 02:03:17 +01:00
|
|
|
|
{
|
|
|
|
|
|
if (env.IsDevelopment())
|
|
|
|
|
|
{
|
2021-04-25 12:12:50 +01:00
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
|
|
app.UseMigrationsEndPoint();
|
2021-04-08 02:03:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2021-05-23 01:00:57 +01:00
|
|
|
|
// app.UseExceptionHandler("/Home/Error");
|
|
|
|
|
|
app.UseDeveloperExceptionPage();
|
2021-05-09 14:56:32 +01:00
|
|
|
|
dbContext.Database.Migrate();
|
2021-04-08 02:03:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-11 18:08:49 +01:00
|
|
|
|
|
2021-04-08 02:03:17 +01:00
|
|
|
|
|
2021-07-05 12:55:52 +01:00
|
|
|
|
app.UseStatusCodePages().UseStaticFiles().UseAuthentication().UseMvc(routes =>
|
2021-04-08 02:03:17 +01:00
|
|
|
|
{
|
|
|
|
|
|
routes.MapRoute(
|
|
|
|
|
|
name: "default",
|
2021-05-23 01:00:57 +01:00
|
|
|
|
template: "{controller=PackageVersion}/{action=Index}/{PackageId?}");
|
2021-04-08 02:03:17 +01:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|