Skip to content

Commit

Permalink
🆕 feat: GetPublicConfigAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
wzh425 committed Aug 23, 2024
1 parent 3a3fbfe commit fdf95e1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// 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 PublicConfigQuery(string Environment, string Cluster, string ConfigObject) : Query<Dictionary<string, string>>
{
public override Dictionary<string, string> Result { get; set; }
}
14 changes: 13 additions & 1 deletion src/Services/Masa.Dcc.Service/Application/App/QueryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class QueryHandler
private readonly IAppConfigObjectRepository _appConfigObjectRepository;
private readonly IMasaStackConfig _masaStackConfig;
private readonly ConfigObjectDomainService _configObjectDomainService;
private readonly IConfigurationApiClient _configurationApiClient;

public QueryHandler(
IPublicConfigRepository publicConfigRepository,
Expand All @@ -27,7 +28,7 @@ public QueryHandler(
IAppConfigObjectRepository appConfigObjectRepository,
IMasaStackConfig masaStackConfig,
ConfigObjectDomainService configObjectDomainService,
IAuthClient authClient)
IConfigurationApiClient configurationApiClient)
{
_publicConfigRepository = publicConfigRepository;
_publicConfigObjectRepository = publicConfigObjectRepository;
Expand All @@ -39,6 +40,7 @@ public QueryHandler(
_appConfigObjectRepository = appConfigObjectRepository;
_masaStackConfig = masaStackConfig;
_configObjectDomainService = configObjectDomainService;
_configurationApiClient = configurationApiClient;
}

[EventHandler]
Expand Down Expand Up @@ -275,5 +277,15 @@ public async Task GetConfigObjectsAsync(ConfigObjectsByDynamicQuery query)
{
query.Result = await _configObjectDomainService.GetConfigObjectsAsync(query.environment, query.cluster, query.appId, query.configObjects);
}

[EventHandler]
public async Task GetPublicConfigAsync(PublicConfigQuery query)
{
query.Result = await _configurationApiClient.GetAsync<Dictionary<string, string>>(
query.Environment,
query.Cluster,
"public-$Config",
query.ConfigObject);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"TLS_NAME": "",
"CLUSTER": "Default",
"OTLP_URL": "https://otel-collector.masastack:9013",
"REDIS": "{\"RedisHost\": \"10.130.0.19\", \"RedisPort\": 2135, \"RedisDb\": 0,\"RedisPassword\": \"Hzss@123\"}",
"REDIS": "{\"RedisHost\": \"10.130.0.19\", \"RedisPort\": 2135, \"RedisDb\": 3,\"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\"}",
Expand Down
8 changes: 8 additions & 0 deletions src/Services/Masa.Dcc.Service/Services/OpenApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,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);
App.MapGet("open-api/releasing/{environment}/{cluster}/publicConfig/{configObject}", GetPublicConfigAsync);
}

public async Task UpdateConfigObjectAsync(IEventBus eventBus, string environment, string cluster, string appId, string configObject,
Expand All @@ -34,5 +35,12 @@ public async Task<Dictionary<string, PublishReleaseModel>> GetConfigObjectsAsync
await eventBus.PublishAsync(query);
return query.Result;
}

public async Task<Dictionary<string, string>> GetPublicConfigAsync(IEventBus eventBus, string environment, string cluster, string configObject)
{
var query = new PublicConfigQuery(environment, cluster, configObject);
await eventBus.PublishAsync(query);
return query.Result;
}
}
}
1 change: 1 addition & 0 deletions src/Services/Masa.Dcc.Service/_Imports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
global using Mapster;
global using Masa.BuildingBlocks.Authentication.Identity;
global using Masa.BuildingBlocks.Caching;
global using Masa.BuildingBlocks.Configuration;
global using Masa.BuildingBlocks.Data.UoW;
global using Masa.BuildingBlocks.Ddd.Domain.Entities.Full;
global using Masa.BuildingBlocks.Ddd.Domain.Events;
Expand Down

0 comments on commit fdf95e1

Please sign in to comment.