@Test void testLoadConfigFolder() throws IOException { mockEntityLoader(); final File configFolder = rootProjectDir.createDirectory("config"); final File identityProvidersFile = new File(configFolder, "identity-providers.yml"); Files.touch(identityProvidersFile); Mockito.when(fileUtils.getInputStream(Mockito.any(File.class))).thenReturn(new ByteArrayInputStream(yml.getBytes(Charset.forName("UTF-8")))); EntityTypeRegistry entityTypeRegistry = new EntityTypeRegistry(new Reflections()); EnvironmentConfigurationUtils environmentConfigurationUtils = new EnvironmentConfigurationUtils(JsonTools.INSTANCE, entityLoaderRegistry, JsonFileUtils.INSTANCE, entityTypeRegistry); Map<String, String> map = environmentConfigurationUtils.loadConfigFolder(configFolder); Assert.assertNotNull(map.get("ENV.IDENTITY_PROVIDER.simple ldap")); }
public Map<String, String> loadConfigFolder(final File configFolder) { final Map<String, String> environmentValues = new LinkedHashMap<>(); final Map<String, EntityUtils.GatewayEntityInfo> entityInfoMap = entityTypeRegistry.getEnvironmentEntityTypes(); entityInfoMap.entrySet().forEach(entityInfoEntry -> { final String entityType; if (EntityTypes.CLUSTER_PROPERTY_TYPE.equals(entityInfoEntry.getKey())) { entityType = "ENVIRONMENT_PROPERTY"; } else { entityType = entityInfoEntry.getKey(); } Class<? extends GatewayEntity> entityClass = entityInfoEntry.getValue().getEntityClass(); final Pair<String, ConfigurationFile.FileType> configFileInfo = EntityUtils.getEntityConfigFileInfo(entityClass); final String environmentType = EntityUtils.getEntityEnvironmentType(entityClass); if (configFileInfo != null && environmentType != null) { final String configFileName = configFileInfo.getLeft() + "." + (configFileInfo.getRight().equals(ConfigurationFile.FileType.JSON_YAML) ? YML_EXTENSION : configFileInfo.getRight().name().toLowerCase()); final File envConfigFile = new File(configFolder, configFileName); if (envConfigFile.exists()) { Map<String, String> entities = loadConfigFromFile(envConfigFile, environmentType); entities.entrySet().forEach(entry -> { environmentValues.put(PREFIX_ENV + environmentType + "." + entry.getKey(), entry.getValue()); if (EntityTypes.TRUSTED_CERT_TYPE.equals(entityType)) { final File certDataFile = new File(configFolder + "/certificates", entry.getKey() + PEM_CERT_FILE_EXTENSION); environmentValues.put(PREFIX_ENV + "CERTIFICATE_FILE" + "." + entry.getKey() + PEM_CERT_FILE_EXTENSION, loadConfigFromFile(certDataFile, "CERTIFICATE_FILE", entry.getKey())); } else if (EntityTypes.PRIVATE_KEY_TYPE.equals(entityType)) { final File privateKeysFolder = new File(configFolder, "privateKeys"); if (privateKeysFolder.exists()) { File privateKeyFile = new File(privateKeysFolder, entry.getKey() + P12_CERT_FILE_EXTENSION); if (privateKeyFile.exists()) { environmentValues.put(PREFIX_ENV + "PRIVATE_KEY_FILE." + entry.getKey() + P12_CERT_FILE_EXTENSION, loadConfigFromFile(privateKeyFile, "PRIVATE_KEY_FILE", entry.getKey())); } } } }); } } }); return environmentValues; }
EnvironmentConfigurationUtils { public Map<String, String> loadConfigFolder(final File configFolder) { final Map<String, String> environmentValues = new LinkedHashMap<>(); final Map<String, EntityUtils.GatewayEntityInfo> entityInfoMap = entityTypeRegistry.getEnvironmentEntityTypes(); entityInfoMap.entrySet().forEach(entityInfoEntry -> { final String entityType; if (EntityTypes.CLUSTER_PROPERTY_TYPE.equals(entityInfoEntry.getKey())) { entityType = "ENVIRONMENT_PROPERTY"; } else { entityType = entityInfoEntry.getKey(); } Class<? extends GatewayEntity> entityClass = entityInfoEntry.getValue().getEntityClass(); final Pair<String, ConfigurationFile.FileType> configFileInfo = EntityUtils.getEntityConfigFileInfo(entityClass); final String environmentType = EntityUtils.getEntityEnvironmentType(entityClass); if (configFileInfo != null && environmentType != null) { final String configFileName = configFileInfo.getLeft() + "." + (configFileInfo.getRight().equals(ConfigurationFile.FileType.JSON_YAML) ? YML_EXTENSION : configFileInfo.getRight().name().toLowerCase()); final File envConfigFile = new File(configFolder, configFileName); if (envConfigFile.exists()) { Map<String, String> entities = loadConfigFromFile(envConfigFile, environmentType); entities.entrySet().forEach(entry -> { environmentValues.put(PREFIX_ENV + environmentType + "." + entry.getKey(), entry.getValue()); if (EntityTypes.TRUSTED_CERT_TYPE.equals(entityType)) { final File certDataFile = new File(configFolder + "/certificates", entry.getKey() + PEM_CERT_FILE_EXTENSION); environmentValues.put(PREFIX_ENV + "CERTIFICATE_FILE" + "." + entry.getKey() + PEM_CERT_FILE_EXTENSION, loadConfigFromFile(certDataFile, "CERTIFICATE_FILE", entry.getKey())); } else if (EntityTypes.PRIVATE_KEY_TYPE.equals(entityType)) { final File privateKeysFolder = new File(configFolder, "privateKeys"); if (privateKeysFolder.exists()) { File privateKeyFile = new File(privateKeysFolder, entry.getKey() + P12_CERT_FILE_EXTENSION); if (privateKeyFile.exists()) { environmentValues.put(PREFIX_ENV + "PRIVATE_KEY_FILE." + entry.getKey() + P12_CERT_FILE_EXTENSION, loadConfigFromFile(privateKeyFile, "PRIVATE_KEY_FILE", entry.getKey())); } } } }); } } }); return environmentValues; } }
EnvironmentConfigurationUtils { public Map<String, String> loadConfigFolder(final File configFolder) { final Map<String, String> environmentValues = new LinkedHashMap<>(); final Map<String, EntityUtils.GatewayEntityInfo> entityInfoMap = entityTypeRegistry.getEnvironmentEntityTypes(); entityInfoMap.entrySet().forEach(entityInfoEntry -> { final String entityType; if (EntityTypes.CLUSTER_PROPERTY_TYPE.equals(entityInfoEntry.getKey())) { entityType = "ENVIRONMENT_PROPERTY"; } else { entityType = entityInfoEntry.getKey(); } Class<? extends GatewayEntity> entityClass = entityInfoEntry.getValue().getEntityClass(); final Pair<String, ConfigurationFile.FileType> configFileInfo = EntityUtils.getEntityConfigFileInfo(entityClass); final String environmentType = EntityUtils.getEntityEnvironmentType(entityClass); if (configFileInfo != null && environmentType != null) { final String configFileName = configFileInfo.getLeft() + "." + (configFileInfo.getRight().equals(ConfigurationFile.FileType.JSON_YAML) ? YML_EXTENSION : configFileInfo.getRight().name().toLowerCase()); final File envConfigFile = new File(configFolder, configFileName); if (envConfigFile.exists()) { Map<String, String> entities = loadConfigFromFile(envConfigFile, environmentType); entities.entrySet().forEach(entry -> { environmentValues.put(PREFIX_ENV + environmentType + "." + entry.getKey(), entry.getValue()); if (EntityTypes.TRUSTED_CERT_TYPE.equals(entityType)) { final File certDataFile = new File(configFolder + "/certificates", entry.getKey() + PEM_CERT_FILE_EXTENSION); environmentValues.put(PREFIX_ENV + "CERTIFICATE_FILE" + "." + entry.getKey() + PEM_CERT_FILE_EXTENSION, loadConfigFromFile(certDataFile, "CERTIFICATE_FILE", entry.getKey())); } else if (EntityTypes.PRIVATE_KEY_TYPE.equals(entityType)) { final File privateKeysFolder = new File(configFolder, "privateKeys"); if (privateKeysFolder.exists()) { File privateKeyFile = new File(privateKeysFolder, entry.getKey() + P12_CERT_FILE_EXTENSION); if (privateKeyFile.exists()) { environmentValues.put(PREFIX_ENV + "PRIVATE_KEY_FILE." + entry.getKey() + P12_CERT_FILE_EXTENSION, loadConfigFromFile(privateKeyFile, "PRIVATE_KEY_FILE", entry.getKey())); } } } }); } } }); return environmentValues; } @Inject  EnvironmentConfigurationUtils(JsonTools jsonTools, EntityLoaderRegistry entityLoaderRegistry,
                                  JsonFileUtils jsonFileUtils, final EntityTypeRegistry entityTypeRegistry); }
