From 1b551f0a1bf94e5cd419cb3eb1f04948f2b90c57 Mon Sep 17 00:00:00 2001 From: duia <58941749+duiapro@users.noreply.github.com> Date: Mon, 13 Nov 2023 16:43:55 +0800 Subject: [PATCH] Feat/Add the get configuration api interface (#634) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat:add api open-api/releasing/get * fix:添加api获取配置接口 --- .../Queries/ConfigObjectsByDynamicQuery.cs | 11 +++++ .../Application/App/QueryHandler.cs | 6 +++ .../App/Services/ConfigObjectDomainService.cs | 43 +++++++++++++++++++ .../Properties/launchSettings.json | 4 +- .../Services/OpenApiService.cs | 9 ++++ .../appsettings.Development.json | 2 +- .../Properties/launchSettings.json | 4 +- 7 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 src/Services/Masa.Dcc.Service/Application/App/Queries/ConfigObjectsByDynamicQuery.cs diff --git a/src/Services/Masa.Dcc.Service/Application/App/Queries/ConfigObjectsByDynamicQuery.cs b/src/Services/Masa.Dcc.Service/Application/App/Queries/ConfigObjectsByDynamicQuery.cs new file mode 100644 index 00000000..932dcdf7 --- /dev/null +++ b/src/Services/Masa.Dcc.Service/Application/App/Queries/ConfigObjectsByDynamicQuery.cs @@ -0,0 +1,11 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Dcc.Service.Admin.Application.App.Queries +{ + public record class ConfigObjectsByDynamicQuery(string environment, string cluster, string appId, + List? configObjects) : Query> + { + public override Dictionary Result { get; set; } + } +} diff --git a/src/Services/Masa.Dcc.Service/Application/App/QueryHandler.cs b/src/Services/Masa.Dcc.Service/Application/App/QueryHandler.cs index a9ae3b73..9e1ff0c2 100644 --- a/src/Services/Masa.Dcc.Service/Application/App/QueryHandler.cs +++ b/src/Services/Masa.Dcc.Service/Application/App/QueryHandler.cs @@ -269,5 +269,11 @@ public async Task RefreshConfigObjectToRedisAsync(RefreshConfigObjectToRedisQuer { query.Result = await _configObjectDomainService.RefreshConfigObjectToRedisAsync(); } + + [EventHandler] + public async Task GetConfigObjectsAsync(ConfigObjectsByDynamicQuery query) + { + query.Result = await _configObjectDomainService.GetConfigObjectsAsync(query.environment, query.cluster, query.appId, query.configObjects); + } } } diff --git a/src/Services/Masa.Dcc.Service/Domain/App/Services/ConfigObjectDomainService.cs b/src/Services/Masa.Dcc.Service/Domain/App/Services/ConfigObjectDomainService.cs index 156a21cc..c06e4f54 100644 --- a/src/Services/Masa.Dcc.Service/Domain/App/Services/ConfigObjectDomainService.cs +++ b/src/Services/Masa.Dcc.Service/Domain/App/Services/ConfigObjectDomainService.cs @@ -1,6 +1,11 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the Apache License. See LICENSE.txt in the project root for license information. +using Masa.BuildingBlocks.Configuration; +using Masa.BuildingBlocks.Data; +using Masa.BuildingBlocks.StackSdks.Dcc.Contracts.Enum; +using Masa.Dcc.Service.Admin.Domain.App.Aggregates; + namespace Masa.Dcc.Service.Admin.Domain.App.Services { public class ConfigObjectDomainService : DomainService @@ -636,5 +641,43 @@ public async Task RefreshConfigObjectToRedisAsync() return "success"; } + + public async Task> GetConfigObjectsAsync(string environmentName, + string clusterName, string appId, List? configObjects) + { + var resultDic = new Dictionary(); + + var envs = await _pmClient.EnvironmentService.GetListAsync(); + var env = envs.FirstOrDefault(e => e.Name.ToLower() == environmentName.ToLower()) ?? throw new UserFriendlyException("Environment does not exist"); + var clusters = await _pmClient.ClusterService.GetListByEnvIdAsync(env.Id); + var cluster = clusters.FirstOrDefault(c => c.Name.ToLower() == clusterName.ToLower()) ?? throw new UserFriendlyException("Cluster does not exist"); + var apps = await _pmClient.AppService.GetListAsync(); + var app = apps.FirstOrDefault(apps => apps.Identity.ToLower() == appId.ToLower()) ?? throw new UserFriendlyException("AppId does not exist"); + + Expression> configObjectFilter = configObject => + configObject.AppConfigObject.EnvironmentClusterId == cluster.Id && + configObject.AppConfigObject.AppId == app.Id && + ((configObjects == null || configObjects.Count == 0) || configObjects.Contains(configObject.Name)); + var configObjectList = await _configObjectRepository.GetListAsync(configObjectFilter); + if (configObjects == null || configObjects.Count == 0) + { + var configObjectPublicList = await _configObjectRepository.GetListAsync(configObject => configObject.PublicConfigObject.EnvironmentClusterId == cluster.Id); + configObjectList = configObjectList.Union(configObjectPublicList); + } + + foreach (var configObject in configObjectList) + { + var key = $"{configObject.Name}".ToLower();//{environmentName}-{clusterName}-{appId}- + if (resultDic.ContainsKey(key)) continue; + resultDic.Add(key, new PublishReleaseModel() + { + Encryption = configObject.Encryption, + FormatLabelCode = configObject.FormatLabelCode, + Content = configObject.Content, + }); + } + + return resultDic; + } } } diff --git a/src/Services/Masa.Dcc.Service/Properties/launchSettings.json b/src/Services/Masa.Dcc.Service/Properties/launchSettings.json index 6d8d7802..ec7669ed 100644 --- a/src/Services/Masa.Dcc.Service/Properties/launchSettings.json +++ b/src/Services/Masa.Dcc.Service/Properties/launchSettings.json @@ -15,8 +15,8 @@ "TLS_NAME": "", "CLUSTER": "Default", "OTLP_URL": "https://otel-collector.masastack:9013", - "REDIS": "{\"RedisHost\": \"10.130.0.235\", \"RedisPort\": 24615, \"RedisDb\": 0,\"RedisPassword\": \"Hzss@123\"}", - "CONNECTIONSTRING": "{\"Server\": \"10.130.0.235\", \"Port\": 24878,\"Database\":\"pm-dev\",\"UserId\": \"ss\",\"Password\":\"Hzss@123\"}", + "REDIS": "{\"RedisHost\": \"10.130.0.19\", \"RedisPort\": 2135, \"RedisDb\": 0,\"RedisPassword\": \"Hzss@123\"}", + "CONNECTIONSTRING": "{\"Server\": \"10.130.0.19\", \"Port\": 2415,\"Database\":\"pm-dev\",\"UserId\": \"ss\",\"Password\":\"Hzss@123\"}", "MASA_STACK": "[{\"id\":\"pm\",\"service\":{\"id\":\"pm-service-dev\",\"domain\":\"http://pm-service-dev.masastack.com\"},\"web\":{\"id\":\"pm-web-dev\",\"domain\":\"https://pm-dev.masastack.com\"}},{\"id\":\"dcc\",\"service\":{\"id\":\"dcc-service-dev\",\"domain\":\"http://dcc-service-dev.masastack.com\"},\"web\":{\"id\":\"dcc-web-dev\",\"domain\":\"https://dcc-dev.masastack.com\"}},{\"id\":\"tsc\",\"service\":{\"id\":\"tsc-service-dev\",\"domain\":\"http://tsc-service-dev.masastack.com\"},\"web\":{\"id\":\"tsc-web-dev\",\"domain\":\"https://tsc-dev.masastack.com\"}},{\"id\":\"alert\",\"service\":{\"id\":\"alert-service-dev\",\"domain\":\"http://alert-service-dev.masastack.com\"},\"web\":{\"id\":\"alert-web-dev\",\"domain\":\"https://alert-dev.masastack.com\"}},{\"id\":\"scheduler\",\"service\":{\"id\":\"scheduler-service-dev\",\"domain\":\"http://scheduler-service-dev.masastack.com\"},\"worker\":{\"id\":\"scheduler-worker-dev\",\"domain\":\"http://scheduler-worker-dev.masastack.com\"},\"web\":{\"id\":\"scheduler-web-dev\",\"domain\":\"https://scheduler-dev.masastack.com\"}},{\"id\":\"mc\",\"service\":{\"id\":\"mc-service-dev\",\"domain\":\"http://mc-service-dev.masastack.com\"},\"web\":{\"id\":\"mc-web-dev\",\"domain\":\"https://mc-dev.masastack.com\"}},{\"id\":\"auth\",\"service\":{\"id\":\"auth-service-dev\",\"domain\":\"http://auth-service-dev.masastack.com\"},\"web\":{\"id\":\"auth-web-dev\",\"domain\":\"https://auth-dev.masastack.com\"},\"sso\":{\"id\":\"auth-sso-dev\",\"domain\":\"https://auth-sso-dev.masastack.com\"}}]", "ELASTIC": "{\"Nodes\": [\"http://es-ydy-new.lonsid.cn:9200\"],\"Index\": \"auth_user_development\"}", "ENVIRONMENT": "Development", diff --git a/src/Services/Masa.Dcc.Service/Services/OpenApiService.cs b/src/Services/Masa.Dcc.Service/Services/OpenApiService.cs index 42033980..672d0927 100644 --- a/src/Services/Masa.Dcc.Service/Services/OpenApiService.cs +++ b/src/Services/Masa.Dcc.Service/Services/OpenApiService.cs @@ -9,6 +9,7 @@ public OpenApiService() { App.MapPut("open-api/releasing/{environment}/{cluster}/{appId}/{configObject}", UpdateConfigObjectAsync); App.MapPost("open-api/releasing/{environment}/{cluster}/{appId}/{isEncryption}", AddConfigObjectAsync); + App.MapPost("open-api/releasing/get/{environment}/{cluster}/{appId}", GetConfigObjectsAsync); } public async Task UpdateConfigObjectAsync(IEventBus eventBus, string environment, string cluster, string appId, string configObject, @@ -25,5 +26,13 @@ public async Task AddConfigObjectAsync(IEventBus eventBus, string environment, s await eventBus.PublishAsync( new InitConfigObjectCommand(environment, cluster, appId, configObjects, configObjectType, isEncryption)); } + + public async Task> GetConfigObjectsAsync(IEventBus eventBus, string environment, string cluster, string appId, + [FromBody] List? configObjects) + { + var query = new ConfigObjectsByDynamicQuery(environment, cluster, appId, configObjects); + await eventBus.PublishAsync(query); + return query.Result; + } } } diff --git a/src/Services/Masa.Dcc.Service/appsettings.Development.json b/src/Services/Masa.Dcc.Service/appsettings.Development.json index 40b06363..4085a7fe 100644 --- a/src/Services/Masa.Dcc.Service/appsettings.Development.json +++ b/src/Services/Masa.Dcc.Service/appsettings.Development.json @@ -7,6 +7,6 @@ } }, "ConnectionStrings": { - "DefaultConnection": "Server=10.175.171.201,32679;Database=dcc_dev;User Id=ss;Password=Hzss@123;" + "DefaultConnection": "Server=10.130.0.19:2415;Database=dcc_dev;User Id=ss;Password=Hzss@123;" } } diff --git a/src/Web/Masa.Dcc.Web.Admin/Masa.Dcc.Web.Admin.Server/Properties/launchSettings.json b/src/Web/Masa.Dcc.Web.Admin/Masa.Dcc.Web.Admin.Server/Properties/launchSettings.json index 3ee11d16..de8951b4 100644 --- a/src/Web/Masa.Dcc.Web.Admin/Masa.Dcc.Web.Admin.Server/Properties/launchSettings.json +++ b/src/Web/Masa.Dcc.Web.Admin/Masa.Dcc.Web.Admin.Server/Properties/launchSettings.json @@ -24,8 +24,8 @@ "TLS_NAME": "", "CLUSTER": "Default", "OTLP_URL": "https://otel-collector.masastack:9013", - "REDIS": "{\"RedisHost\": \"10.130.0.235\", \"RedisPort\": 24615, \"RedisDb\": 0,\"RedisPassword\": \"Hzss@123\"}", - "CONNECTIONSTRING": "{\"Server\": \"10.130.0.235\", \"Port\": 24878,\"Database\":\"pm-dev\",\"UserId\": \"ss\",\"Password\":\"Hzss@123\"}", + "REDIS": "{\"RedisHost\": \"10.130.0.19\", \"RedisPort\": 2135, \"RedisDb\": 0,\"RedisPassword\": \"Hzss@123\"}", + "CONNECTIONSTRING": "{\"Server\": \"10.130.0.19\", \"Port\": 2415,\"Database\":\"pm-dev\",\"UserId\": \"ss\",\"Password\":\"Hzss@123\"}", "MASA_STACK": "[{\"id\":\"pm\",\"service\":{\"id\":\"pm-service-dev\",\"domain\":\"http://pm-service-dev.masastack.com\"},\"web\":{\"id\":\"pm-web-dev\",\"domain\":\"https://pm-dev.masastack.com\"}},{\"id\":\"dcc\",\"service\":{\"id\":\"dcc-service-dev\",\"domain\":\"http://dcc-service-dev.masastack.com\"},\"web\":{\"id\":\"dcc-web-dev\",\"domain\":\"https://dcc-dev.masastack.com\"}},{\"id\":\"tsc\",\"service\":{\"id\":\"tsc-service-dev\",\"domain\":\"http://tsc-service-dev.masastack.com\"},\"web\":{\"id\":\"tsc-web-dev\",\"domain\":\"https://tsc-dev.masastack.com\"}},{\"id\":\"alert\",\"service\":{\"id\":\"alert-service-dev\",\"domain\":\"http://alert-service-dev.masastack.com\"},\"web\":{\"id\":\"alert-web-dev\",\"domain\":\"https://alert-dev.masastack.com\"}},{\"id\":\"scheduler\",\"service\":{\"id\":\"scheduler-service-dev\",\"domain\":\"http://scheduler-service-dev.masastack.com\"},\"worker\":{\"id\":\"scheduler-worker-dev\",\"domain\":\"http://scheduler-worker-dev.masastack.com\"},\"web\":{\"id\":\"scheduler-web-dev\",\"domain\":\"https://scheduler-dev.masastack.com\"}},{\"id\":\"mc\",\"service\":{\"id\":\"mc-service-dev\",\"domain\":\"http://mc-service-dev.masastack.com\"},\"web\":{\"id\":\"mc-web-dev\",\"domain\":\"https://mc-dev.masastack.com\"}},{\"id\":\"auth\",\"service\":{\"id\":\"auth-service-dev\",\"domain\":\"http://auth-service-dev.masastack.com\"},\"web\":{\"id\":\"auth-web-dev\",\"domain\":\"https://auth-dev.masastack.com\"},\"sso\":{\"id\":\"auth-sso-dev\",\"domain\":\"https://auth-sso-dev.masastack.com\"}}]", "ELASTIC": "{\"Nodes\": [\"http://es-ydy-new.lonsid.cn:9200\"],\"Index\": \"auth_user_development\"}", "ENVIRONMENT": "Development",