|
7 | 7 |
|
8 | 8 | package io.harness.ng.core.environment.resources; |
9 | 9 |
|
| 10 | +import static io.harness.beans.FeatureName.NG_SERVICE_CONFIG_FILES_OVERRIDE; |
10 | 11 | import static io.harness.beans.FeatureName.NG_SERVICE_MANIFEST_OVERRIDE; |
11 | 12 | import static io.harness.data.structure.EmptyPredicate.isEmpty; |
12 | 13 | import static io.harness.data.structure.EmptyPredicate.isNotEmpty; |
13 | 14 | import static io.harness.ng.accesscontrol.PlatformPermissions.VIEW_PROJECT_PERMISSION; |
14 | 15 | import static io.harness.ng.accesscontrol.PlatformResourceTypes.PROJECT; |
| 16 | +import static io.harness.ng.core.environment.mappers.EnvironmentMapper.checkDuplicateConfigFilesIdentifiersWithIn; |
15 | 17 | import static io.harness.ng.core.environment.mappers.EnvironmentMapper.checkDuplicateManifestIdentifiersWithIn; |
16 | 18 | import static io.harness.ng.core.environment.mappers.EnvironmentMapper.toNGEnvironmentConfig; |
17 | 19 | import static io.harness.ng.core.serviceoverride.mapper.NGServiceOverrideEntityConfigMapper.toNGServiceOverrideConfig; |
@@ -226,8 +228,10 @@ public class EnvironmentResourceV2 { |
226 | 228 | environmentRequestDTO.getProjectIdentifier()), |
227 | 229 | Resource.of(ENVIRONMENT, null, environmentAttributes), ENVIRONMENT_CREATE_PERMISSION); |
228 | 230 | final boolean ngSvcManifestOverrideEnabled = cdFeatureFlagHelper.isEnabled(accountId, NG_SERVICE_MANIFEST_OVERRIDE); |
229 | | - Environment environmentEntity = |
230 | | - EnvironmentMapper.toEnvironmentEntity(accountId, environmentRequestDTO, ngSvcManifestOverrideEnabled); |
| 231 | + final boolean ngSvcConfigFileOverrideEnabled = |
| 232 | + cdFeatureFlagHelper.isEnabled(accountId, NG_SERVICE_CONFIG_FILES_OVERRIDE); |
| 233 | + Environment environmentEntity = EnvironmentMapper.toEnvironmentEntity( |
| 234 | + accountId, environmentRequestDTO, ngSvcManifestOverrideEnabled, ngSvcConfigFileOverrideEnabled); |
231 | 235 | orgAndProjectValidationHelper.checkThatTheOrganizationAndProjectExists(environmentEntity.getOrgIdentifier(), |
232 | 236 | environmentEntity.getProjectIdentifier(), environmentEntity.getAccountId()); |
233 | 237 | Environment createdEnvironment = environmentService.create(environmentEntity); |
@@ -279,8 +283,10 @@ public class EnvironmentResourceV2 { |
279 | 283 | Resource.of(ENVIRONMENT, environmentRequestDTO.getIdentifier()), ENVIRONMENT_UPDATE_PERMISSION); |
280 | 284 |
|
281 | 285 | final boolean ngSvcManifestOverrideEnabled = cdFeatureFlagHelper.isEnabled(accountId, NG_SERVICE_MANIFEST_OVERRIDE); |
282 | | - Environment requestEnvironment = |
283 | | - EnvironmentMapper.toEnvironmentEntity(accountId, environmentRequestDTO, ngSvcManifestOverrideEnabled); |
| 286 | + final boolean ngSvcConfigFileOverrideEnabled = |
| 287 | + cdFeatureFlagHelper.isEnabled(accountId, NG_SERVICE_CONFIG_FILES_OVERRIDE); |
| 288 | + Environment requestEnvironment = EnvironmentMapper.toEnvironmentEntity( |
| 289 | + accountId, environmentRequestDTO, ngSvcManifestOverrideEnabled, ngSvcConfigFileOverrideEnabled); |
284 | 290 | requestEnvironment.setVersion(isNumeric(ifMatch) ? parseLong(ifMatch) : null); |
285 | 291 | Environment updatedEnvironment = environmentService.update(requestEnvironment); |
286 | 292 | return ResponseDTO.newResponse( |
@@ -308,8 +314,10 @@ public class EnvironmentResourceV2 { |
308 | 314 | Resource.of(ENVIRONMENT, environmentRequestDTO.getIdentifier()), ENVIRONMENT_UPDATE_PERMISSION); |
309 | 315 |
|
310 | 316 | final boolean ngSvcManifestOverrideEnabled = cdFeatureFlagHelper.isEnabled(accountId, NG_SERVICE_MANIFEST_OVERRIDE); |
311 | | - Environment requestEnvironment = |
312 | | - EnvironmentMapper.toEnvironmentEntity(accountId, environmentRequestDTO, ngSvcManifestOverrideEnabled); |
| 317 | + final boolean ngSvcConfigFileOverrideEnabled = |
| 318 | + cdFeatureFlagHelper.isEnabled(accountId, NG_SERVICE_CONFIG_FILES_OVERRIDE); |
| 319 | + Environment requestEnvironment = EnvironmentMapper.toEnvironmentEntity( |
| 320 | + accountId, environmentRequestDTO, ngSvcManifestOverrideEnabled, ngSvcConfigFileOverrideEnabled); |
313 | 321 | requestEnvironment.setVersion(isNumeric(ifMatch) ? parseLong(ifMatch) : null); |
314 | 322 | orgAndProjectValidationHelper.checkThatTheOrganizationAndProjectExists(requestEnvironment.getOrgIdentifier(), |
315 | 323 | requestEnvironment.getProjectIdentifier(), requestEnvironment.getAccountId()); |
@@ -507,22 +515,30 @@ public ResponseDTO<NGEnvironmentConfig> getNGEnvironmentConfig() { |
507 | 515 | serviceOverridesEntity.getProjectIdentifier(), serviceOverridesEntity.getEnvironmentRef(), |
508 | 516 | serviceOverridesEntity.getServiceRef()); |
509 | 517 | final boolean ngManifestOverrideEnabled = cdFeatureFlagHelper.isEnabled(accountId, NG_SERVICE_MANIFEST_OVERRIDE); |
510 | | - validateServiceOverrides(serviceOverridesEntity, ngManifestOverrideEnabled); |
| 518 | + final boolean ngConfigOverrideEnabled = cdFeatureFlagHelper.isEnabled(accountId, NG_SERVICE_CONFIG_FILES_OVERRIDE); |
| 519 | + validateServiceOverrides(serviceOverridesEntity, ngManifestOverrideEnabled, ngConfigOverrideEnabled); |
511 | 520 |
|
512 | 521 | NGServiceOverridesEntity createdServiceOverride = serviceOverrideService.upsert(serviceOverridesEntity); |
513 | 522 | return ResponseDTO.newResponse(ServiceOverridesMapper.toResponseWrapper(createdServiceOverride)); |
514 | 523 | } |
515 | 524 |
|
516 | | - private void validateServiceOverrides( |
517 | | - NGServiceOverridesEntity serviceOverridesEntity, boolean ngManifestOverrideEnabled) { |
| 525 | + private void validateServiceOverrides(NGServiceOverridesEntity serviceOverridesEntity, |
| 526 | + boolean ngManifestOverrideEnabled, boolean ngConfigOverrideEnabled) { |
518 | 527 | final NGServiceOverrideConfig serviceOverrideConfig = toNGServiceOverrideConfig(serviceOverridesEntity); |
519 | 528 | if (serviceOverrideConfig.getServiceOverrideInfoConfig() != null) { |
520 | 529 | if (!ngManifestOverrideEnabled |
521 | 530 | && isNotEmpty(serviceOverrideConfig.getServiceOverrideInfoConfig().getManifests())) { |
522 | 531 | throw new InvalidRequestException( |
523 | | - "Manifest Override is not supported with FF disabled NG_SERVICE_MANIFEST_OVERRIDE"); |
| 532 | + "Manifest Override is not supported with FF disabled NG_SERVICE_MANIFEST_OVERRIDE"); |
524 | 533 | } |
| 534 | + if (!ngConfigOverrideEnabled |
| 535 | + && isNotEmpty(serviceOverrideConfig.getServiceOverrideInfoConfig().getConfigFiles())) { |
| 536 | + throw new InvalidRequestException( |
| 537 | + "Config Files Override is not supported with FF disabled NG_SERVICE_CONFIG_FILES_OVERRIDE"); |
| 538 | + } |
| 539 | + |
525 | 540 | checkDuplicateManifestIdentifiersWithIn(serviceOverrideConfig.getServiceOverrideInfoConfig().getManifests()); |
| 541 | + checkDuplicateConfigFilesIdentifiersWithIn(serviceOverrideConfig.getServiceOverrideInfoConfig().getConfigFiles()); |
526 | 542 | } |
527 | 543 | } |
528 | 544 |
|
|
0 commit comments