EnvironmentConfigurationUtils { public Map<String, String> loadConfigFolder(final File configFolder) { final Map<String, String> environmentValues = new LinkedHashMap<>(); final Map<String, EntityUtils.GatewayEntityInfo> entityInfoMap = entityTypeRegistry.getEnvironmentEntityTypes(); entityInfoMap.entrySet().forEach(entityInfoEntry -> { final String entityType; if (EntityTypes.CLUSTER_PROPERTY_TYPE.equals(entityInfoEntry.getKey())) { entityType = "ENVIRONMENT_PROPERTY"; } else { entityType = entityInfoEntry.getKey(); } Class<? extends GatewayEntity> entityClass = entityInfoEntry.getValue().getEntityClass(); final Pair<String, ConfigurationFile.FileType> configFileInfo = EntityUtils.getEntityConfigFileInfo(entityClass); final String environmentType = EntityUtils.getEntityEnvironmentType(entityClass); if (configFileInfo != null && environmentType != null) { final String configFileName = configFileInfo.getLeft() + "." + (configFileInfo.getRight().equals(ConfigurationFile.FileType.JSON_YAML) ? YML_EXTENSION : configFileInfo.getRight().name().toLowerCase()); final File envConfigFile = new File(configFolder, configFileName); if (envConfigFile.exists()) { Map<String, String> entities = loadConfigFromFile(envConfigFile, environmentType); entities.entrySet().forEach(entry -> { environmentValues.put(PREFIX_ENV + environmentType + "." + entry.getKey(), entry.getValue()); if (EntityTypes.TRUSTED_CERT_TYPE.equals(entityType)) { final File certDataFile = new File(configFolder + "/certificates", entry.getKey() + PEM_CERT_FILE_EXTENSION); environmentValues.put(PREFIX_ENV + "CERTIFICATE_FILE" + "." + entry.getKey() + PEM_CERT_FILE_EXTENSION, loadConfigFromFile(certDataFile, "CERTIFICATE_FILE", entry.getKey())); } else if (EntityTypes.PRIVATE_KEY_TYPE.equals(entityType)) { final File privateKeysFolder = new File(configFolder, "privateKeys"); if (privateKeysFolder.exists()) { File privateKeyFile = new File(privateKeysFolder, entry.getKey() + P12_CERT_FILE_EXTENSION); if (privateKeyFile.exists()) { environmentValues.put(PREFIX_ENV + "PRIVATE_KEY_FILE." + entry.getKey() + P12_CERT_FILE_EXTENSION, loadConfigFromFile(privateKeyFile, "PRIVATE_KEY_FILE", entry.getKey())); } } } }); } } }); return environmentValues; } @Inject  EnvironmentConfigurationUtils(JsonTools jsonTools, EntityLoaderRegistry entityLoaderRegistry,
                                  JsonFileUtils jsonFileUtils, final EntityTypeRegistry entityTypeRegistry); @SuppressWarnings("unchecked") Map<String, String> parseEnvironmentValues(Map providedEnvironmentValues); Pair<String, Map<String, String>> parseBundleMetadata(File metaDataFile, File configFolder); Map<String, String> loadConfigFolder(final File configFolder); @NotNull String loadConfigFromFile(File configFile, String entityType, String entityName); @NotNull Map<String, String> loadConfigFromFile(File configFile, String entityType); static String tryInferContentTypeFromValue(final String value); static DependentBundle generateDependentEnvBundleFromProject(final ProjectInfo projectInfo); static String extractEntityName(final String entityName); }
