Esempio n. 1
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
            .AddXmlSerializerFormatters();

            services.AddMvc(option => option.EnableEndpointRouting = false);

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,

                    ValidIssuer      = pconfig.ManagementApiIssuer,
                    ValidAudience    = pconfig.ManagementApiAudience,
                    ClockSkew        = TimeSpan.FromMinutes(5.0),
                    IssuerSigningKey =
                        new SymmetricSecurityKey(Convert.FromBase64String(pconfig.ManagmentApiSymmetricKey))
                };
            });

            PskStorageAdapter pskAdpater = GetPskAdapter();

            if (pskAdpater != null)
            {
                services.AddSingleton(pskAdpater);
            }

            services.AddPiraeusConfiguration();
            services.AddOrleansConfiguration();
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddSingleton <ILog, Logger>();
            services.AddLogging(log =>
            {
                log.AddConsole();
                log.SetMinimumLevel(Enum.Parse <LogLevel>(pconfig.LogLevel));
            });

            if (!string.IsNullOrEmpty(pconfig.InstrumentationKey))
            {
                services.AddApplicationInsightsTelemetry(pconfig.InstrumentationKey);
            }

            services.AddSingletonOrleansClusterClient(WebApiHelpers.GetOrleansConfig());
            services.AddRouting();
        }
Esempio n. 2
0
        public static IHostBuilder CreateHostBuilder(string[] args)
        {
            return(Host.CreateDefaultBuilder(args)
                   .ConfigureServices(services => services.AddPiraeusConfiguration())
                   .ConfigureWebHostDefaults(webBuilder =>
            {
                PiraeusConfig config = WebApiHelpers.GetPiraeusConfig();
                webBuilder
                .ConfigureKestrel(options =>
                {
                    options.Limits.MaxConcurrentConnections = config.MaxConnections;
                    options.Limits.MaxConcurrentUpgradedConnections = config.MaxConnections;
                    options.Limits.MaxRequestBodySize = config.MaxBufferSize;
                    options.Limits.MinRequestBodyDataRate =
                        new MinDataRate(100, TimeSpan.FromSeconds(10));
                    options.Limits.MinResponseDataRate =
                        new MinDataRate(100, TimeSpan.FromSeconds(10));
                    X509Certificate2 cert = config.GetServerCerticate();
                    int[] ports = config.GetPorts();

                    foreach (int port in ports)
                    {
                        if (cert != null)
                        {
                            options.ListenAnyIP(port, a => a.UseHttps(cert));
                        }
                        else
                        {
                            IPAddress address = GetIPAddress(Dns.GetHostName());
                            options.Listen(address, port);
                        }
                    }

                    if (!string.IsNullOrEmpty(config.ServerCertificateFilename))
                    {
                        string[] portStrings = config.Ports.Split(";", StringSplitOptions.RemoveEmptyEntries);

                        foreach (string portString in portStrings)
                        {
                            options.ListenAnyIP(Convert.ToInt32(portString),
                                                a => a.UseHttps(config.ServerCertificateFilename,
                                                                config.ServerCertificatePassword));
                        }
                    }
                });
                webBuilder.UseStartup <Startup>();
            }));
        }
Esempio n. 3
0
 public Startup(IConfiguration configuration)
 {
     Configuration = configuration;
     pconfig       = WebApiHelpers.GetPiraeusConfig();
 }