Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add getStackConfigAsync and getI18NConfigAsync #647

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Masa.Dcc.Infrastructure.Domain/App/Queries/I18NConfigQuery.cs
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.Infrastructure.Domain.App.Queries;

public record class I18NConfigQuery(string Environment, string Cluster, string Culture) : Query<Dictionary<string, string>>
{
public override Dictionary<string, string> Result { get; set; }
}
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.Infrastructure.Domain.App.Queries;

public record class StackConfigQuery(string Environment, string Cluster) : Query<Dictionary<string, string>>
{
public override Dictionary<string, string> Result { get; set; }
}
39 changes: 39 additions & 0 deletions Masa.Dcc.Infrastructure.Domain/App/QueryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,43 @@ public async Task GetConfigObjectsAsync(ConfigObjectsByDynamicQuery query)
{
query.Result = await _configObjectDomainService.GetConfigObjectsAsync(query.environment, query.cluster, query.appId, query.configObjects);
}

[EventHandler]
public async Task GetStackConfigAsync(StackConfigQuery query)
{
var defaultConfig = await _configurationApiClient.GetAsync<Dictionary<string, string>>(
query.Environment,
query.Cluster,
"public-$Config",
"$public.DefaultConfig");

var allowedSafeKeys = new List<string>
{
MasaStackConfigConstant.VERSION,
MasaStackConfigConstant.ENVIRONMENT,
MasaStackConfigConstant.IS_DEMO,
MasaStackConfigConstant.CLUSTER,
MasaStackConfigConstant.DOMAIN_NAME,
MasaStackConfigConstant.NAMESPACE,
MasaStackConfigConstant.MASA_STACK,
MasaStackConfigConstant.OTLP_URL
};

var stackConfig = defaultConfig.Where(x => allowedSafeKeys.Contains(x.Key))
.ToDictionary(x => x.Key, x => x.Value);

query.Result = stackConfig;
}

[EventHandler]
public async Task GetI18NConfigAsync(I18NConfigQuery query)
{
var i18nConfig = await _configurationApiClient.GetAsync<Dictionary<string, string>>(
query.Environment,
query.Cluster,
"public-$Config",
$"$public.i18n.{query.Culture}");

query.Result = i18nConfig;
}
}
1 change: 1 addition & 0 deletions Masa.Dcc.Infrastructure.Domain/_Imports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
global using Masa.Dcc.Contracts.Admin.App.Dtos;
global using Masa.Dcc.Contracts.Admin.App.Enums;
global using Masa.Dcc.Contracts.Admin.Label.Dtos;
global using Masa.Dcc.Infrastructure.Domain.App.Queries;
global using Masa.Dcc.Infrastructure.Domain.Commands;
global using Masa.Dcc.Infrastructure.Domain.Queries;
global using Masa.Dcc.Infrastructure.Domain.Services;
Expand Down
16 changes: 16 additions & 0 deletions src/Services/Masa.Dcc.Service/Services/OpenApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ 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}/stack-config", GetStackConfigAsync);
App.MapGet("open-api/releasing/{environment}/{cluster}/i18n/{culture}", GetI18NConfigAsync);
}

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

public async Task<Dictionary<string, string>> GetStackConfigAsync(IEventBus eventBus, string environment, string cluster)
{
var query = new StackConfigQuery(environment, cluster);
await eventBus.PublishAsync(query);
return query.Result;
}

public async Task<Dictionary<string, string>> GetI18NConfigAsync(IEventBus eventBus, string environment, string cluster, string culture)
{
var query = new I18NConfigQuery(environment, cluster, culture);
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 @@ -30,6 +30,7 @@
global using Masa.Dcc.Contracts.Admin.App.Dtos;
global using Masa.Dcc.Contracts.Admin.App.Enums;
global using Masa.Dcc.Contracts.Admin.Label.Dtos;
global using Masa.Dcc.Infrastructure.Domain.App.Queries;
global using Masa.Dcc.Infrastructure.Domain.Commands;
global using Masa.Dcc.Infrastructure.Domain.Queries;
global using Masa.Dcc.Infrastructure.Domain.Services;
Expand Down
Loading