Skip to content

Commit

Permalink
Refactor the download_database_on_pipeline_creation checks (elastic#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
joegallo committed Oct 23, 2024
1 parent 8ea52ff commit 625c441
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,14 @@ private static boolean hasAtLeastOneGeoipProcessor(Map<String, Object> processor
{
final Map<String, Object> processorConfig = (Map<String, Object>) processor.get(GEOIP_TYPE);
if (processorConfig != null) {
return downloadDatabaseOnPipelineCreation(GEOIP_TYPE, processorConfig, null) == downloadDatabaseOnPipelineCreation;
return downloadDatabaseOnPipelineCreation(processorConfig) == downloadDatabaseOnPipelineCreation;
}
}

{
final Map<String, Object> processorConfig = (Map<String, Object>) processor.get(IP_LOCATION_TYPE);
if (processorConfig != null) {
return downloadDatabaseOnPipelineCreation(IP_LOCATION_TYPE, processorConfig, null) == downloadDatabaseOnPipelineCreation;
return downloadDatabaseOnPipelineCreation(processorConfig) == downloadDatabaseOnPipelineCreation;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,8 @@ public Processor create(
boolean ignoreMissing = readBooleanProperty(type, processorTag, config, "ignore_missing", false);
boolean firstOnly = readBooleanProperty(type, processorTag, config, "first_only", true);

// Validating the download_database_on_pipeline_creation even if the result
// is not used directly by the factory.
downloadDatabaseOnPipelineCreation(type, config, processorTag);
// validate (and consume) the download_database_on_pipeline_creation property even though the result is not used by the factory
readBooleanProperty(type, processorTag, config, "download_database_on_pipeline_creation", true);

// noop, should be removed in 9.0
Object value = config.remove("fallback_to_default_databases");
Expand Down Expand Up @@ -319,8 +318,15 @@ public Processor create(
);
}

public static boolean downloadDatabaseOnPipelineCreation(String type, Map<String, Object> config, String processorTag) {
return readBooleanProperty(type, processorTag, config, "download_database_on_pipeline_creation", true);
/**
* Get the value of the "download_database_on_pipeline_creation" property from a processor's config map.
* <p>
* As with the actual property definition, the default value of the property is 'true'. Unlike the actual
* property definition, this method doesn't consume (that is, <code>config.remove</code>) the property from
* the config map.
*/
public static boolean downloadDatabaseOnPipelineCreation(Map<String, Object> config) {
return (boolean) config.getOrDefault("download_database_on_pipeline_creation", true);
}
}

Expand Down

0 comments on commit 625c441

Please sign in to comment.