internal static ServiceConfig GetServiceConfig() { // Load service configuration file Console.WriteLine("Loading service configuration file: " + Utils.SecretNames.ServiceConfigFile); string serviceConfigJson = Utils.GetSecretOrEnvVar(Utils.SecretNames.ServiceConfigFile); if (serviceConfigJson == null || serviceConfigJson.Length == 0) { throw new ApplicationException("Invalid service configuration file: " + Utils.SecretNames.ServiceConfigFile); } Utils.ServiceConfig svccfg = JsonConvert.DeserializeObject <Utils.ServiceConfig>(serviceConfigJson); return(svccfg); }
internal static int GetMaxRows() { if (max_rows == -1) { // Load the service configuration file Utils.ServiceConfig svccfg = Utils.GetServiceConfig(); max_rows = 1000; if (svccfg.max_rows > 0) { max_rows = svccfg.max_rows; } } return(max_rows); }
internal static DataFactory.DataConfig GetDataConfig() { // Load the service config file string serviceConfigJson = Utils.GetSecretOrEnvVar(Utils.SecretNames.ServiceConfigFile); if (serviceConfigJson == null || serviceConfigJson.Length == 0) { throw new ApplicationException("Invalid service configuration file: " + Utils.SecretNames.ServiceConfigFile); } Utils.ServiceConfig svccfg = JsonConvert.DeserializeObject <Utils.ServiceConfig>(serviceConfigJson); // Get the data configuration string dataStorageType = svccfg.data_storage_service_type.Trim(); string connString = svccfg.data_storage_connection_string.Trim(); string databaseName = svccfg.database_name.Trim(); // Return the config DataFactory.DataConfig dc = new DataFactory.DataConfig(); dc.ProviderType = dataStorageType; dc.ConnectionString = connString; dc.DatabaseName = databaseName; return(dc); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Load the service configuration file Utils.ServiceConfig svccfg = Utils.GetServiceConfig(); // Load configuration values Console.WriteLine("Loading Allowed CORS URLs..."); if (svccfg.url_allowed_cors == null || svccfg.url_allowed_cors.Length == 0) { throw new ApplicationException("Invalid configuration entry: allowed_cors"); } Console.WriteLine("CORS Url(s): " + svccfg.url_allowed_cors); string[] corsUrls = svccfg.url_allowed_cors.Split(",", StringSplitOptions.RemoveEmptyEntries); Console.WriteLine("Loading Identity Server Url..."); if (svccfg.url_identity_server == null || svccfg.url_identity_server.Length == 0) { throw new ApplicationException("Invalid configuration entry: url_identity_server"); } svccfg.url_identity_server = "http://localhost:5000"; // Vikas Console.WriteLine("Identity Server Url: " + svccfg.url_identity_server); // Check for any startup commands if (svccfg.startup_commands != null && svccfg.startup_commands.Count > 0) { // Process each command foreach (Utils.StartupCommand command in svccfg.startup_commands) { Console.WriteLine("Starting process: " + command.command); Process startProcess = Process.Start(command.command, command.arguments); Console.WriteLine("Waiting 10 seconds..."); startProcess.WaitForExit(10000); if (!startProcess.HasExited) { Console.WriteLine("WARNING: Startup process not completed within 10 seconds, continuing startup functions"); } else { Console.WriteLine("Startup process finished (NOTE: does not indicate success!)"); } } } Console.WriteLine("Adding logging..."); // Enable logging of identity model events that may contain PII (required for .well-known debugging issues) Microsoft.IdentityModel.Logging.IdentityModelEventSource.ShowPII = true; services.AddLogging(); // Add CORS Console.WriteLine("Adding CORS..."); services.AddCors(options => { //options.AddPolicy("AllowAllCors", // builder => builder.AllowAnyOrigin() // .AllowAnyMethod() // .AllowAnyHeader() // .AllowCredentials() // ); // "https://atsmeptyltd.sharepoint.com","https://stlpcastlepoint.sharepoint.com","http://localhost:6060", https://web.stlp.castlepoint.systems options.AddPolicy("AllowRestrictedCors", builder => builder.WithOrigins(svccfg.url_allowed_cors) .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials() ); }); // Add Authentication Console.WriteLine("Adding Authentication..."); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { // base-address of your identityserver options.Authority = svccfg.url_identity_server; // if you are using API resources, you can specify the name here //options.Audience = "castlepoint"; // IdentityServer emits a typ header by default, recommended extra check options.TokenValidationParameters.ValidTypes = new[] { "at+jwt" }; // Remove audience validation options.TokenValidationParameters.ValidateAudience = false; }); // GM 20200727 // Removed legacy ID4 v3 code //services.AddAuthentication(options => //{ // options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; // options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; //}) //.AddIdentityServerAuthentication(options => //{ // options.Authority = svccfg.url_identity_server; // options.RequireHttpsMetadata = false; // options.ApiName = "castlepoint"; //}); // Add localization services.AddLocalization(options => options.ResourcesPath = "Resources"); // Configure MVC with Authorization Console.WriteLine("Adding authorization..."); services.AddMvcCore(options => options.EnableEndpointRouting = false) .AddAuthorization() .AddNewtonsoftJson() .AddMvcLocalization() .AddApiExplorer(); // Add the Swagger API explorer // Add Swagger documentation generation services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Castlepoint API", Version = "v1" }); }); services.AddSwaggerGenNewtonsoftSupport(); // explicit opt-in - needs to be placed after AddSwaggerGen() }