From 6f911611579cd7f96e15ebfa78afb4c6df3bbee3 Mon Sep 17 00:00:00 2001 From: "agile.zhou" Date: Tue, 12 Sep 2023 00:06:52 +0800 Subject: [PATCH 01/22] update release-xxx.yml --- .github/workflows/release-xxx.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release-xxx.yml b/.github/workflows/release-xxx.yml index ecc105aa..5f008f7e 100644 --- a/.github/workflows/release-xxx.yml +++ b/.github/workflows/release-xxx.yml @@ -50,10 +50,10 @@ jobs: name: agileconfig-ui path: src/AgileConfig.Server.Apisite/wwwroot/ui - name: build server release xxx - run: dotnet publish AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj -c Release + run: dotnet publish src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj -c Release - uses: vimtor/action-zip@v1 with: - files: AgileConfig.Server.Apisite/bin/Release/net6.0/publish/ + files: src/AgileConfig.Server.Apisite/bin/Release/net6.0/publish/ dest: agileconfig_server_deploy.zip - name: create release uses: ncipollo/release-action@v1 From d132ac4936b89222d8ff290eabd23e2cc0de47da Mon Sep 17 00:00:00 2001 From: lungchito <32699569+lungchito@users.noreply.github.com> Date: Tue, 12 Sep 2023 16:39:59 +0800 Subject: [PATCH 02/22] Update EnsureTables.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修正SQL Server区分大小写的情况下,提示异常Invalid object name 'dbo.SYSOBJECTS'. --- src/AgileConfig.Server.Data.Freesql/EnsureTables.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AgileConfig.Server.Data.Freesql/EnsureTables.cs b/src/AgileConfig.Server.Data.Freesql/EnsureTables.cs index 1c5e37d5..32323e26 100644 --- a/src/AgileConfig.Server.Data.Freesql/EnsureTables.cs +++ b/src/AgileConfig.Server.Data.Freesql/EnsureTables.cs @@ -16,7 +16,7 @@ public class EnsureTables " SELECT count(1) FROM information_schema.TABLES WHERE table_schema= @schema AND table_name ='agc_app'"; private const string SqlServer_ExistTableSql = - "SELECT COUNT(1) FROM dbo.SYSOBJECTS WHERE ID = object_id(N'[dbo].[agc_app]') and OBJECTPROPERTY(id, N'IsUserTable') = 1"; + "SELECT COUNT(1) FROM dbo.sysobjects WHERE ID = object_id(N'[dbo].[agc_app]') and OBJECTPROPERTY(id, N'IsUserTable') = 1"; private const string Oracle_ExistTableSql = "select count(1) from user_tables where table_name = 'agc_app'"; private const string PostgreSql_ExistTableSql = "select count(1) from pg_class where relname = 'agc_app'"; @@ -91,4 +91,4 @@ public static void Ensure(IFreeSql instance) } } } -} \ No newline at end of file +} From 8f6dc572647c444f25650b05825681db1b4b40e1 Mon Sep 17 00:00:00 2001 From: "agile.zhou" Date: Sat, 7 Oct 2023 01:05:27 +0800 Subject: [PATCH 03/22] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20appid=20=E4=B8=BA?= =?UTF-8?q?=E4=B8=AD=E6=96=87=E6=97=B6=E6=97=A0=E6=B3=95=E6=8B=89=E5=8F=96?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AgileConfig.Server.Apisite.csproj | 4 ++-- .../Websocket/MessageHandlers/MessageHandler.cs | 5 ++++- .../Websocket/WebsocketHandlerMiddleware.cs | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj b/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj index 19ae642a..83219f9e 100644 --- a/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj +++ b/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj @@ -3,11 +3,11 @@ net6.0 InProcess - 1.7.0 + 1.7.1 1.7.0-rc 1.6.20 Linux - 1.7.0 + 1.7.1 kklldog kklldog diff --git a/src/AgileConfig.Server.Apisite/Websocket/MessageHandlers/MessageHandler.cs b/src/AgileConfig.Server.Apisite/Websocket/MessageHandlers/MessageHandler.cs index effd63f8..d39eee7c 100644 --- a/src/AgileConfig.Server.Apisite/Websocket/MessageHandlers/MessageHandler.cs +++ b/src/AgileConfig.Server.Apisite/Websocket/MessageHandlers/MessageHandler.cs @@ -4,6 +4,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; +using System.Web; using Agile.Config.Protocol; using AgileConfig.Server.IService; using Microsoft.AspNetCore.Http; @@ -58,10 +59,12 @@ public async Task Handle(string message, HttpRequest request, WebsocketClient cl message = ""; } - if (message == "ping") + // "ping" is old version + if (message == "ping" || message == "c:ping") { //如果是ping,回复本地数据的md5版本 var appId = request.Headers["appid"]; + appId = HttpUtility.UrlDecode(appId); var env = request.Headers["env"]; env = await _configService.IfEnvEmptySetDefaultAsync(env); var md5 = await _configService.AppPublishedConfigsMd5CacheWithInheritanced(appId, env); diff --git a/src/AgileConfig.Server.Apisite/Websocket/WebsocketHandlerMiddleware.cs b/src/AgileConfig.Server.Apisite/Websocket/WebsocketHandlerMiddleware.cs index 58ace610..3e543008 100644 --- a/src/AgileConfig.Server.Apisite/Websocket/WebsocketHandlerMiddleware.cs +++ b/src/AgileConfig.Server.Apisite/Websocket/WebsocketHandlerMiddleware.cs @@ -56,6 +56,8 @@ public async Task Invoke( appId = appIdSecret.Item1; } + appId = HttpUtility.UrlDecode(appId); + var env = context.Request.Headers["env"]; if (!string.IsNullOrEmpty(env)) { From 3e96b0558183678214a23f262c683d9cfc73a7de Mon Sep 17 00:00:00 2001 From: "agile.zhou" Date: Sat, 7 Oct 2023 01:05:36 +0800 Subject: [PATCH 04/22] update version to 1.7.1 --- .../AgileConfig.Server.Apisite.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj b/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj index 83219f9e..fe11827c 100644 --- a/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj +++ b/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj @@ -4,7 +4,7 @@ net6.0 InProcess 1.7.1 - 1.7.0-rc + 1.7.1 1.6.20 Linux 1.7.1 From d8dbd4fa172d0e3bc4c31887c857e11ba19eea3e Mon Sep 17 00:00:00 2001 From: "agile.zhou" Date: Sat, 7 Oct 2023 01:14:15 +0800 Subject: [PATCH 05/22] update version to 1.7.2 --- .../AgileConfig.Server.Apisite.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj b/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj index fe11827c..d4c4f63d 100644 --- a/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj +++ b/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj @@ -3,8 +3,8 @@ net6.0 InProcess - 1.7.1 - 1.7.1 + 1.7.2 + 1.7.2 1.6.20 Linux 1.7.1 From 1370c1952838bd652608c732213fb2ddb07d28eb Mon Sep 17 00:00:00 2001 From: "agile.zhou" Date: Sat, 7 Oct 2023 01:14:20 +0800 Subject: [PATCH 06/22] update version to 1.7.2 --- .../AgileConfig.Server.Apisite.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj b/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj index d4c4f63d..621234b7 100644 --- a/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj +++ b/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj @@ -7,7 +7,7 @@ 1.7.2 1.6.20 Linux - 1.7.1 + 1.7.2 kklldog kklldog From b744adfc2ec54e574909b8dc6fdb635248519f54 Mon Sep 17 00:00:00 2001 From: "agile.zhou" Date: Sat, 7 Oct 2023 01:17:53 +0800 Subject: [PATCH 07/22] Update CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33fa01a3..c850f87b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change log ------------------------------ +[1.7.2] +* 修复 appid 为中文时无法获取配置的问题 + +[1.7.1] +* 修复在严格区分大小写的 SQLServer 上建表失败的问题 + [1.7.0] * 支持 SSO 登录 From 5c9a6bea6076039518cfeffc1590b0984050d734 Mon Sep 17 00:00:00 2001 From: "agile.zhou" Date: Tue, 31 Oct 2023 22:23:58 +0800 Subject: [PATCH 08/22] =?UTF-8?q?Fix=20bug=EF=BC=9Auser=20be=20deleted=20s?= =?UTF-8?q?till=20can=20login=20successfully=20by=20sso.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/AdminController.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/AgileConfig.Server.Apisite/Controllers/AdminController.cs b/src/AgileConfig.Server.Apisite/Controllers/AdminController.cs index 39b770fd..33aebc3d 100644 --- a/src/AgileConfig.Server.Apisite/Controllers/AdminController.cs +++ b/src/AgileConfig.Server.Apisite/Controllers/AdminController.cs @@ -23,7 +23,7 @@ public class AdminController : Controller private readonly IJwtService _jwtService; private readonly IOidcClient _oidcClient; public AdminController( - ISettingService settingService, + ISettingService settingService, IUserService userService, IPremissionService permissionService, IJwtService jwtService, @@ -54,7 +54,7 @@ public async Task Login4AntdPro([FromBody] LoginVM model) var result = await _userService.ValidateUserPassword(userName, model.password); if (result) { - var response = await LoginSuccessful(userName); + var response = await LoginSuccessful(userName); return Json(response); } @@ -134,6 +134,14 @@ public async Task OidcLoginByCode(string code) await _userService.AddAsync(newUser); await _userService.UpdateUserRolesAsync(newUser.Id, new List { Role.NormalUser }); } + else if (user.Status == UserStatus.Deleted) + { + return Json(new + { + status = "error", + message = "该用户已被删除" + }); + } var response = await LoginSuccessful(userInfo.UserName); return Json(response); From 47b7669b2117c65212ab41187c4448b77b80056c Mon Sep 17 00:00:00 2001 From: "agile.zhou" Date: Tue, 31 Oct 2023 22:27:08 +0800 Subject: [PATCH 09/22] Update version to 1.7.3 --- .../AgileConfig.Server.Apisite.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj b/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj index 621234b7..168808c3 100644 --- a/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj +++ b/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj @@ -3,8 +3,8 @@ net6.0 InProcess - 1.7.2 - 1.7.2 + 1.7.3 + 1.7.3 1.6.20 Linux 1.7.2 From a95f9507f6151fd4dfad88d64225f31d379e3bf2 Mon Sep 17 00:00:00 2001 From: "agile.zhou" Date: Tue, 31 Oct 2023 22:27:30 +0800 Subject: [PATCH 10/22] update version to 1.7.3 --- .../AgileConfig.Server.Apisite.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj b/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj index 168808c3..62742144 100644 --- a/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj +++ b/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj @@ -7,7 +7,7 @@ 1.7.3 1.6.20 Linux - 1.7.2 + 1.7.3 kklldog kklldog From 1f5534e690376c5102c0942299b1974e61fb38e4 Mon Sep 17 00:00:00 2001 From: "agile.zhou" Date: Fri, 24 Nov 2023 11:51:51 +0800 Subject: [PATCH 11/22] Upgrade to .NET8 --- Dockerfile | 4 +- .../Agile.Config.Protocol.csproj | 2 +- ...AgileConfig - Backup.Server.Apisite.csproj | 65 +++++++++++++++++++ .../AgileConfig.Server.Apisite.csproj | 28 ++++---- src/AgileConfig.Server.Apisite/Program.cs | 4 -- .../AgileConfig.Server.Common.csproj | 12 ++-- .../AgileConfig.Server.Data.Entity.csproj | 3 +- .../AgileConfig.Server.Data.Freesql.csproj | 2 +- .../AgileConfig.Server.IService.csproj | 21 +++--- .../AgileConfig.Server.OIDC.csproj | 4 +- .../AgileConfig.Server.Service.csproj | 2 +- .../RemoteServerNodeProxy.cs | 1 - .../ServerNodeService.cs | 1 - .../src/layouts/compos/LayoutFooter.tsx | 2 +- .../AgileConfig.Server.CommonTests.csproj | 2 +- .../AgileConfig.Server.ServiceTests.csproj | 2 +- test/ApiSiteTests/ApiSiteTests.csproj | 2 +- 17 files changed, 105 insertions(+), 52 deletions(-) create mode 100644 src/AgileConfig.Server.Apisite/AgileConfig - Backup.Server.Apisite.csproj diff --git a/Dockerfile b/Dockerfile index 7c716358..db13e02d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base RUN sed -i 's/DEFAULT@SECLEVEL=2/DEFAULT@SECLEVEL=1/g' /etc/ssl/openssl.cnf RUN sed -i 's/MinProtocol = TLSv1.2/MinProtocol = TLSv1/g' /etc/ssl/openssl.cnf RUN sed -i 's/DEFAULT@SECLEVEL=2/DEFAULT@SECLEVEL=1/g' /usr/lib/ssl/openssl.cnf @@ -6,7 +6,7 @@ RUN sed -i 's/MinProtocol = TLSv1.2/MinProtocol = TLSv1/g' /usr/lib/ssl/openssl. WORKDIR /app EXPOSE 5000 -FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /src COPY ["src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj", "AgileConfig.Server.Apisite/"] COPY ["src/AgileConfig.Server.Data.Entity/AgileConfig.Server.Data.Entity.csproj", "AgileConfig.Server.Data.Entity/"] diff --git a/src/Agile.Config.Protocol/Agile.Config.Protocol.csproj b/src/Agile.Config.Protocol/Agile.Config.Protocol.csproj index dbc15171..58990cd5 100644 --- a/src/Agile.Config.Protocol/Agile.Config.Protocol.csproj +++ b/src/Agile.Config.Protocol/Agile.Config.Protocol.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 diff --git a/src/AgileConfig.Server.Apisite/AgileConfig - Backup.Server.Apisite.csproj b/src/AgileConfig.Server.Apisite/AgileConfig - Backup.Server.Apisite.csproj new file mode 100644 index 00000000..8c424cc6 --- /dev/null +++ b/src/AgileConfig.Server.Apisite/AgileConfig - Backup.Server.Apisite.csproj @@ -0,0 +1,65 @@ + + + + net8.0 + InProcess + 1.8 + 1.8 + 1.6.20 + Linux + 1.7.3 + kklldog + kklldog + + + + bin\Debug\AgileConfig.Server.Apisite.xml + 1701;1702;1591;1573 + + + + bin\Release\AgileConfig.Server.Apisite.xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Always + + + PreserveNewest + + + + + + + + + + + + diff --git a/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj b/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj index 62742144..7a25e770 100644 --- a/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj +++ b/src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj @@ -1,13 +1,13 @@  - net6.0 + net8.0 InProcess - 1.7.3 - 1.7.3 - 1.6.20 + 1.8 + 1.8 + 1.8 Linux - 1.7.3 + 1.8 kklldog kklldog @@ -26,15 +26,15 @@ - - - - - - - - - + + + + + + + + + diff --git a/src/AgileConfig.Server.Apisite/Program.cs b/src/AgileConfig.Server.Apisite/Program.cs index 475a4b93..d8da189f 100644 --- a/src/AgileConfig.Server.Apisite/Program.cs +++ b/src/AgileConfig.Server.Apisite/Program.cs @@ -1,12 +1,8 @@ using System; -using System.IO; using AgileConfig.Server.Common; -using AgileConfig.Server.IService; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; using NLog.Web; namespace AgileConfig.Server.Apisite diff --git a/src/AgileConfig.Server.Common/AgileConfig.Server.Common.csproj b/src/AgileConfig.Server.Common/AgileConfig.Server.Common.csproj index fac82794..0ed6ad66 100644 --- a/src/AgileConfig.Server.Common/AgileConfig.Server.Common.csproj +++ b/src/AgileConfig.Server.Common/AgileConfig.Server.Common.csproj @@ -1,16 +1,14 @@  - net6.0 + net8.0 - - - - - - + + + + diff --git a/src/AgileConfig.Server.Data.Entity/AgileConfig.Server.Data.Entity.csproj b/src/AgileConfig.Server.Data.Entity/AgileConfig.Server.Data.Entity.csproj index 114a83d7..2f74890f 100644 --- a/src/AgileConfig.Server.Data.Entity/AgileConfig.Server.Data.Entity.csproj +++ b/src/AgileConfig.Server.Data.Entity/AgileConfig.Server.Data.Entity.csproj @@ -1,12 +1,11 @@  - net6.0 + net8.0 - diff --git a/src/AgileConfig.Server.Data.Freesql/AgileConfig.Server.Data.Freesql.csproj b/src/AgileConfig.Server.Data.Freesql/AgileConfig.Server.Data.Freesql.csproj index 29091334..4fb5adc6 100644 --- a/src/AgileConfig.Server.Data.Freesql/AgileConfig.Server.Data.Freesql.csproj +++ b/src/AgileConfig.Server.Data.Freesql/AgileConfig.Server.Data.Freesql.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 diff --git a/src/AgileConfig.Server.IService/AgileConfig.Server.IService.csproj b/src/AgileConfig.Server.IService/AgileConfig.Server.IService.csproj index 6485ad29..0f5bb84b 100644 --- a/src/AgileConfig.Server.IService/AgileConfig.Server.IService.csproj +++ b/src/AgileConfig.Server.IService/AgileConfig.Server.IService.csproj @@ -1,16 +1,13 @@ - + - - net6.0 - + + net8.0 + - - - - - - - - + + + + + diff --git a/src/AgileConfig.Server.OIDC/AgileConfig.Server.OIDC.csproj b/src/AgileConfig.Server.OIDC/AgileConfig.Server.OIDC.csproj index 50f69027..ff97aaf8 100644 --- a/src/AgileConfig.Server.OIDC/AgileConfig.Server.OIDC.csproj +++ b/src/AgileConfig.Server.OIDC/AgileConfig.Server.OIDC.csproj @@ -1,14 +1,14 @@ - net6.0 + net8.0 enable disable - + diff --git a/src/AgileConfig.Server.Service/AgileConfig.Server.Service.csproj b/src/AgileConfig.Server.Service/AgileConfig.Server.Service.csproj index cd7d6a1c..363061e7 100644 --- a/src/AgileConfig.Server.Service/AgileConfig.Server.Service.csproj +++ b/src/AgileConfig.Server.Service/AgileConfig.Server.Service.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 diff --git a/src/AgileConfig.Server.Service/RemoteServerNodeProxy.cs b/src/AgileConfig.Server.Service/RemoteServerNodeProxy.cs index c7e97bdd..ec2130ea 100644 --- a/src/AgileConfig.Server.Service/RemoteServerNodeProxy.cs +++ b/src/AgileConfig.Server.Service/RemoteServerNodeProxy.cs @@ -12,7 +12,6 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; namespace AgileConfig.Server.Service { diff --git a/src/AgileConfig.Server.Service/ServerNodeService.cs b/src/AgileConfig.Server.Service/ServerNodeService.cs index 6d434d97..2a87fd85 100644 --- a/src/AgileConfig.Server.Service/ServerNodeService.cs +++ b/src/AgileConfig.Server.Service/ServerNodeService.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Threading.Tasks; using AgileConfig.Server.Common; -using Microsoft.EntityFrameworkCore; using System; using AgileConfig.Server.Data.Freesql; diff --git a/src/AgileConfig.Server.UI/react-ui-antd/src/layouts/compos/LayoutFooter.tsx b/src/AgileConfig.Server.UI/react-ui-antd/src/layouts/compos/LayoutFooter.tsx index 2a86a6b5..225af795 100644 --- a/src/AgileConfig.Server.UI/react-ui-antd/src/layouts/compos/LayoutFooter.tsx +++ b/src/AgileConfig.Server.UI/react-ui-antd/src/layouts/compos/LayoutFooter.tsx @@ -14,7 +14,7 @@ const LayoutFooter : React.FC =()=>{ { getAppVer()}    -   Powered by .NET6.0 ant-design-pro4 +   Powered by .NET8 ant-design-pro4 ) } diff --git a/test/AgileConfig.Server.CommonTests/AgileConfig.Server.CommonTests.csproj b/test/AgileConfig.Server.CommonTests/AgileConfig.Server.CommonTests.csproj index 412f6a16..343ed964 100644 --- a/test/AgileConfig.Server.CommonTests/AgileConfig.Server.CommonTests.csproj +++ b/test/AgileConfig.Server.CommonTests/AgileConfig.Server.CommonTests.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 false diff --git a/test/AgileConfig.Server.ServiceTests/AgileConfig.Server.ServiceTests.csproj b/test/AgileConfig.Server.ServiceTests/AgileConfig.Server.ServiceTests.csproj index c19aa5e3..581ad7c0 100644 --- a/test/AgileConfig.Server.ServiceTests/AgileConfig.Server.ServiceTests.csproj +++ b/test/AgileConfig.Server.ServiceTests/AgileConfig.Server.ServiceTests.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 false diff --git a/test/ApiSiteTests/ApiSiteTests.csproj b/test/ApiSiteTests/ApiSiteTests.csproj index fbc4b726..94188534 100644 --- a/test/ApiSiteTests/ApiSiteTests.csproj +++ b/test/ApiSiteTests/ApiSiteTests.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 false From d86a25df0678666eb6d9091f2e27f825a8f3ab47 Mon Sep 17 00:00:00 2001 From: "agile.zhou" Date: Fri, 24 Nov 2023 12:02:23 +0800 Subject: [PATCH 12/22] Update master-ci.yml --- .github/workflows/master-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/master-ci.yml b/.github/workflows/master-ci.yml index 0e4e99ca..f74050b4 100644 --- a/.github/workflows/master-ci.yml +++ b/.github/workflows/master-ci.yml @@ -41,7 +41,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 6.0.100 + dotnet-version: 8.0 - name: Install dependencies run: dotnet restore - name: Build From be6131e5aafac3428ba1f94c69d8bee24374848c Mon Sep 17 00:00:00 2001 From: "agile.zhou" Date: Fri, 24 Nov 2023 12:07:05 +0800 Subject: [PATCH 13/22] Update all the CI to .NET8 --- .github/workflows/arm32.yml | 2 +- .github/workflows/arm64.yml | 2 +- .github/workflows/mysqlconnector.yml | 2 +- .github/workflows/preview-dotnet.yml | 2 +- .github/workflows/publish.yml | 2 +- .github/workflows/release-xxx.yml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/arm32.yml b/.github/workflows/arm32.yml index 72113ce8..cbaa963b 100644 --- a/.github/workflows/arm32.yml +++ b/.github/workflows/arm32.yml @@ -41,7 +41,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 6.0.100 + dotnet-version: 8.0 - name: Install dependencies run: dotnet restore - name: Build diff --git a/.github/workflows/arm64.yml b/.github/workflows/arm64.yml index 0886a928..dc98f9a0 100644 --- a/.github/workflows/arm64.yml +++ b/.github/workflows/arm64.yml @@ -41,7 +41,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 6.0.100 + dotnet-version: 8.0 - name: Install dependencies run: dotnet restore - name: Build diff --git a/.github/workflows/mysqlconnector.yml b/.github/workflows/mysqlconnector.yml index ffe768fd..e75f2a63 100644 --- a/.github/workflows/mysqlconnector.yml +++ b/.github/workflows/mysqlconnector.yml @@ -41,7 +41,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 6.0.100 + dotnet-version: 8.0 - name: Install dependencies run: dotnet restore - name: Build diff --git a/.github/workflows/preview-dotnet.yml b/.github/workflows/preview-dotnet.yml index 92fb502c..3f9d9302 100644 --- a/.github/workflows/preview-dotnet.yml +++ b/.github/workflows/preview-dotnet.yml @@ -23,7 +23,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 6.0.100 + dotnet-version: 8.0 - name: Install dependencies run: dotnet restore - name: Build diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 9c970b2f..b1a4f65f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -39,7 +39,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 6.0.100 + dotnet-version: 8.0 - name: Install dependencies run: dotnet restore - name: Build diff --git a/.github/workflows/release-xxx.yml b/.github/workflows/release-xxx.yml index 5f008f7e..25752912 100644 --- a/.github/workflows/release-xxx.yml +++ b/.github/workflows/release-xxx.yml @@ -40,7 +40,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 6.0.100 + dotnet-version: 8.0 - name: Install dependencies run: dotnet restore - name: Build From e186536b83b59ad670a13ff08c6053e0ed644311 Mon Sep 17 00:00:00 2001 From: "agile.zhou" Date: Fri, 24 Nov 2023 13:39:12 +0800 Subject: [PATCH 14/22] Update ci yml --- .github/workflows/master-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/master-ci.yml b/.github/workflows/master-ci.yml index f74050b4..da070939 100644 --- a/.github/workflows/master-ci.yml +++ b/.github/workflows/master-ci.yml @@ -8,6 +8,7 @@ on: - '**/*.yml' pull_request: branches: [ master ] + workflow_dispatch: jobs: build-reactapp: From 09911e25484622ee53673a0774d2ad8e541470bf Mon Sep 17 00:00:00 2001 From: "agile.zhou" Date: Fri, 24 Nov 2023 13:43:53 +0800 Subject: [PATCH 15/22] Update ci yml --- .github/workflows/master-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/master-ci.yml b/.github/workflows/master-ci.yml index da070939..0ad47092 100644 --- a/.github/workflows/master-ci.yml +++ b/.github/workflows/master-ci.yml @@ -42,7 +42,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 8.0 + dotnet-version: 8.0.* - name: Install dependencies run: dotnet restore - name: Build From aec2d367a901ac9ecf9bfe2d1f28fe0cfcae7def Mon Sep 17 00:00:00 2001 From: "agile.zhou" Date: Fri, 24 Nov 2023 15:05:15 +0800 Subject: [PATCH 16/22] Update docker file --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index db13e02d..d92d34e0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,6 +26,7 @@ FROM build AS publish RUN dotnet publish "AgileConfig.Server.Apisite.csproj" -c Release -o /app/publish FROM base AS final +ENV COMPlus_EnableDiagnostics=0 WORKDIR /app COPY --from=publish /app/publish . From 8560bcc7334fea9294fb57f18104383f30a3e69d Mon Sep 17 00:00:00 2001 From: "agile.zhou" Date: Fri, 24 Nov 2023 15:49:34 +0800 Subject: [PATCH 17/22] Update docker-compose yml --- Dockerfile | 1 - docker-compose.yml | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d92d34e0..db13e02d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,7 +26,6 @@ FROM build AS publish RUN dotnet publish "AgileConfig.Server.Apisite.csproj" -c Release -o /app/publish FROM base AS final -ENV COMPlus_EnableDiagnostics=0 WORKDIR /app COPY --from=publish /app/publish . diff --git a/docker-compose.yml b/docker-compose.yml index 0748e31f..ee5ed0d3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,8 @@ services: - "15000:5000" networks: - net0 + security_opt: + - seccomp=unconfined volumes: - /etc/localtime:/etc/localtime environment: @@ -20,6 +22,8 @@ services: - "15001:5000" networks: - net0 + security_opt: + - seccomp=unconfined volumes: - /etc/localtime:/etc/localtime environment: @@ -35,6 +39,8 @@ services: - "15002:5000" networks: - net0 + security_opt: + - seccomp=unconfined volumes: - /etc/localtime:/etc/localtime environment: From a383b583266ddeda2811dc44a89513d369951937 Mon Sep 17 00:00:00 2001 From: "agile.zhou" Date: Sat, 25 Nov 2023 15:58:57 +0800 Subject: [PATCH 18/22] Update CI yml --- .github/workflows/arm32.yml | 2 +- .github/workflows/arm64.yml | 2 +- .github/workflows/mysqlconnector.yml | 2 +- .github/workflows/preview-dotnet.yml | 2 +- .github/workflows/publish.yml | 2 +- .github/workflows/release-xxx.yml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/arm32.yml b/.github/workflows/arm32.yml index cbaa963b..87406802 100644 --- a/.github/workflows/arm32.yml +++ b/.github/workflows/arm32.yml @@ -41,7 +41,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 8.0 + dotnet-version: 8.0.* - name: Install dependencies run: dotnet restore - name: Build diff --git a/.github/workflows/arm64.yml b/.github/workflows/arm64.yml index dc98f9a0..db7826d0 100644 --- a/.github/workflows/arm64.yml +++ b/.github/workflows/arm64.yml @@ -41,7 +41,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 8.0 + dotnet-version: 8.0.* - name: Install dependencies run: dotnet restore - name: Build diff --git a/.github/workflows/mysqlconnector.yml b/.github/workflows/mysqlconnector.yml index e75f2a63..330c3b0d 100644 --- a/.github/workflows/mysqlconnector.yml +++ b/.github/workflows/mysqlconnector.yml @@ -41,7 +41,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 8.0 + dotnet-version: 8.0.* - name: Install dependencies run: dotnet restore - name: Build diff --git a/.github/workflows/preview-dotnet.yml b/.github/workflows/preview-dotnet.yml index 3f9d9302..2c0df1fe 100644 --- a/.github/workflows/preview-dotnet.yml +++ b/.github/workflows/preview-dotnet.yml @@ -23,7 +23,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 8.0 + dotnet-version: 8.0.* - name: Install dependencies run: dotnet restore - name: Build diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b1a4f65f..e7914e7d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -39,7 +39,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 8.0 + dotnet-version: 8.0.* - name: Install dependencies run: dotnet restore - name: Build diff --git a/.github/workflows/release-xxx.yml b/.github/workflows/release-xxx.yml index 25752912..ba72af98 100644 --- a/.github/workflows/release-xxx.yml +++ b/.github/workflows/release-xxx.yml @@ -40,7 +40,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 8.0 + dotnet-version: 8.0.* - name: Install dependencies run: dotnet restore - name: Build From 246d589a33b4eeab4051ea07505c8088b89d125a Mon Sep 17 00:00:00 2001 From: "agile.zhou" Date: Sat, 25 Nov 2023 16:23:05 +0800 Subject: [PATCH 19/22] Update CI yml --- .github/workflows/publish.yml | 3 ++- .github/workflows/release-xxx.yml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e7914e7d..9efa6c0b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -6,7 +6,8 @@ on: paths-ignore: - '**/*.md' - '**/*.yml' - + workflow_dispatch: + jobs: build-reactapp: runs-on: ubuntu-latest diff --git a/.github/workflows/release-xxx.yml b/.github/workflows/release-xxx.yml index ba72af98..6e4b06ba 100644 --- a/.github/workflows/release-xxx.yml +++ b/.github/workflows/release-xxx.yml @@ -7,7 +7,7 @@ on: - '**/*.yml' tags: - 'v-*' - + workflow_dispatch: jobs: build-reactapp: runs-on: ubuntu-latest From 3c5b7f263390c2e1b8ae98b14adc16caabe7235d Mon Sep 17 00:00:00 2001 From: "agile.zhou" Date: Sat, 25 Nov 2023 16:58:11 +0800 Subject: [PATCH 20/22] Update release-xxx.yml --- .github/workflows/release-xxx.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-xxx.yml b/.github/workflows/release-xxx.yml index 6e4b06ba..8645e4fb 100644 --- a/.github/workflows/release-xxx.yml +++ b/.github/workflows/release-xxx.yml @@ -53,7 +53,7 @@ jobs: run: dotnet publish src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.csproj -c Release - uses: vimtor/action-zip@v1 with: - files: src/AgileConfig.Server.Apisite/bin/Release/net6.0/publish/ + files: src/AgileConfig.Server.Apisite/bin/Release/net8.0/publish/ dest: agileconfig_server_deploy.zip - name: create release uses: ncipollo/release-action@v1 From 435687d12cff0572dec4823940f30a0009a28342 Mon Sep 17 00:00:00 2001 From: "agile.zhou" Date: Sat, 25 Nov 2023 17:01:31 +0800 Subject: [PATCH 21/22] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c850f87b..a44bbb64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Change log ------------------------------ +[1.8.0] +* 升级到 .NET8 + [1.7.2] * 修复 appid 为中文时无法获取配置的问题 From fe8629182afdbc6ae804e3d50534ad96786f1ad5 Mon Sep 17 00:00:00 2001 From: "agile.zhou" Date: Sun, 26 Nov 2023 20:34:41 +0800 Subject: [PATCH 22/22] Use build-in httpclient instead of AgileHttp; --- src/AgileConfig.Server.Apisite/Startup.cs | 22 ++- .../StartupExtension.cs | 32 ++++ src/AgileConfig.Server.Common/Global.cs | 2 + .../RestClient/DefaultRestClient.cs | 82 ++++++++++ .../RestClient/IRestClient.cs | 18 +++ .../RestClient/ServiceCollectionEx.cs | 12 ++ .../IRegisterCenterService.cs | 4 - src/AgileConfig.Server.OIDC/OidcClient.cs | 10 +- .../AgileConfig.Server.Service.csproj | 4 - .../EventRegisterService/EventRegister.cs | 7 +- .../ServiceInfoStatusUpdateRegister.cs | 24 +-- .../RemoteServerNodeProxy.cs | 149 +++++++----------- .../ServiceCollectionExt.cs | 13 +- .../ServiceHealthCheckService.cs | 23 ++- 14 files changed, 261 insertions(+), 141 deletions(-) create mode 100644 src/AgileConfig.Server.Apisite/StartupExtension.cs create mode 100644 src/AgileConfig.Server.Common/RestClient/DefaultRestClient.cs create mode 100644 src/AgileConfig.Server.Common/RestClient/IRestClient.cs create mode 100644 src/AgileConfig.Server.Common/RestClient/ServiceCollectionEx.cs diff --git a/src/AgileConfig.Server.Apisite/Startup.cs b/src/AgileConfig.Server.Apisite/Startup.cs index faee737d..0afaf10a 100644 --- a/src/AgileConfig.Server.Apisite/Startup.cs +++ b/src/AgileConfig.Server.Apisite/Startup.cs @@ -1,10 +1,12 @@ using System; using System.IO; using System.Net; +using System.Net.Http; using System.Text; using AgileConfig.Server.Apisite.UIExtension; using AgileConfig.Server.Apisite.Websocket; using AgileConfig.Server.Common; +using AgileConfig.Server.Common.RestClient; using AgileConfig.Server.Data.Freesql; using AgileConfig.Server.OIDC; using AgileConfig.Server.Service; @@ -27,13 +29,23 @@ public Startup(IConfiguration configuration, ILoggerFactory loggerFactory) Configuration = configuration; Global.LoggerFactory = loggerFactory; - TrustSSL(configuration); + SetTrustSSL(configuration); } - private void TrustSSL(IConfiguration configuration) + private static bool IsTrustSSL(IConfiguration configuration) { var alwaysTrustSsl = configuration["alwaysTrustSsl"]; if (!string.IsNullOrEmpty(alwaysTrustSsl) && alwaysTrustSsl.ToLower() == "true") + { + return true; + } + + return false; + } + + private static void SetTrustSSL(IConfiguration configuration) + { + if (IsTrustSSL(configuration)) { ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; } @@ -47,6 +59,9 @@ public IConfiguration Configuration // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { + services.AddDefaultHttpClient(IsTrustSSL(Configuration)); + services.AddRestClient(); + var jwtService = new JwtService(); services.AddMemoryCache(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) @@ -71,6 +86,7 @@ public void ConfigureServices(IServiceCollection services) services.AddBusinessServices(); services.AddHostedService(); services.AddAntiforgery(o => o.SuppressXFrameOptionsHeader = true); + services.AddOIDC(); } @@ -138,5 +154,7 @@ private void AddSwaggerMiddleWare(IApplicationBuilder app) c.SwaggerEndpoint("v1/swagger.json", "My API V1"); }); } + + } } diff --git a/src/AgileConfig.Server.Apisite/StartupExtension.cs b/src/AgileConfig.Server.Apisite/StartupExtension.cs new file mode 100644 index 00000000..80d2ab90 --- /dev/null +++ b/src/AgileConfig.Server.Apisite/StartupExtension.cs @@ -0,0 +1,32 @@ +using AgileConfig.Server.Common; +using Microsoft.Extensions.DependencyInjection; +using System.Net.Http; + +namespace AgileConfig.Server.Apisite +{ + public static class StartupExtension + { + public static void AddDefaultHttpClient(this IServiceCollection services, bool isTrustSSL) + { + services.AddHttpClient(Global.DefaultHttpClientName) + .ConfigurePrimaryHttpMessageHandler(() => { + return NewMessageHandler(isTrustSSL); + }) + ; + } + + static HttpMessageHandler NewMessageHandler(bool alwaysTrustSsl) + { + var handler = new HttpClientHandler(); + if (alwaysTrustSsl) + { + handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => + { + return true; + }; + } + + return handler; + } + } +} diff --git a/src/AgileConfig.Server.Common/Global.cs b/src/AgileConfig.Server.Common/Global.cs index 275e862d..01ace172 100644 --- a/src/AgileConfig.Server.Common/Global.cs +++ b/src/AgileConfig.Server.Common/Global.cs @@ -24,5 +24,7 @@ public static ILoggerFactory LoggerFactory _loggerFactory = value; } } + + public const string DefaultHttpClientName = "Default"; } } diff --git a/src/AgileConfig.Server.Common/RestClient/DefaultRestClient.cs b/src/AgileConfig.Server.Common/RestClient/DefaultRestClient.cs new file mode 100644 index 00000000..e9830e42 --- /dev/null +++ b/src/AgileConfig.Server.Common/RestClient/DefaultRestClient.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Threading.Tasks; + +namespace AgileConfig.Server.Common.RestClient +{ + public class DefaultRestClient : IRestClient + { + private readonly IHttpClientFactory _httpClientFactory; + + public DefaultRestClient( + IHttpClientFactory httpClientFactory + ) + { + this._httpClientFactory = httpClientFactory; + } + + private HttpClient GetDefaultClient() + { + return _httpClientFactory.CreateClient(Global.DefaultHttpClientName); + } + + public async Task GetAsync(string url, Dictionary headers = null) + { + using var resp = await GetAsync(url, headers); + resp.EnsureSuccessStatusCode(); + + var json = await resp.Content.ReadAsStringAsync(); + return Newtonsoft.Json.JsonConvert.DeserializeObject(json); + } + + public async Task PostAsync(string url, object data, Dictionary headers = null) + { + using var resp = await PostAsync(url, data, headers); + + resp.EnsureSuccessStatusCode(); + + var json = await resp.Content.ReadAsStringAsync(); + return Newtonsoft.Json.JsonConvert.DeserializeObject(json); + } + + public async Task PostAsync(string url, object data, Dictionary headers = null) + { + var httpclient = GetDefaultClient(); + if (headers != null) + { + foreach (var header in headers) + { + httpclient.DefaultRequestHeaders.Add(header.Key, header.Value); + } + } + + var jsondata = ""; + if (data != null) + { + jsondata = Newtonsoft.Json.JsonConvert.SerializeObject(data); + } + var stringContent = new StringContent(jsondata, + new System.Net.Http.Headers.MediaTypeHeaderValue("application/json")); + + var resp = await httpclient.PostAsync(url, stringContent); + + return resp; + } + + public async Task GetAsync(string url, Dictionary headers = null) + { + var httpclient = GetDefaultClient(); + if (headers != null) + { + foreach (var header in headers) + { + httpclient.DefaultRequestHeaders.Add(header.Key, header.Value); + } + } + var resp = await httpclient.GetAsync(url); + + return resp; + } + } +} diff --git a/src/AgileConfig.Server.Common/RestClient/IRestClient.cs b/src/AgileConfig.Server.Common/RestClient/IRestClient.cs new file mode 100644 index 00000000..d379c07e --- /dev/null +++ b/src/AgileConfig.Server.Common/RestClient/IRestClient.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; +using System.Net.Http; +using System.Threading.Tasks; + +namespace AgileConfig.Server.Common.RestClient +{ + public interface IRestClient + { + Task GetAsync(string url, Dictionary headers = null); + + Task GetAsync(string url, Dictionary headers = null); + + Task PostAsync(string url, object data, Dictionary headers = null); + + Task PostAsync(string url, object data, Dictionary headers = null); + + } +} diff --git a/src/AgileConfig.Server.Common/RestClient/ServiceCollectionEx.cs b/src/AgileConfig.Server.Common/RestClient/ServiceCollectionEx.cs new file mode 100644 index 00000000..e9d0bcd7 --- /dev/null +++ b/src/AgileConfig.Server.Common/RestClient/ServiceCollectionEx.cs @@ -0,0 +1,12 @@ +using Microsoft.Extensions.DependencyInjection; + +namespace AgileConfig.Server.Common.RestClient +{ + public static class ServiceCollectionEx + { + public static void AddRestClient(this IServiceCollection sc) + { + sc.AddScoped(); + } + } +} diff --git a/src/AgileConfig.Server.IService/IRegisterCenterService.cs b/src/AgileConfig.Server.IService/IRegisterCenterService.cs index 74f12a3b..02c07a99 100644 --- a/src/AgileConfig.Server.IService/IRegisterCenterService.cs +++ b/src/AgileConfig.Server.IService/IRegisterCenterService.cs @@ -1,8 +1,4 @@ using AgileConfig.Server.Data.Entity; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Threading.Tasks; namespace AgileConfig.Server.IService diff --git a/src/AgileConfig.Server.OIDC/OidcClient.cs b/src/AgileConfig.Server.OIDC/OidcClient.cs index b13fcab8..73e6d0b9 100644 --- a/src/AgileConfig.Server.OIDC/OidcClient.cs +++ b/src/AgileConfig.Server.OIDC/OidcClient.cs @@ -1,4 +1,5 @@ -using AgileConfig.Server.OIDC.SettingProvider; +using AgileConfig.Server.Common; +using AgileConfig.Server.OIDC.SettingProvider; using AgileConfig.Server.OIDC.TokenEndpointAuthMethods; using Newtonsoft.Json; using System.IdentityModel.Tokens.Jwt; @@ -10,11 +11,13 @@ public class OidcClient : IOidcClient { private readonly IOidcSettingProvider _oidcSettingProvider; private readonly OidcSetting _oidcSetting; + private readonly IHttpClientFactory _httpClientFactory; public OidcSetting OidcSetting => _oidcSetting; - public OidcClient(IOidcSettingProvider oidcSettingProvider) + public OidcClient(IOidcSettingProvider oidcSettingProvider, IHttpClientFactory httpClientFactory) { + _httpClientFactory = httpClientFactory; _oidcSettingProvider = oidcSettingProvider; _oidcSetting = _oidcSettingProvider.GetSetting(); } @@ -35,7 +38,8 @@ public string GetAuthorizeUrl() var authMethod = TokenEndpointAuthMethodFactory.Create(_oidcSetting.TokenEndpointAuthMethod); var httpContent = authMethod.GetAuthHttpContent(code, _oidcSetting); - using var httpclient = new HttpClient(); + + var httpclient = _httpClientFactory.CreateClient(Global.DefaultHttpClientName); if (!string.IsNullOrEmpty(httpContent.BasicAuthorizationString)) { httpclient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", httpContent.BasicAuthorizationString); diff --git a/src/AgileConfig.Server.Service/AgileConfig.Server.Service.csproj b/src/AgileConfig.Server.Service/AgileConfig.Server.Service.csproj index 363061e7..ea67d43a 100644 --- a/src/AgileConfig.Server.Service/AgileConfig.Server.Service.csproj +++ b/src/AgileConfig.Server.Service/AgileConfig.Server.Service.csproj @@ -4,10 +4,6 @@ net8.0 - - - - diff --git a/src/AgileConfig.Server.Service/EventRegisterService/EventRegister.cs b/src/AgileConfig.Server.Service/EventRegisterService/EventRegister.cs index 9a1f3d1b..a99ed8be 100644 --- a/src/AgileConfig.Server.Service/EventRegisterService/EventRegister.cs +++ b/src/AgileConfig.Server.Service/EventRegisterService/EventRegister.cs @@ -1,4 +1,5 @@ -using AgileConfig.Server.IService; +using AgileConfig.Server.Common.RestClient; +using AgileConfig.Server.IService; using Microsoft.Extensions.Logging; namespace AgileConfig.Server.Service.EventRegisterService; @@ -10,12 +11,12 @@ public class EventRegister : IEventRegister private readonly SysLogRegister _sysLogRegister; private readonly ServiceInfoStatusUpdateRegister _serviceInfoStatusUpdateRegister; - public EventRegister(IRemoteServerNodeProxy remoteServerNodeProxy, ILoggerFactory loggerFactory) + public EventRegister(IRemoteServerNodeProxy remoteServerNodeProxy, ILoggerFactory loggerFactory, IRestClient restClient) { _remoteServerNodeProxy = remoteServerNodeProxy; _configStatusUpdateRegister = new ConfigStatusUpdateRegister(_remoteServerNodeProxy); _sysLogRegister = new SysLogRegister(); - _serviceInfoStatusUpdateRegister = new ServiceInfoStatusUpdateRegister(_remoteServerNodeProxy, loggerFactory); + _serviceInfoStatusUpdateRegister = new ServiceInfoStatusUpdateRegister(_remoteServerNodeProxy, loggerFactory, restClient); } public void Register() diff --git a/src/AgileConfig.Server.Service/EventRegisterService/ServiceInfoStatusUpdateRegister.cs b/src/AgileConfig.Server.Service/EventRegisterService/ServiceInfoStatusUpdateRegister.cs index 24b32346..fc001bcf 100644 --- a/src/AgileConfig.Server.Service/EventRegisterService/ServiceInfoStatusUpdateRegister.cs +++ b/src/AgileConfig.Server.Service/EventRegisterService/ServiceInfoStatusUpdateRegister.cs @@ -1,13 +1,14 @@ using System; using System.Linq; using System.Net; +using System.Net.Http; using System.Threading.Tasks; using Agile.Config.Protocol; using AgileConfig.Server.Common; +using AgileConfig.Server.Common.RestClient; using AgileConfig.Server.Data.Entity; using AgileConfig.Server.Data.Freesql; using AgileConfig.Server.IService; -using AgileHttp; using Microsoft.Extensions.Logging; namespace AgileConfig.Server.Service.EventRegisterService; @@ -15,11 +16,17 @@ namespace AgileConfig.Server.Service.EventRegisterService; internal class ServiceInfoStatusUpdateRegister : IEventRegister { private readonly IRemoteServerNodeProxy _remoteServerNodeProxy; + private readonly IRestClient _restClient; private ILogger _logger; - public ServiceInfoStatusUpdateRegister(IRemoteServerNodeProxy remoteServerNodeProxy, ILoggerFactory loggerFactory) + public ServiceInfoStatusUpdateRegister( + IRemoteServerNodeProxy remoteServerNodeProxy, + ILoggerFactory loggerFactory, + IRestClient restClient + ) { _remoteServerNodeProxy = remoteServerNodeProxy; + _restClient = restClient; _logger = loggerFactory.CreateLogger(); } @@ -129,14 +136,11 @@ private async Task SendServiceOfflineMessageAsync(ServiceInfo service) { await FunctionUtil.TRYAsync(async () => { - var resp = await service.AlarmUrl.AsHttp("POST", msg).Config(new RequestOptions() - { - ContentType = "application/json" - }).SendAsync(); - if (resp.Exception != null) - { - throw resp.Exception; - } + var content = new StringContent(""); + content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); + using var resp = await _restClient.PostAsync(service.AlarmUrl, null); + + resp.EnsureSuccessStatusCode(); return resp.StatusCode == HttpStatusCode.OK; }, 5); diff --git a/src/AgileConfig.Server.Service/RemoteServerNodeProxy.cs b/src/AgileConfig.Server.Service/RemoteServerNodeProxy.cs index ec2130ea..1edb261c 100644 --- a/src/AgileConfig.Server.Service/RemoteServerNodeProxy.cs +++ b/src/AgileConfig.Server.Service/RemoteServerNodeProxy.cs @@ -1,38 +1,20 @@ using Agile.Config.Protocol; using AgileConfig.Server.Common; +using AgileConfig.Server.Common.RestClient; using AgileConfig.Server.Data.Entity; using AgileConfig.Server.Data.Freesql; using AgileConfig.Server.IService; -using AgileHttp; -using AgileHttp.serialize; using Microsoft.Extensions.Logging; -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Security.Policy; using System.Threading.Tasks; namespace AgileConfig.Server.Service { public class RemoteServerNodeProxy : IRemoteServerNodeProxy { - internal class SerializeProvider : ISerializeProvider - { - public T Deserialize(string content) - { - return JsonConvert.DeserializeObject(content, new JsonSerializerSettings - { - ContractResolver = new CamelCasePropertyNamesContractResolver() - }); - } - - public string Serialize(object obj) - { - return JsonConvert.SerializeObject(obj); - } - } - private IServerNodeService GetServerNodeService() { return new ServerNodeService(new FreeSqlContext(FreeSQL.Instance)); @@ -47,33 +29,25 @@ private ISysLogService GetSysLogService() private static ConcurrentDictionary _serverNodeClientReports = new ConcurrentDictionary(); + private readonly IRestClient _restClient; - public RemoteServerNodeProxy(ILoggerFactory loggerFactory) + public RemoteServerNodeProxy(ILoggerFactory loggerFactory, IRestClient restClient) { _logger = loggerFactory.CreateLogger(); + _restClient = restClient; } public async Task AllClientsDoActionAsync(string address, WebsocketAction action) { var result = await FunctionUtil.TRYAsync(async () => { - using (var resp = await (address + "/RemoteOP/AllClientsDoAction") - .AsHttp("POST", action) - .Config(new RequestOptions { ContentType = "application/json" }) - .SendAsync()) + dynamic result = await _restClient.PostAsync(address + "/RemoteOP/AllClientsDoAction", action); + if ((bool)result.success) { - if (resp.StatusCode == System.Net.HttpStatusCode.OK) - { - var result = resp.Deserialize(); - - if ((bool)result.success) - { - return true; - } - } - - return false; + return true; } + + return false; }, 5); using (var service = GetSysLogService()) @@ -102,23 +76,14 @@ public async Task AppClientsDoActionAsync(string address, string appId, st { var result = await FunctionUtil.TRYAsync(async () => { - using (var resp = await (address + "/RemoteOP/AppClientsDoAction".AppendQueryString("appId", appId).AppendQueryString("env", env)) - .AsHttp("POST", action) - .Config(new RequestOptions { ContentType = "application/json" }) - .SendAsync()) + var url = $"{address}/RemoteOP/AppClientsDoAction?appId={Uri.EscapeDataString(appId)}&env={env}"; + dynamic result = await _restClient.PostAsync(url, action); + if ((bool)result.success) { - if (resp.StatusCode == System.Net.HttpStatusCode.OK) - { - var result = resp.Deserialize(); - - if ((bool)result.success) - { - return true; - } - } - - return false; + return true; } + + return false; }, 5); using (var service = GetSysLogService()) @@ -148,36 +113,28 @@ public async Task OneClientDoActionAsync(string address, string clientId, { var result = await FunctionUtil.TRYAsync(async () => { - using (var resp = await (address + "/RemoteOP/OneClientDoAction?clientId=" + clientId) - .AsHttp("POST", action) - .Config(new RequestOptions { ContentType = "application/json" }) - .SendAsync()) + var url = $"{address}/RemoteOP/OneClientDoAction?clientId={clientId}"; + dynamic result = await _restClient.PostAsync(url, action); + + if ((bool)result.success) { - if (resp.StatusCode == System.Net.HttpStatusCode.OK) + if (action.Action == ActionConst.Offline) { - var result = resp.Deserialize(); - - if ((bool)result.success) + if (_serverNodeClientReports.ContainsKey(address)) { - if (action.Action == ActionConst.Offline) + if (_serverNodeClientReports[address].Infos != null) { - if (_serverNodeClientReports.ContainsKey(address)) - { - if (_serverNodeClientReports[address].Infos != null) - { - var report = _serverNodeClientReports[address]; - report.Infos.RemoveAll(c => c.Id == clientId); - report.ClientCount = report.Infos.Count; - } - } + var report = _serverNodeClientReports[address]; + report.Infos.RemoveAll(c => c.Id == clientId); + report.ClientCount = report.Infos.Count; } - - return true; } } - return false; + return true; } + + return false; }, 5); using (var service = GetSysLogService()) @@ -215,25 +172,20 @@ public async Task GetClientsReportAsync(string address) try { - using (var resp = await (address + "/report/Clients").AsHttp() - .Config(new RequestOptions(new SerializeProvider())).SendAsync()) - { - if (resp.StatusCode == System.Net.HttpStatusCode.OK) - { - var clients = resp.Deserialize(); - if (clients != null) - { - clients.Infos?.ForEach(i => { i.Address = address; }); - return clients; - } - } + var url = address + "/report/Clients"; - return new ClientInfos() - { - ClientCount = 0, - Infos = new List() - }; + var clients = await _restClient.GetAsync(url); + if (clients != null) + { + clients.Infos?.ForEach(i => { i.Address = address; }); + return clients; } + + return new ClientInfos() + { + ClientCount = 0, + Infos = new List() + }; } catch (Exception ex) { @@ -253,8 +205,11 @@ public async Task TestEchoAsync(string address) var node = await service.GetAsync(address); try { - using var resp = await (node.Address + "/home/echo").AsHttp().SendAsync(); - if (resp.StatusCode == System.Net.HttpStatusCode.OK && (await resp.GetResponseContentAsync()) == "ok") + var url = node.Address + "/home/echo"; + + using var resp = await _restClient.GetAsync(url); + + if (resp.StatusCode == System.Net.HttpStatusCode.OK && (await resp.Content.ReadAsStringAsync()) == "ok") { node.LastEchoTime = DateTime.Now; node.Status = NodeStatus.Online; @@ -310,8 +265,9 @@ public Task TestEchoAsync() public async Task ClearConfigServiceCache(string address) { try - { - await (address + "/RemoteOP/ClearConfigServiceCache").AsHttp("POST").SendAsync(); + { + var url = (address + "/RemoteOP/ClearConfigServiceCache"); + using var resp = await _restClient.PostAsync(url, null); } catch (Exception e) { @@ -322,8 +278,11 @@ public async Task ClearConfigServiceCache(string address) public async Task ClearServiceInfoCache(string address) { try - { - await (address + "/RemoteOP/ClearServiceInfoCache").AsHttp("POST").SendAsync(); + { + var url = (address + "/RemoteOP/ClearServiceInfoCache"); + + await _restClient.PostAsync(url, null); + } catch (Exception e) { diff --git a/src/AgileConfig.Server.Service/ServiceCollectionExt.cs b/src/AgileConfig.Server.Service/ServiceCollectionExt.cs index cd3cf887..66490646 100644 --- a/src/AgileConfig.Server.Service/ServiceCollectionExt.cs +++ b/src/AgileConfig.Server.Service/ServiceCollectionExt.cs @@ -1,4 +1,5 @@ -using AgileConfig.Server.IService; +using AgileConfig.Server.Common.RestClient; +using AgileConfig.Server.IService; using AgileConfig.Server.Service.EventRegisterService; using Microsoft.Extensions.DependencyInjection; @@ -10,11 +11,11 @@ public static void AddBusinessServices(this IServiceCollection sc) { sc.AddSingleton(); - sc.AddSingleton(); - sc.AddSingleton(); - sc.AddSingleton(); - sc.AddSingleton(); - + sc.AddScoped(); + sc.AddScoped(); + sc.AddScoped(); + sc.AddScoped(); + sc.AddScoped(); sc.AddScoped(); sc.AddScoped(); diff --git a/src/AgileConfig.Server.Service/ServiceHealthCheckService.cs b/src/AgileConfig.Server.Service/ServiceHealthCheckService.cs index e7ed3f20..0474d275 100644 --- a/src/AgileConfig.Server.Service/ServiceHealthCheckService.cs +++ b/src/AgileConfig.Server.Service/ServiceHealthCheckService.cs @@ -1,10 +1,10 @@ using System; using System.Threading.Tasks; using AgileConfig.Server.Common; +using AgileConfig.Server.Common.RestClient; using AgileConfig.Server.Data.Entity; using AgileConfig.Server.Data.Freesql; using AgileConfig.Server.IService; -using AgileHttp; using Microsoft.Extensions.Logging; namespace AgileConfig.Server.Service; @@ -12,14 +12,18 @@ namespace AgileConfig.Server.Service; public class ServiceHealthCheckService : IServiceHealthCheckService { private readonly ILogger _logger; + private readonly IRestClient _restClient; private readonly IServiceInfoService _serviceInfoService; public ServiceHealthCheckService( IServiceInfoService serviceInfoService, - ILogger logger) + ILogger logger, + IRestClient restClient + ) { _serviceInfoService = serviceInfoService; _logger = logger; + _restClient = restClient; } private int _checkInterval; @@ -189,20 +193,11 @@ private async Task CheckAService(ServiceInfo service) { try { - using var resp = await service.CheckUrl - .AsHttp() - .SendAsync(); - if (resp.Exception != null) - { - throw resp.Exception; - } + using var resp = await _restClient.GetAsync(service.CheckUrl); var result = false; - if (resp.StatusCode.HasValue) - { - int istatus = ((int)resp.StatusCode - 200); - result = istatus >= 0 && istatus < 100; // 200 段都认为是正常的 - } + int istatus = ((int)resp.StatusCode - 200); + result = istatus >= 0 && istatus < 100; // 200 段都认为是正常的 _logger.LogInformation("check service health {0} {1} {2} result:{3}", service.CheckUrl, service.ServiceId, service.ServiceName, result ? "up" : "down");