EnvironmentConfigurationUtils { public Map<String, String> loadConfigFolder(final File configFolder) { final Map<String, String> environmentValues = new LinkedHashMap<>(); final Map<String, EntityUtils.GatewayEntityInfo> entityInfoMap = entityTypeRegistry.getEnvironmentEntityTypes(); entityInfoMap.entrySet().forEach(entityInfoEntry -> { final String entityType; if (EntityTypes.CLUSTER_PROPERTY_TYPE.equals(entityInfoEntry.getKey())) { entityType = "ENVIRONMENT_PROPERTY"; } else { entityType = entityInfoEntry.getKey(); } Class<? extends GatewayEntity> entityClass = entityInfoEntry.getValue().getEntityClass(); final Pair<String, ConfigurationFile.FileType> configFileInfo = EntityUtils.getEntityConfigFileInfo(entityClass); final String environmentType = EntityUtils.getEntityEnvironmentType(entityClass); if (configFileInfo != null && environmentType != null) { final String configFileName = configFileInfo.getLeft() + "." + (configFileInfo.getRight().equals(ConfigurationFile.FileType.JSON_YAML) ? YML_EXTENSION : configFileInfo.getRight().name().toLowerCase()); final File envConfigFile = new File(configFolder, configFileName); if (envConfigFile.exists()) { Map<String, String> entities = loadConfigFromFile(envConfigFile, environmentType); entities.entrySet().forEach(entry -> { environmentValues.put(PREFIX_ENV + environmentType + "." + entry.getKey(), entry.getValue()); if (EntityTypes.TRUSTED_CERT_TYPE.equals(entityType)) { final File certDataFile = new File(configFolder + "/certificates", entry.getKey() + PEM_CERT_FILE_EXTENSION); environmentValues.put(PREFIX_ENV + "CERTIFICATE_FILE" + "." + entry.getKey() + PEM_CERT_FILE_EXTENSION, loadConfigFromFile(certDataFile, "CERTIFICATE_FILE", entry.getKey())); } else if (EntityTypes.PRIVATE_KEY_TYPE.equals(entityType)) { final File privateKeysFolder = new File(configFolder, "privateKeys"); if (privateKeysFolder.exists()) { File privateKeyFile = new File(privateKeysFolder, entry.getKey() + P12_CERT_FILE_EXTENSION); if (privateKeyFile.exists()) { environmentValues.put(PREFIX_ENV + "PRIVATE_KEY_FILE." + entry.getKey() + P12_CERT_FILE_EXTENSION, loadConfigFromFile(privateKeyFile, "PRIVATE_KEY_FILE", entry.getKey())); } } } }); } } }); return environmentValues; } @Inject  EnvironmentConfigurationUtils(JsonTools jsonTools, EntityLoaderRegistry entityLoaderRegistry,
                                  JsonFileUtils jsonFileUtils, final EntityTypeRegistry entityTypeRegistry); @SuppressWarnings("unchecked") Map<String, String> parseEnvironmentValues(Map providedEnvironmentValues); Pair<String, Map<String, String>> parseBundleMetadata(File metaDataFile, File configFolder); Map<String, String> loadConfigFolder(final File configFolder); @NotNull String loadConfigFromFile(File configFile, String entityType, String entityName); @NotNull Map<String, String> loadConfigFromFile(File configFile, String entityType); static String tryInferContentTypeFromValue(final String value); static DependentBundle generateDependentEnvBundleFromProject(final ProjectInfo projectInfo); static String extractEntityName(final String entityName);  }