diff --git a/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IAppConfigObjectRepository.cs b/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IAppConfigObjectRepository.cs index 3bec9c22..1ba2d646 100644 --- a/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IAppConfigObjectRepository.cs +++ b/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IAppConfigObjectRepository.cs @@ -11,5 +11,7 @@ public interface IAppConfigObjectRepository : IRepository Task> GetAppLatestReleaseConfigAsync(IEnumerable appIds, int? envClusterId = null); + + Task GetbyConfigObjectIdAsync(int configObjectId); } } diff --git a/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IBizConfigObjectRepository.cs b/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IBizConfigObjectRepository.cs index 4e68e49a..c41b1a48 100644 --- a/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IBizConfigObjectRepository.cs +++ b/src/Services/Masa.Dcc.Service/Domain/App/Repositories/IBizConfigObjectRepository.cs @@ -12,5 +12,7 @@ Task> GetListByEnvClusterIdAsync(int envClusterId, int biz Task> GetProjectLatestReleaseConfigAsync( List projects, int? envClusterId = null); + + Task GetByConfigObjectIdAsync(int configObjectId); } } 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 04fcca29..156a21cc 100644 --- a/src/Services/Masa.Dcc.Service/Domain/App/Services/ConfigObjectDomainService.cs +++ b/src/Services/Masa.Dcc.Service/Domain/App/Services/ConfigObjectDomainService.cs @@ -366,7 +366,6 @@ public async Task AddConfigObjectReleaseAsync(AddConfigObjectReleaseDto dto) else { //add redis cache - //TODO: encryption value var key = $"{dto.EnvironmentName}-{dto.ClusterName}-{dto.Identity}-{configObject.Name}"; if (configObject.Encryption) { @@ -425,6 +424,38 @@ await _configObjectReleaseRepository.AddAsync(new ConfigObjectRelease( var configObject = (await _configObjectRepository.FindAsync(config => config.Id == rollbackDto.ConfigObjectId))!; configObject.AddContent(configObject.Content, rollbackToEntity.Content); await _configObjectRepository.UpdateAsync(configObject); + + string key = string.Empty; + var envClusters = await _pmClient.ClusterService.GetEnvironmentClustersAsync(); + if (configObject.Type == ConfigObjectType.Public) + { + var publicConfigObject = await _publicConfigObjectRepository.GetByConfigObjectIdAsync(configObject.Id); + var publicConfig = await _publicConfigRepository.FindAsync(c => c.Id == publicConfigObject.PublicConfigId) ?? throw new MasaException(); + var envCluster = envClusters.First(e => e.Id == publicConfigObject.EnvironmentClusterId); + key = $"{envCluster.EnvironmentName}-{envCluster.ClusterName}-{publicConfig.Identity}-{configObject.Name}"; + } + else if (configObject.Type == ConfigObjectType.Biz) + { + var bizConfigObject = await _bizConfigObjectRepository.GetByConfigObjectIdAsync(configObject.Id); + var bizConfig = await _bizConfigRepository.FindAsync(c => c.Id == bizConfigObject.BizConfigId) ?? throw new MasaException(); + var envCluster = envClusters.First(e => e.Id == bizConfigObject.EnvironmentClusterId); + key = $"{envCluster.EnvironmentName}-{envCluster.ClusterName}-{bizConfig.Identity}-{configObject.Name}"; + } + else if (configObject.Type == ConfigObjectType.App) + { + var appConfigObject = await _appConfigObjectRepository.GetbyConfigObjectIdAsync(configObject.Id); + var app = await _pmClient.AppService.GetAsync(appConfigObject.AppId) ?? throw new MasaException(); ; + var envCluster = envClusters.First(e => e.Id == appConfigObject.EnvironmentClusterId); + key = $"{envCluster.EnvironmentName}-{envCluster.ClusterName}-{app.Identity}-{configObject.Name}"; + } + + var releaseContent = new PublishReleaseModel + { + Content = configObject.Encryption ? EncryptContent(rollbackToEntity.Content) : rollbackToEntity.Content, + FormatLabelCode = configObject.FormatLabelCode, + Encryption = configObject.Encryption + }; + await _memoryCacheClient.SetAsync(key.ToLower(), releaseContent); } public async Task UpdateConfigObjectAsync( diff --git a/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/AppConfigObjectRepository.cs b/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/AppConfigObjectRepository.cs index 9b451a2c..9e3221c8 100644 --- a/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/AppConfigObjectRepository.cs +++ b/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/AppConfigObjectRepository.cs @@ -64,5 +64,14 @@ public async Task> GetListByAppIdAsync(int appId) return configData; } + + + public async Task GetbyConfigObjectIdAsync(int configObjectId) + { + var result = await Context.Set() + .FirstOrDefaultAsync(p => p.ConfigObjectId == configObjectId); + + return result ?? new(0, 0); + } } } diff --git a/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/BizConfigObjectRepository.cs b/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/BizConfigObjectRepository.cs index 3eb02574..3d5eb88d 100644 --- a/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/BizConfigObjectRepository.cs +++ b/src/Services/Masa.Dcc.Service/Infrastructure/Repositories/App/BizConfigObjectRepository.cs @@ -88,5 +88,13 @@ from release in rNullable.DefaultIfEmpty() return result; } + + public async Task GetByConfigObjectIdAsync(int configObjectId) + { + var result = await Context.Set() + .FirstOrDefaultAsync(p => p.ConfigObjectId == configObjectId); + + return result ?? new(0, 0); + } } }