-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SECURITY_SOLUTION][ENDPOINT] Add creation of Trusted Apps Agnostic L…
- Loading branch information
1 parent
5959e3c
commit 8d13393
Showing
3 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
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
77 changes: 77 additions & 0 deletions
77
x-pack/plugins/lists/server/services/exception_lists/create_endpoint_trusted_apps_list.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,77 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { SavedObjectsClientContract } from 'kibana/server'; | ||
import uuid from 'uuid'; | ||
|
||
import { | ||
ENDPOINT_TRUSTED_APPS_LIST_DESCRIPTION, | ||
ENDPOINT_TRUSTED_APPS_LIST_ID, | ||
ENDPOINT_TRUSTED_APPS_LIST_NAME, | ||
} from '../../../common/constants'; | ||
import { ExceptionListSchema, ExceptionListSoSchema, Version } from '../../../common/schemas'; | ||
|
||
import { getSavedObjectType, transformSavedObjectToExceptionList } from './utils'; | ||
|
||
interface CreateEndpointListOptions { | ||
savedObjectsClient: SavedObjectsClientContract; | ||
user: string; | ||
tieBreaker?: string; | ||
version: Version; | ||
} | ||
|
||
/** | ||
* Creates the Endpoint Trusted Apps agnostic list if it does not yet exist | ||
* | ||
* @param savedObjectsClient | ||
* @param user | ||
* @param tieBreaker | ||
* @param version | ||
*/ | ||
export const createEndpointTrustedAppsList = async ({ | ||
savedObjectsClient, | ||
user, | ||
tieBreaker, | ||
version, | ||
}: CreateEndpointListOptions): Promise<ExceptionListSchema | null> => { | ||
const savedObjectType = getSavedObjectType({ namespaceType: 'agnostic' }); | ||
const dateNow = new Date().toISOString(); | ||
try { | ||
const savedObject = await savedObjectsClient.create<ExceptionListSoSchema>( | ||
savedObjectType, | ||
{ | ||
_tags: [], | ||
comments: undefined, | ||
created_at: dateNow, | ||
created_by: user, | ||
description: ENDPOINT_TRUSTED_APPS_LIST_DESCRIPTION, | ||
entries: undefined, | ||
immutable: false, | ||
item_id: undefined, | ||
list_id: ENDPOINT_TRUSTED_APPS_LIST_ID, | ||
list_type: 'list', | ||
meta: undefined, | ||
name: ENDPOINT_TRUSTED_APPS_LIST_NAME, | ||
tags: [], | ||
tie_breaker_id: tieBreaker ?? uuid.v4(), | ||
type: 'endpoint', | ||
updated_by: user, | ||
version, | ||
}, | ||
{ | ||
// We intentionally hard coding the id so that there can only be one Trusted apps list within the space | ||
id: ENDPOINT_TRUSTED_APPS_LIST_ID, | ||
} | ||
); | ||
return transformSavedObjectToExceptionList({ savedObject }); | ||
} catch (err) { | ||
if (savedObjectsClient.errors.isConflictError(err)) { | ||
return null; | ||
} else { | ||
throw err; | ||
} | ||
} | ||
}; |
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