Class DataSourceConfiguration
java.lang.Object
org.elasticsearch.xpack.esql.datasources.spi.DataSourceConfiguration
- Direct Known Subclasses:
FileDataSourceConfiguration
Base class for datasource configurations. Handles map-backed storage, unknown field
rejection, and toStoredSettings(). Subclasses provide cross-field validation via
validate(ValidationException).-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDeprecation-logger key prefix for a deprecatedauthvalue; the deprecated value name is appended to form the per-alias key (e.g.static final StringDeprecation-warning message template emitted when a deprecatedauthvalue alias is canonicalized on parse. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDataSourceConfiguration(Map<String, Object> raw, Map<String, DataSourceConfigDefinition> fieldDefs) Parses, normalizes, and validates raw settings from a REST request or CRUD layer.protectedDataSourceConfiguration(Map<String, Object> raw, Map<String, DataSourceConfigDefinition> fieldDefs, Set<String> preexistingSecretKeys) LikeDataSourceConfiguration(Map, Map), but for a PUT-as-update: a secret field omitted fromrawis still treated as present (seehasStoredSecret(java.lang.String)) if its name is inpreexistingSecretKeys, so credential-completeness checks pass when the caller intends to keep the existing value. -
Method Summary
Modifier and TypeMethodDescriptionbuildRawMap(Object... fieldValuePairs) Builds a raw settings map from alternating field/value pairs, skipping nulls.booleanprotected static <T> Configured<T> filterAndConstruct(Map<String, Object> raw, Map<String, DataSourceConfigDefinition> fieldDefs, Function<Map<String, Object>, T> constructor) Filtersrawto keys infieldDefsviafilterKnown(java.util.Map<java.lang.String, java.lang.Object>, java.util.Map<java.lang.String, org.elasticsearch.xpack.esql.datasources.spi.DataSourceConfigDefinition>), then constructs a configuration from the kept entries (ornullif none kept).protected static Configured<Map<String, Object>> filterKnown(Map<String, Object> raw, Map<String, DataSourceConfigDefinition> fieldDefs) Returns a copy ofrawcontaining only entries whose key is infieldDefs, paired with the set of keys that were kept.Gets a setting value as a string.protected booleanTrue if any field marked secret has a value set in this request specifically, excluding any preexisting secret carried forward from a stored value.protected booleanTrue if any field marked secret has a value set, or a preexisting one carries forward (seehasStoredSecret(java.lang.String)).booleanReturns true if any field marked as federated identity (aka keyless auth) has a value set.inthashCode()protected booleanhasStoredSecret(String key) True if the named secret field has a value set in this request, or carries forward from a preexisting stored value on a PUT-as-update.protected voidSubclass hook to canonicalize parsed values before they are frozen — e.g.toMap()Returns the internal values map.Returns validated settings as a map from field name toDataSourceSetting.protected abstract voidvalidate(ValidationException errors) Cross-field validation.
-
Field Details
-
DEPRECATED_AUTH_MESSAGE
Deprecation-warning message template emitted when a deprecatedauthvalue alias is canonicalized on parse. The two{}placeholders are the deprecated value and its canonical replacement, in that order. Shared by everynormalize()that canonicalizes anauthalias so the emitted string stays byte-identical across datasource types (a serverless test filters on it).- See Also:
-
DEPRECATED_AUTH_LOG_KEY_PREFIX
Deprecation-logger key prefix for a deprecatedauthvalue; the deprecated value name is appended to form the per-alias key (e.g.esql_datasource_auth_none). Shared so everynormalize()keys the warning identically.- See Also:
-
-
Constructor Details
-
DataSourceConfiguration
protected DataSourceConfiguration(Map<String, Object> raw, Map<String, DataSourceConfigDefinition> fieldDefs) Parses, normalizes, and validates raw settings from a REST request or CRUD layer. Rejects unknown fields, then calls subclassvalidate(ValidationException)for cross-field checks. Values preserve their original types (String, Integer, Boolean, etc.) for non-lossy round-trips. Fields markedcaseInsensitiveare automatically lowercased on input. All validation errors are accumulated and thrown together.Note:
validate()is a virtual call during base construction. This is safe because subclasses must not add instance fields — all state is accessed viaget(java.lang.String)from the already-populated base class. Subclass constructors should be private.- Parameters:
raw- the raw settings map from the REST requestfieldDefs- the field definitions- Throws:
ValidationException- if any validation errors are found
-
DataSourceConfiguration
protected DataSourceConfiguration(Map<String, Object> raw, Map<String, DataSourceConfigDefinition> fieldDefs, Set<String> preexistingSecretKeys) LikeDataSourceConfiguration(Map, Map), but for a PUT-as-update: a secret field omitted fromrawis still treated as present (seehasStoredSecret(java.lang.String)) if its name is inpreexistingSecretKeys, so credential-completeness checks pass when the caller intends to keep the existing value. The caller excludes any key the request explicitly clears (JSONnull).- Parameters:
preexistingSecretKeys- secret field names already stored, empty for a create
-
-
Method Details
-
normalize
Subclass hook to canonicalize parsed values before they are frozen — e.g. mapping a deprecated enum alias to its current value so the stored configuration (and every later read) holds the canonical form. Runs after unknown-field rejection and case-insensitive lowering, beforevalidate(org.elasticsearch.common.ValidationException). The default is a no-op. Likevalidate(org.elasticsearch.common.ValidationException), this is a virtual call during construction, so overrides must touch only the supplied map and static data, never instance fields. -
validate
Cross-field validation. Accumulate errors into the provided exception. -
hasAnySecretValue
protected boolean hasAnySecretValue()True if any field marked secret has a value set, or a preexisting one carries forward (seehasStoredSecret(java.lang.String)). -
hasAnyExplicitSecretValue
protected boolean hasAnyExplicitSecretValue()True if any field marked secret has a value set in this request specifically, excluding any preexisting secret carried forward from a stored value. Use this to distinguish "this request supplied credentials" from "credentials came from the existing entry" in a conflict message — e.g. rejectingauth=anonymousbecause a stored secret wasn't cleared shouldn't say the request supplied one. -
hasStoredSecret
True if the named secret field has a value set in this request, or carries forward from a preexisting stored value on a PUT-as-update. Use this, notStrings.hasText(get(key)), inhasCredentials()/credential-completeness checks so an update that omits an already-stored secret still satisfies them. -
hasFederatedAuth
public boolean hasFederatedAuth()Returns true if any field marked as federated identity (aka keyless auth) has a value set. Null values are already excluded. -
filterKnown
protected static Configured<Map<String,Object>> filterKnown(Map<String, Object> raw, Map<String, DataSourceConfigDefinition> fieldDefs) Returns a copy ofrawcontaining only entries whose key is infieldDefs, paired with the set of keys that were kept. Used at query time where a query-time configuration map carries a mix of storage and format options; the storage plugin must ignore keys it does not own rather than reject them as unknown. Returnsnull/empty unchanged.Dropped keys are logged at
DEBUGso a user who misspells e.g.accoutcan find out why the storage config came back with defaults. Only key names are logged — values are never emitted, since this method is unaware of which keys are secrets. Format keys (likeheader_row) will appear here too, which is expected. -
filterAndConstruct
protected static <T> Configured<T> filterAndConstruct(Map<String, Object> raw, Map<String, DataSourceConfigDefinition> fieldDefs, Function<Map<String, Object>, T> constructor) Filtersrawto keys infieldDefsviafilterKnown(java.util.Map<java.lang.String, java.lang.Object>, java.util.Map<java.lang.String, org.elasticsearch.xpack.esql.datasources.spi.DataSourceConfigDefinition>), then constructs a configuration from the kept entries (ornullif none kept). Pairs the result with the consumed-keys set. Use from each subclass'sfromQueryConfigto eliminate the filter-construct-pair pipeline boilerplate. -
buildRawMap
Builds a raw settings map from alternating field/value pairs, skipping nulls. Returns null if all values are null. Used byfromFields()factory methods. -
toMap
Returns the internal values map. Normalized, no nulls, types preserved. -
get
Gets a setting value as a string. ReturnstoString()of the stored value, or null. -
toStoredSettings
Returns validated settings as a map from field name toDataSourceSetting. -
equals
-
hashCode
public int hashCode()
-