Skip to content

Commit

Permalink
fix security solution schema
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed May 18, 2021
1 parent 1dfe1b0 commit 76d5445
Showing 1 changed file with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,39 +87,37 @@ const MacEntrySchema = schema.object({
...CommonEntrySchema,
});

const entriesSchemaOptions = {
minSize: 1,
validate(entries: ConditionEntry[]) {
return (
getDuplicateFields(entries)
.map((field) => `duplicatedEntry.${field}`)
.join(', ') || undefined
);
},
};

/*
* Entry Schema depending on Os type using schema.conditional.
* Entities array schema depending on Os type using schema.conditional.
* If OS === WINDOWS then use Windows schema,
* else if OS === LINUX then use Linux schema,
* else use Mac schema
*
* The validate function checks there is no duplicated entry inside the array
*/
const EntrySchemaDependingOnOS = schema.conditional(
const EntriesSchema = schema.conditional(
schema.siblingRef('os'),
OperatingSystem.WINDOWS,
WindowsEntrySchema,
schema.arrayOf(WindowsEntrySchema, entriesSchemaOptions),
schema.conditional(
schema.siblingRef('os'),
OperatingSystem.LINUX,
LinuxEntrySchema,
MacEntrySchema
schema.arrayOf(LinuxEntrySchema, entriesSchemaOptions),
schema.arrayOf(MacEntrySchema, entriesSchemaOptions)
)
);

/*
* Entities array schema.
* The validate function checks there is no duplicated entry inside the array
*/
const EntriesSchema = schema.arrayOf(EntrySchemaDependingOnOS, {
minSize: 1,
validate(entries: ConditionEntry[]) {
return (
getDuplicateFields(entries)
.map((field) => `duplicatedEntry.${field}`)
.join(', ') || undefined
);
},
});

const getTrustedAppForOsScheme = (forUpdateFlow: boolean = false) =>
schema.object({
name: schema.string({ minLength: 1, maxLength: 256 }),
Expand Down

0 comments on commit 76d5445

Please sign in to comment.