-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SECURITY SOLUTION] add
enableExperimental
plugin configuration set…
…ting (#94944) * Added new setting (enableExperimental) to plugin configuration * Remove plugin config setting `fleetServerEnabled` and use instead `enableExperimental`
- Loading branch information
1 parent
04e4661
commit e7bb8b7
Showing
4 changed files
with
85 additions
and
4 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
x-pack/plugins/security_solution/common/experimental_features.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export type ExperimentalFeatures = typeof allowedExperimentalValues; | ||
|
||
/** | ||
* A list of allowed values that can be used in `xpack.securitySolution.enableExperimental`. | ||
* This object is then used to validate and parse the value entered. | ||
*/ | ||
const allowedExperimentalValues = Object.freeze({ | ||
fleetServerEnabled: false, | ||
}); | ||
|
||
type ExperimentalConfigKeys = Array<keyof ExperimentalFeatures>; | ||
type Mutable<T> = { -readonly [P in keyof T]: T[P] }; | ||
|
||
const SecuritySolutionInvalidExperimentalValue = class extends Error {}; | ||
const allowedKeys = Object.keys(allowedExperimentalValues) as Readonly<ExperimentalConfigKeys>; | ||
|
||
/** | ||
* Parses the string value used in `xpack.securitySolution.enableExperimental` kibana configuration, | ||
* which should be a string of values delimited by a comma (`,`) | ||
* | ||
* @param configValue | ||
* @throws SecuritySolutionInvalidExperimentalValue | ||
*/ | ||
export const parseExperimentalConfigValue = (configValue: string[]): ExperimentalFeatures => { | ||
const enabledFeatures: Mutable<Partial<ExperimentalFeatures>> = {}; | ||
|
||
for (const value of configValue) { | ||
if (!isValidExperimentalValue(value)) { | ||
throw new SecuritySolutionInvalidExperimentalValue(`[${value}] is not valid.`); | ||
} | ||
|
||
enabledFeatures[value as keyof ExperimentalFeatures] = true; | ||
} | ||
|
||
return { | ||
...allowedExperimentalValues, | ||
...enabledFeatures, | ||
}; | ||
}; | ||
|
||
export const isValidExperimentalValue = (value: string): boolean => { | ||
return allowedKeys.includes(value as keyof ExperimentalFeatures); | ||
}; | ||
|
||
export const getExperimentalAllowedValues = (): string[] => [...allowedKeys]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters