@Test void testGenerateCertAndSaveForStackAndUpdateDnsEntryShouldUpdateDnsEntryWhenUserFacingCertHasAlreadyBeenGenerated() { SecurityConfig securityConfig = new SecurityConfig(); securityConfig.setUserFacingKey(USER_FACING_PRIVATE_KEY); securityConfig.setUserFacingCert("CERT"); Cluster cluster = TestUtil.cluster(); Stack stack = cluster.getStack(); stack.setSecurityConfig(securityConfig); stack.setCluster(cluster); InstanceMetaData primaryGatewayInstance = stack.getPrimaryGatewayInstance(); String endpointName = primaryGatewayInstance.getShortHostname(); String envName = "anEnvName"; String accountWorkloadSubdomain = "aWorkloadSubdomain"; String fqdn = endpointName + ".anenvname.xcu2-8y8x.dev.cldr.work"; DetailedEnvironmentResponse environment = DetailedEnvironmentResponse.Builder .builder() .withName(envName) .build(); when(environmentClientService.getByCrn(Mockito.anyString())).thenReturn(environment); UserManagementProto.Account umsAccount = UserManagementProto.Account.newBuilder() .setWorkloadSubdomain(accountWorkloadSubdomain) .build(); when(grpcUmsClient.getAccountDetails(USER_CRN, "123", Optional.empty())).thenReturn(umsAccount); when(domainNameProvider.getFullyQualifiedEndpointName(endpointName, envName, accountWorkloadSubdomain)).thenReturn(fqdn); when(dnsManagementService.createOrUpdateDnsEntryWithIp(eq(USER_CRN), eq("123"), eq(endpointName), eq(envName), eq(Boolean.FALSE), eq(List.of(primaryGatewayInstance.getPublicIpWrapper())))).thenReturn(Boolean.TRUE); boolean result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.generateCertAndSaveForStackAndUpdateDnsEntry(stack)); verify(environmentClientService, times(1)).getByCrn(anyString()); verify(grpcUmsClient, times(1)).getAccountDetails(USER_CRN, "123", Optional.empty()); verify(domainNameProvider, times(1)).getFullyQualifiedEndpointName(endpointName, envName, accountWorkloadSubdomain); verify(dnsManagementService, times(1)) .createOrUpdateDnsEntryWithIp(eq(USER_CRN), eq("123"), eq(endpointName), eq(envName), eq(Boolean.FALSE), eq(List.of(primaryGatewayInstance.getPublicIpWrapper()))); verify(clusterService, times(1)).save(any(Cluster.class)); Assertions.assertEquals(Boolean.FALSE, result); }
public boolean generateCertAndSaveForStackAndUpdateDnsEntry(Stack stack) { boolean success = false; if (manageCertificateAndDnsInPem() && stack != null && stack.getCluster() != null) { if (StringUtils.isEmpty(stack.getSecurityConfig().getUserFacingCert())) { success = generateCertAndSaveForStack(stack); } updateDnsEntryForCluster(stack); } else { LOGGER.info("External FQDN and valid certificate creation is disabled."); } return success; }
GatewayPublicEndpointManagementService extends BasePublicEndpointManagementService { public boolean generateCertAndSaveForStackAndUpdateDnsEntry(Stack stack) { boolean success = false; if (manageCertificateAndDnsInPem() && stack != null && stack.getCluster() != null) { if (StringUtils.isEmpty(stack.getSecurityConfig().getUserFacingCert())) { success = generateCertAndSaveForStack(stack); } updateDnsEntryForCluster(stack); } else { LOGGER.info("External FQDN and valid certificate creation is disabled."); } return success; } }
GatewayPublicEndpointManagementService extends BasePublicEndpointManagementService { public boolean generateCertAndSaveForStackAndUpdateDnsEntry(Stack stack) { boolean success = false; if (manageCertificateAndDnsInPem() && stack != null && stack.getCluster() != null) { if (StringUtils.isEmpty(stack.getSecurityConfig().getUserFacingCert())) { success = generateCertAndSaveForStack(stack); } updateDnsEntryForCluster(stack); } else { LOGGER.info("External FQDN and valid certificate creation is disabled."); } return success; }  }
GatewayPublicEndpointManagementService extends BasePublicEndpointManagementService { public boolean generateCertAndSaveForStackAndUpdateDnsEntry(Stack stack) { boolean success = false; if (manageCertificateAndDnsInPem() && stack != null && stack.getCluster() != null) { if (StringUtils.isEmpty(stack.getSecurityConfig().getUserFacingCert())) { success = generateCertAndSaveForStack(stack); } updateDnsEntryForCluster(stack); } else { LOGGER.info("External FQDN and valid certificate creation is disabled."); } return success; }  boolean isCertRenewalTriggerable(Stack stack); boolean generateCertAndSaveForStackAndUpdateDnsEntry(Stack stack); String updateDnsEntry(Stack stack, String gatewayIp); String deleteDnsEntry(Stack stack, String environmentName); boolean renewCertificate(Stack stack); }
GatewayPublicEndpointManagementService extends BasePublicEndpointManagementService { public boolean generateCertAndSaveForStackAndUpdateDnsEntry(Stack stack) { boolean success = false; if (manageCertificateAndDnsInPem() && stack != null && stack.getCluster() != null) { if (StringUtils.isEmpty(stack.getSecurityConfig().getUserFacingCert())) { success = generateCertAndSaveForStack(stack); } updateDnsEntryForCluster(stack); } else { LOGGER.info("External FQDN and valid certificate creation is disabled."); } return success; }  boolean isCertRenewalTriggerable(Stack stack); boolean generateCertAndSaveForStackAndUpdateDnsEntry(Stack stack); String updateDnsEntry(Stack stack, String gatewayIp); String deleteDnsEntry(Stack stack, String environmentName); boolean renewCertificate(Stack stack);  }