-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into top-hits-fields
- Loading branch information
Showing
393 changed files
with
11,359 additions
and
2,543 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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
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
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
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
18 changes: 18 additions & 0 deletions
18
src/core/server/elasticsearch/deprecations/deprecation_provider.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,18 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { RegisterDeprecationsConfig } from '../../deprecations'; | ||
import { getScriptingDisabledDeprecations } from './scripting_disabled_deprecation'; | ||
|
||
export const getElasticsearchDeprecationsProvider = (): RegisterDeprecationsConfig => { | ||
return { | ||
getDeprecations: async (context) => { | ||
return [...(await getScriptingDisabledDeprecations({ esClient: context.esClient }))]; | ||
}, | ||
}; | ||
}; |
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,9 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export { getElasticsearchDeprecationsProvider } from './deprecation_provider'; |
99 changes: 99 additions & 0 deletions
99
src/core/server/elasticsearch/deprecations/is_scripting_disabled.test.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,99 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { estypes } from '@elastic/elasticsearch'; | ||
import { elasticsearchServiceMock } from '../../elasticsearch/elasticsearch_service.mock'; | ||
import { isInlineScriptingDisabled } from './is_scripting_disabled'; | ||
|
||
describe('isInlineScriptingDisabled', () => { | ||
let client: ReturnType<typeof elasticsearchServiceMock.createElasticsearchClient>; | ||
|
||
beforeEach(() => { | ||
client = elasticsearchServiceMock.createElasticsearchClient(); | ||
}); | ||
|
||
const mockSettingsValue = (settings: estypes.ClusterGetSettingsResponse) => { | ||
client.cluster.getSettings.mockReturnValue( | ||
elasticsearchServiceMock.createSuccessTransportRequestPromise(settings) | ||
); | ||
}; | ||
|
||
it('returns `false` if all settings are empty', async () => { | ||
mockSettingsValue({ | ||
transient: {}, | ||
persistent: {}, | ||
defaults: {}, | ||
}); | ||
|
||
expect(await isInlineScriptingDisabled({ client })).toEqual(false); | ||
}); | ||
|
||
it('returns `false` if `defaults.script.allowed_types` is `inline`', async () => { | ||
mockSettingsValue({ | ||
transient: {}, | ||
persistent: {}, | ||
defaults: { | ||
'script.allowed_types': ['inline'], | ||
}, | ||
}); | ||
|
||
expect(await isInlineScriptingDisabled({ client })).toEqual(false); | ||
}); | ||
|
||
it('returns `true` if `defaults.script.allowed_types` is `none`', async () => { | ||
mockSettingsValue({ | ||
transient: {}, | ||
persistent: {}, | ||
defaults: { | ||
'script.allowed_types': ['none'], | ||
}, | ||
}); | ||
|
||
expect(await isInlineScriptingDisabled({ client })).toEqual(true); | ||
}); | ||
|
||
it('returns `true` if `defaults.script.allowed_types` is `stored`', async () => { | ||
mockSettingsValue({ | ||
transient: {}, | ||
persistent: {}, | ||
defaults: { | ||
'script.allowed_types': ['stored'], | ||
}, | ||
}); | ||
|
||
expect(await isInlineScriptingDisabled({ client })).toEqual(true); | ||
}); | ||
|
||
it('respect the persistent->defaults priority', async () => { | ||
mockSettingsValue({ | ||
transient: {}, | ||
persistent: { | ||
'script.allowed_types': ['inline'], | ||
}, | ||
defaults: { | ||
'script.allowed_types': ['stored'], | ||
}, | ||
}); | ||
|
||
expect(await isInlineScriptingDisabled({ client })).toEqual(false); | ||
}); | ||
|
||
it('respect the transient->persistent priority', async () => { | ||
mockSettingsValue({ | ||
transient: { | ||
'script.allowed_types': ['stored'], | ||
}, | ||
persistent: { | ||
'script.allowed_types': ['inline'], | ||
}, | ||
defaults: {}, | ||
}); | ||
|
||
expect(await isInlineScriptingDisabled({ client })).toEqual(true); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
src/core/server/elasticsearch/deprecations/is_scripting_disabled.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,34 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { ElasticsearchClient } from '../../elasticsearch'; | ||
|
||
const scriptAllowedTypesKey = 'script.allowed_types'; | ||
|
||
export const isInlineScriptingDisabled = async ({ | ||
client, | ||
}: { | ||
client: ElasticsearchClient; | ||
}): Promise<boolean> => { | ||
const { body: settings } = await client.cluster.getSettings({ | ||
include_defaults: true, | ||
flat_settings: true, | ||
}); | ||
|
||
// priority: transient -> persistent -> default | ||
const scriptAllowedTypes: string[] = | ||
settings.transient[scriptAllowedTypesKey] ?? | ||
settings.persistent[scriptAllowedTypesKey] ?? | ||
settings.defaults![scriptAllowedTypesKey] ?? | ||
[]; | ||
|
||
// when unspecified, the setting as a default `[]` value that means that both scriptings are allowed. | ||
const scriptAllowed = scriptAllowedTypes.length === 0 || scriptAllowedTypes.includes('inline'); | ||
|
||
return !scriptAllowed; | ||
}; |
12 changes: 12 additions & 0 deletions
12
src/core/server/elasticsearch/deprecations/scripting_disabled_deprecation.test.mocks.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,12 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export const isInlineScriptingDisabledMock = jest.fn(); | ||
jest.doMock('./is_scripting_disabled', () => ({ | ||
isInlineScriptingDisabled: isInlineScriptingDisabledMock, | ||
})); |
Oops, something went wrong.