[Fleet] Add keep_enabled flag to preconfiguration to prevent disabling certain inputs (#99656)
* [Fleet] Add keep_enabled flag to prevent disabling inputs * Remove console.log * Fix missing key definition
This commit is contained in:
parent
0b5d323613
commit
b5380697cc
|
@ -21,6 +21,7 @@ export type PackagePolicyConfigRecord = Record<string, PackagePolicyConfigRecord
|
|||
|
||||
export interface NewPackagePolicyInputStream {
|
||||
enabled: boolean;
|
||||
keep_enabled?: boolean;
|
||||
data_stream: {
|
||||
dataset: string;
|
||||
type: string;
|
||||
|
@ -37,6 +38,7 @@ export interface PackagePolicyInputStream extends NewPackagePolicyInputStream {
|
|||
export interface NewPackagePolicyInput {
|
||||
type: string;
|
||||
enabled: boolean;
|
||||
keep_enabled?: boolean;
|
||||
vars?: PackagePolicyConfigRecord;
|
||||
config?: PackagePolicyConfigRecord;
|
||||
streams: NewPackagePolicyInputStream[];
|
||||
|
|
|
@ -120,6 +120,7 @@ export const PackagePolicyInputPanel: React.FunctionComponent<{
|
|||
</EuiFlexGroup>
|
||||
}
|
||||
checked={packagePolicyInput.enabled}
|
||||
disabled={packagePolicyInput.keep_enabled}
|
||||
onChange={(e) => {
|
||||
const enabled = e.target.checked;
|
||||
updatePackagePolicyInput({
|
||||
|
|
|
@ -83,6 +83,7 @@ export const PackagePolicyInputStreamConfig: React.FunctionComponent<{
|
|||
<EuiFlexItem grow={5}>
|
||||
<EuiSwitch
|
||||
label={packageInputStream.title}
|
||||
disabled={packagePolicyInputStream.keep_enabled}
|
||||
checked={packagePolicyInputStream.enabled}
|
||||
onChange={(e) => {
|
||||
const enabled = e.target.checked;
|
||||
|
|
|
@ -390,6 +390,7 @@ describe('Package policy service', () => {
|
|||
{
|
||||
config: {},
|
||||
enabled: true,
|
||||
keep_enabled: true,
|
||||
type: 'endpoint',
|
||||
vars: {
|
||||
dog: {
|
||||
|
@ -428,7 +429,7 @@ describe('Package policy service', () => {
|
|||
const inputsUpdate = [
|
||||
{
|
||||
config: {},
|
||||
enabled: true,
|
||||
enabled: false,
|
||||
type: 'endpoint',
|
||||
vars: {
|
||||
dog: {
|
||||
|
@ -501,6 +502,7 @@ describe('Package policy service', () => {
|
|||
);
|
||||
|
||||
const [modifiedInput] = result.inputs;
|
||||
expect(modifiedInput.enabled).toEqual(true);
|
||||
expect(modifiedInput.vars!.dog.value).toEqual('labrador');
|
||||
expect(modifiedInput.vars!.cat.value).toEqual('siamese');
|
||||
const [modifiedStream] = modifiedInput.streams;
|
||||
|
|
|
@ -614,12 +614,14 @@ function enforceFrozenInputs(oldInputs: PackagePolicyInput[], newInputs: Package
|
|||
|
||||
for (const input of resultInputs) {
|
||||
const oldInput = oldInputs.find((i) => i.type === input.type);
|
||||
if (oldInput?.keep_enabled) input.enabled = oldInput.enabled;
|
||||
if (input.vars && oldInput?.vars) {
|
||||
input.vars = _enforceFrozenVars(oldInput.vars, input.vars);
|
||||
}
|
||||
if (input.streams && oldInput?.streams) {
|
||||
for (const stream of input.streams) {
|
||||
const oldStream = oldInput.streams.find((s) => s.id === stream.id);
|
||||
if (oldStream?.keep_enabled) stream.enabled = oldStream.enabled;
|
||||
if (stream.vars && oldStream?.vars) {
|
||||
stream.vars = _enforceFrozenVars(oldStream.vars, stream.vars);
|
||||
}
|
||||
|
|
|
@ -285,6 +285,8 @@ function overridePackageInputs(
|
|||
}
|
||||
|
||||
if (typeof override.enabled !== 'undefined') originalInput.enabled = override.enabled;
|
||||
if (typeof override.keep_enabled !== 'undefined')
|
||||
originalInput.keep_enabled = override.keep_enabled;
|
||||
|
||||
if (override.vars) {
|
||||
try {
|
||||
|
|
|
@ -46,6 +46,7 @@ const PackagePolicyBaseSchema = {
|
|||
schema.object({
|
||||
type: schema.string(),
|
||||
enabled: schema.boolean(),
|
||||
keep_enabled: schema.maybe(schema.boolean()),
|
||||
vars: schema.maybe(ConfigRecordSchema),
|
||||
config: schema.maybe(
|
||||
schema.recordOf(
|
||||
|
@ -60,6 +61,7 @@ const PackagePolicyBaseSchema = {
|
|||
schema.object({
|
||||
id: schema.maybe(schema.string()), // BWC < 7.11
|
||||
enabled: schema.boolean(),
|
||||
keep_enabled: schema.maybe(schema.boolean()),
|
||||
data_stream: schema.object({ dataset: schema.string(), type: schema.string() }),
|
||||
vars: schema.maybe(ConfigRecordSchema),
|
||||
config: schema.maybe(
|
||||
|
|
|
@ -67,6 +67,7 @@ export const PreconfiguredAgentPoliciesSchema = schema.arrayOf(
|
|||
schema.object({
|
||||
type: schema.string(),
|
||||
enabled: schema.maybe(schema.boolean()),
|
||||
keep_enabled: schema.maybe(schema.boolean()),
|
||||
vars: varsSchema,
|
||||
streams: schema.maybe(
|
||||
schema.arrayOf(
|
||||
|
@ -76,6 +77,7 @@ export const PreconfiguredAgentPoliciesSchema = schema.arrayOf(
|
|||
dataset: schema.string(),
|
||||
}),
|
||||
enabled: schema.maybe(schema.boolean()),
|
||||
keep_enabled: schema.maybe(schema.boolean()),
|
||||
vars: varsSchema,
|
||||
})
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue