From 5cd1c99d442d8e32ef653371ef479319f64e68d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Thu, 5 Aug 2021 14:56:25 +0300 Subject: [PATCH] revized config --- etc/k8s/README.md | 5 +++ .../eventhub/templates/_helpers.tpl | 8 +++++ etc/k8s/helm-chart/eventhub/values.yaml | 6 +++- .../appsettings.Development.json | 2 -- .../Web/EventHubUrlOptions.cs | 32 +++++++++++++++++ .../EventHubHttpApiHostModule.cs | 7 ++-- .../appsettings.Development.json | 14 -------- src/EventHub.HttpApi.Host/appsettings.json | 13 ++----- .../EventHubIdentityServerModule.cs | 34 ++++++++----------- .../appsettings.Development.json | 8 ----- src/EventHub.IdentityServer/appsettings.json | 22 +----------- src/EventHub.Web/EventHubWebModule.cs | 8 ++++- src/EventHub.Web/appsettings.Development.json | 3 -- src/EventHub.Web/appsettings.json | 17 ++-------- 14 files changed, 82 insertions(+), 97 deletions(-) create mode 100644 etc/k8s/README.md delete mode 100644 src/EventHub.Admin.HttpApi.Host/appsettings.Development.json delete mode 100644 src/EventHub.HttpApi.Host/appsettings.Development.json delete mode 100644 src/EventHub.IdentityServer/appsettings.Development.json delete mode 100644 src/EventHub.Web/appsettings.Development.json diff --git a/etc/k8s/README.md b/etc/k8s/README.md new file mode 100644 index 0000000..c215f05 --- /dev/null +++ b/etc/k8s/README.md @@ -0,0 +1,5 @@ +### How to run? + +* Run `build-images.ps1` in the `scripts` directory. +* Run `helm install eh-st eventhub` in the `helm-chart` directory. + diff --git a/etc/k8s/helm-chart/eventhub/templates/_helpers.tpl b/etc/k8s/helm-chart/eventhub/templates/_helpers.tpl index 40ef14c..f908b84 100644 --- a/etc/k8s/helm-chart/eventhub/templates/_helpers.tpl +++ b/etc/k8s/helm-chart/eventhub/templates/_helpers.tpl @@ -9,4 +9,12 @@ value: "{{ .Values.global.adminUrlFull }}" - name: "AppUrls__AdminApi" value: "{{ .Values.global.adminApiUrlFull }}" +- name: "Redis__Configuration" + value: "{{ .Values.global.redisConfiguration }}" +- name: "AuthServer__Authority" + value: "{{ .Values.global.internalAuthServerAuthority }}" +- name: "AuthServer__RequireHttpsMetadata" + value: "{{ .Values.global.internalAuthServerRequireHttpsMetadata }}" +- name: "StringEncryption__DefaultPassPhrase" + value: "{{ .Values.global.stringEncryptionDefaultPassPhrase }}" {{- end }} \ No newline at end of file diff --git a/etc/k8s/helm-chart/eventhub/values.yaml b/etc/k8s/helm-chart/eventhub/values.yaml index d55d3e8..652460c 100644 --- a/etc/k8s/helm-chart/eventhub/values.yaml +++ b/etc/k8s/helm-chart/eventhub/values.yaml @@ -11,4 +11,8 @@ global: adminApiUrlFull: https://eh-st-admin-api nginxProxyBufferSize: "32k" nginxProxyBuffersNumber: "8" - defaultConnString: "Host=eh-st-postgresql;Port=5435;Database=EventHub;Username=root;Password=root" \ No newline at end of file + defaultConnString: "Host=eh-st-postgresql;Port=5435;Database=EventHub;Username=root;Password=root" + redisConfiguration: "eh-st-redis" + internalAuthServerAuthority: "http://eh-st-account" + internalAuthServerRequireHttpsMetadata: "false" + stringEncryptionDefaultPassPhrase: "TxVIZFPxK33czbbv" \ No newline at end of file diff --git a/src/EventHub.Admin.HttpApi.Host/appsettings.Development.json b/src/EventHub.Admin.HttpApi.Host/appsettings.Development.json deleted file mode 100644 index 2c63c08..0000000 --- a/src/EventHub.Admin.HttpApi.Host/appsettings.Development.json +++ /dev/null @@ -1,2 +0,0 @@ -{ -} diff --git a/src/EventHub.Domain.Shared/Web/EventHubUrlOptions.cs b/src/EventHub.Domain.Shared/Web/EventHubUrlOptions.cs index 1e2873c..eec5b04 100644 --- a/src/EventHub.Domain.Shared/Web/EventHubUrlOptions.cs +++ b/src/EventHub.Domain.Shared/Web/EventHubUrlOptions.cs @@ -2,10 +2,42 @@ { public class EventHubUrlOptions { + private const string ConfigurationName = "AppUrls"; + public string Account { get; set; } = "https://localhost:44313"; public string Www { get; set; } = "https://localhost:44308"; public string Api { get; set; } = "https://localhost:44362"; public string Admin { get; set; } = "https://localhost:44307"; public string AdminApi { get; set; } = "https://localhost:44305"; + + public static string GetAccountConfigKey() + { + return GetConfigKey(nameof(Account)); + } + + public static string GetWwwConfigKey() + { + return GetConfigKey(nameof(Www)); + } + + public static string GetApiConfigKey() + { + return GetConfigKey(nameof(Api)); + } + + public static string GetAdminConfigKey() + { + return GetConfigKey(nameof(Admin)); + } + + public static string GetAdminApiConfigKey() + { + return GetConfigKey(nameof(AdminApi)); + } + + private static string GetConfigKey(string appName) + { + return $"{ConfigurationName}:{appName}"; + } } } \ No newline at end of file diff --git a/src/EventHub.HttpApi.Host/EventHubHttpApiHostModule.cs b/src/EventHub.HttpApi.Host/EventHubHttpApiHostModule.cs index 5814887..6bc3a7b 100644 --- a/src/EventHub.HttpApi.Host/EventHubHttpApiHostModule.cs +++ b/src/EventHub.HttpApi.Host/EventHubHttpApiHostModule.cs @@ -11,6 +11,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using EventHub.EntityFrameworkCore; +using EventHub.Web; using Microsoft.AspNetCore.Localization; using StackExchange.Redis; using Microsoft.OpenApi.Models; @@ -26,6 +27,7 @@ using Volo.Abp.Caching.StackExchangeRedis; using Volo.Abp.Localization; using Volo.Abp.Modularity; using Volo.Abp.Swashbuckle; +using Volo.Abp.UI.Navigation.Urls; using Volo.Abp.VirtualFileSystem; namespace EventHub @@ -158,10 +160,7 @@ namespace EventHub { builder .WithOrigins( - configuration["App:CorsOrigins"] - .Split(",", StringSplitOptions.RemoveEmptyEntries) - .Select(o => o.RemovePostFix("/")) - .ToArray() + configuration[EventHubUrlOptions.GetWwwConfigKey()] ) .WithAbpExposedHeaders() .SetIsOriginAllowedToAllowWildcardSubdomains() diff --git a/src/EventHub.HttpApi.Host/appsettings.Development.json b/src/EventHub.HttpApi.Host/appsettings.Development.json deleted file mode 100644 index 1455394..0000000 --- a/src/EventHub.HttpApi.Host/appsettings.Development.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "ConnectionStrings": { - "Default": "Host=localhost;Database=EventHub;Username=root;Password=root;Port=5432" - }, - "Redis": { - "Configuration": "127.0.0.1" - }, - "AuthServer": { - "Authority": "https://localhost:44313", - "RequireHttpsMetadata": "true", - "SwaggerClientId": "EventHub_Swagger", - "SwaggerClientSecret": "1q2w3e*" - } -} diff --git a/src/EventHub.HttpApi.Host/appsettings.json b/src/EventHub.HttpApi.Host/appsettings.json index 423ad5a..aca9ac1 100644 --- a/src/EventHub.HttpApi.Host/appsettings.json +++ b/src/EventHub.HttpApi.Host/appsettings.json @@ -1,21 +1,14 @@ { - "App": { - "CorsOrigins": "https://eh-st-www,eh-st-admin", - "WebAppUrl": "https://eh-st-www" - }, "ConnectionStrings": { "Default": "Host=localhost;Database=EventHub;Username=root;Password=root;Port=5432" }, "Redis": { - "Configuration": "eh-st-redis" + "Configuration": "localhost" }, "AuthServer": { - "Authority": "http://eh-st-account", - "RequireHttpsMetadata": "false", + "Authority": "https://localhost:44313", + "RequireHttpsMetadata": "true", "SwaggerClientId": "EventHub_Swagger", "SwaggerClientSecret": "1q2w3e*" - }, - "StringEncryption": { - "DefaultPassPhrase": "TxVIZFPxK33czbbv" } } diff --git a/src/EventHub.IdentityServer/EventHubIdentityServerModule.cs b/src/EventHub.IdentityServer/EventHubIdentityServerModule.cs index 99a3e37..da0fb56 100644 --- a/src/EventHub.IdentityServer/EventHubIdentityServerModule.cs +++ b/src/EventHub.IdentityServer/EventHubIdentityServerModule.cs @@ -1,6 +1,4 @@ -using System; using System.IO; -using System.Linq; using System.Security.Cryptography.X509Certificates; using Localization.Resources.AbpUi; using Microsoft.AspNetCore.Builder; @@ -17,13 +15,11 @@ using IdentityServer4.Configuration; using IdentityServer4.Extensions; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; -using Microsoft.IdentityModel.Tokens; using StackExchange.Redis; using Volo.Abp; using Volo.Abp.Account; using Volo.Abp.Account.Web; using Volo.Abp.AspNetCore.Mvc.UI.Bundling; -using Volo.Abp.AspNetCore.Mvc.UI.Components.LayoutHook; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; using Volo.Abp.AspNetCore.Serilog; using Volo.Abp.Auditing; @@ -119,14 +115,9 @@ namespace EventHub options.ApplicationName = "AuthServer"; }); - Configure(options => - { - options.Applications["MVC"].RootUrl = configuration["App:SelfUrl"]; - }); - Configure(options => { - options.IssuerUri = configuration["App:SelfUrl"]; + options.IssuerUri = configuration["AppUrls:Account"]; }); if (hostingEnvironment.IsDevelopment()) @@ -141,8 +132,13 @@ namespace EventHub Configure(options => { - options.Applications["MVC"].RootUrl = configuration["App:SelfUrl"]; - options.RedirectAllowedUrls.AddRange(configuration["App:RedirectAllowedUrls"].Split(',')); + options.Applications["MVC"].RootUrl = configuration[EventHubUrlOptions.GetAccountConfigKey()]; + options.RedirectAllowedUrls.AddRange( + new[] + { + configuration[EventHubUrlOptions.GetWwwConfigKey()], + configuration[EventHubUrlOptions.GetAdminConfigKey()] + }); }); Configure(options => @@ -166,10 +162,10 @@ namespace EventHub { builder .WithOrigins( - configuration["App:CorsOrigins"] - .Split(",", StringSplitOptions.RemoveEmptyEntries) - .Select(o => o.RemovePostFix("/")) - .ToArray() + configuration[EventHubUrlOptions.GetWwwConfigKey()], + configuration[EventHubUrlOptions.GetApiConfigKey()], + configuration[EventHubUrlOptions.GetAdminConfigKey()], + configuration[EventHubUrlOptions.GetAdminApiConfigKey()] ) .WithAbpExposedHeaders() .SetIsOriginAllowedToAllowWildcardSubdomains() @@ -186,7 +182,7 @@ namespace EventHub { var app = context.GetApplicationBuilder(); var env = context.GetEnvironment(); - var conf = context.ServiceProvider.GetRequiredService(); + var configuration = context.ServiceProvider.GetRequiredService(); /* app.Use((context, next) => @@ -200,7 +196,7 @@ namespace EventHub { if (ctx.Request.Headers.ContainsKey("fromingress")) { - ctx.SetIdentityServerOrigin(conf["App:SelfUrl"]); + ctx.SetIdentityServerOrigin(configuration[EventHubUrlOptions.GetAccountConfigKey()]); } await next(); @@ -221,7 +217,7 @@ namespace EventHub app.UseCookiePolicy(); app.UseCorrelationId(); - app.UseVirtualFiles(); + app.UseStaticFiles(); app.UseRouting(); app.UseCors(DefaultCorsPolicyName); app.UseAuthentication(); diff --git a/src/EventHub.IdentityServer/appsettings.Development.json b/src/EventHub.IdentityServer/appsettings.Development.json deleted file mode 100644 index de1a3cb..0000000 --- a/src/EventHub.IdentityServer/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "ConnectionStrings": { - "Default": "Host=localhost;Database=EventHub;Username=root;Password=root;Port=5432" - }, - "Redis": { - "Configuration": "localhost" - } -} \ No newline at end of file diff --git a/src/EventHub.IdentityServer/appsettings.json b/src/EventHub.IdentityServer/appsettings.json index 7195084..85f4ef3 100644 --- a/src/EventHub.IdentityServer/appsettings.json +++ b/src/EventHub.IdentityServer/appsettings.json @@ -1,28 +1,8 @@ { - "App": { - "SelfUrl": "https://eh-st-account", - "CorsOrigins": "https://eh-st-www,https://eh-st-api,https://localhost:44307,https://localhost:44362", - "RedirectAllowedUrls": "https://eh-st-api,https://eh-st-www,http://eh-st-api,http://eh-st-www", - "WebAppUrl": "https://eh-st-www" - }, "ConnectionStrings": { "Default": "Host=localhost;Database=EventHub;Username=root;Password=root;Port=5432" }, "Redis": { - "Configuration": "eh-st-redis" - }, - "StringEncryption": { - "DefaultPassPhrase": "TxVIZFPxK33czbbv" - }, - "Settings": { - "Abp.Mailing.Smtp.Host": "127.0.0.1", - "Abp.Mailing.Smtp.Port": "25", - "Abp.Mailing.Smtp.UserName": "", - "Abp.Mailing.Smtp.Password": "", - "Abp.Mailing.Smtp.Domain": "", - "Abp.Mailing.Smtp.EnableSsl": "false", - "Abp.Mailing.Smtp.UseDefaultCredentials": "true", - "Abp.Mailing.DefaultFromAddress": "noreply@abp.io", - "Abp.Mailing.DefaultFromDisplayName": "ABP application" + "Configuration": "localhost" } } diff --git a/src/EventHub.Web/EventHubWebModule.cs b/src/EventHub.Web/EventHubWebModule.cs index 3e394ff..66d38ec 100644 --- a/src/EventHub.Web/EventHubWebModule.cs +++ b/src/EventHub.Web/EventHubWebModule.cs @@ -28,6 +28,7 @@ using Volo.Abp.Autofac; using Volo.Abp.AutoMapper; using Volo.Abp.Caching; using Volo.Abp.Caching.StackExchangeRedis; +using Volo.Abp.Http.Client; using Volo.Abp.Http.Client.IdentityModel.Web; using Volo.Abp.Modularity; using Volo.Abp.Swashbuckle; @@ -109,7 +110,12 @@ namespace EventHub.Web { Configure(options => { - options.Applications["MVC"].RootUrl = configuration["App:SelfUrl"]; + options.Applications["MVC"].RootUrl = configuration[EventHubUrlOptions.GetWwwConfigKey()]; + }); + + Configure(options => + { + options.RemoteServices.Default.BaseUrl = configuration[EventHubUrlOptions.GetApiConfigKey()].EnsureEndsWith('/'); }); } diff --git a/src/EventHub.Web/appsettings.Development.json b/src/EventHub.Web/appsettings.Development.json deleted file mode 100644 index 0db3279..0000000 --- a/src/EventHub.Web/appsettings.Development.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - -} diff --git a/src/EventHub.Web/appsettings.json b/src/EventHub.Web/appsettings.json index 830df47..2c4a520 100644 --- a/src/EventHub.Web/appsettings.json +++ b/src/EventHub.Web/appsettings.json @@ -1,22 +1,11 @@ { - "App": { - "SelfUrl": "https://eh-st-www" - }, - "RemoteServices": { - "Default": { - "BaseUrl": "http://eh-st-api/" - } - }, "Redis": { - "Configuration": "eh-st-redis" + "Configuration": "localhost" }, "AuthServer": { - "Authority": "http://eh-st-account", - "RequireHttpsMetadata": "false", + "Authority": "https://localhost:44313", + "RequireHttpsMetadata": "true", "ClientId": "EventHub_Web", "ClientSecret": "1q2w3e*" - }, - "StringEncryption": { - "DefaultPassPhrase": "7loHY5ax625vIGkV" } }