From 264c2db10cf3f7adf6cf604bfe94cc14ddc448a0 Mon Sep 17 00:00:00 2001 From: pgayvallet Date: Sat, 14 Oct 2023 23:59:17 +0200 Subject: [PATCH] moar --- .../server/saved_objects/ensure_authorized.ts | 5 ++++- .../spaces/secure_spaces_client_wrapper.ts | 14 ++++++++----- .../security_usage_collector.ts | 8 +++---- .../common/utils/sourcerer.ts | 17 ++++++++++----- .../lib/detection_engine/routes/utils.ts | 4 +++- .../aggregations/execution_results/index.ts | 8 +++---- .../rule_types/eql/wrap_sequences_factory.ts | 13 ++++++------ .../timeline/saved_object/timelines/index.ts | 17 +++++++-------- .../factory/risk_score/kpi/index.ts | 8 +++---- .../factory/users/all/index.ts | 12 +++++------ .../endpoint/services/metering_service.ts | 3 ++- .../capabilities/capabilities_switcher.ts | 13 ++++++++---- .../server/connector_types/jira/service.ts | 21 +++++++++---------- .../connector_types/lib/servicenow/utils.ts | 8 +++---- .../connector_types/servicenow_itom/api.ts | 13 ++++++------ 15 files changed, 90 insertions(+), 74 deletions(-) diff --git a/x-pack/plugins/security/server/saved_objects/ensure_authorized.ts b/x-pack/plugins/security/server/saved_objects/ensure_authorized.ts index e945848d71105..770c2816b4e4d 100644 --- a/x-pack/plugins/security/server/saved_objects/ensure_authorized.ts +++ b/x-pack/plugins/security/server/saved_objects/ensure_authorized.ts @@ -104,7 +104,10 @@ export async function ensureAuthorized( // Neither fully nor partially authorized. Bail with error. const uniqueUnauthorizedPrivileges = [...missingPrivileges.entries()].reduce( - (acc, [, privilegeSet]) => new Set([...acc, ...privilegeSet]), + (acc, [, privilegeSet]) => { + privilegeSet.forEach(acc.add); + return acc; + }, new Set() ); const targetTypesAndActions = [...uniqueUnauthorizedPrivileges] diff --git a/x-pack/plugins/security/server/spaces/secure_spaces_client_wrapper.ts b/x-pack/plugins/security/server/spaces/secure_spaces_client_wrapper.ts index 18c6ae824584c..1e9e25b6b800d 100644 --- a/x-pack/plugins/security/server/spaces/secure_spaces_client_wrapper.ts +++ b/x-pack/plugins/security/server/spaces/secure_spaces_client_wrapper.ts @@ -81,10 +81,13 @@ export class SecureSpacesClientWrapper implements ISpacesClient { // Collect all privileges which need to be checked const allPrivileges = Object.entries(PURPOSE_PRIVILEGE_MAP).reduce( - (acc, [getSpacesPurpose, privilegeFactory]) => - !includeAuthorizedPurposes && getSpacesPurpose !== purpose - ? acc - : { ...acc, [getSpacesPurpose]: privilegeFactory(this.authorization) }, + (acc, [getSpacesPurpose, privilegeFactory]) => { + if (!includeAuthorizedPurposes && getSpacesPurpose !== purpose) { + return acc; + } + acc[getSpacesPurpose as GetAllSpacesPurpose] = privilegeFactory(this.authorization); + return acc; + }, {} as Record ); @@ -117,7 +120,8 @@ export class SecureSpacesClientWrapper implements ISpacesClient { const requiredActions = privilegeFactory(this.authorization); const hasAllRequired = checkHasAllRequired(space, requiredActions); hasAnyAuthorization = hasAnyAuthorization || hasAllRequired; - return { ...acc, [purposeKey]: hasAllRequired }; + acc[purposeKey as GetAllSpacesPurpose] = hasAllRequired; + return acc; }, {} as Record ); diff --git a/x-pack/plugins/security/server/usage_collector/security_usage_collector.ts b/x-pack/plugins/security/server/usage_collector/security_usage_collector.ts index f73ac0bbb25a3..e713a4d0d171b 100644 --- a/x-pack/plugins/security/server/usage_collector/security_usage_collector.ts +++ b/x-pack/plugins/security/server/usage_collector/security_usage_collector.ts @@ -161,10 +161,10 @@ export function registerSecurityUsageCollector({ usageCollection, config, licens const authProviderCount = config.authc.sortedProviders.length; const enabledAuthProviders = [ ...new Set( - config.authc.sortedProviders.reduce( - (acc, provider) => [...acc, provider.type], - [] as string[] - ) + config.authc.sortedProviders.reduce((acc, provider) => { + acc.push(provider.type); + return acc; + }, [] as string[]) ), ]; const accessAgreementEnabled = diff --git a/x-pack/plugins/security_solution/common/utils/sourcerer.ts b/x-pack/plugins/security_solution/common/utils/sourcerer.ts index cb58c0ecf1e05..a47193003ef88 100644 --- a/x-pack/plugins/security_solution/common/utils/sourcerer.ts +++ b/x-pack/plugins/security_solution/common/utils/sourcerer.ts @@ -6,10 +6,14 @@ */ export const sortWithExcludesAtEnd = (indices: string[]) => { const allSorted = indices.reduce( - (acc: { includes: string[]; excludes: string[] }, index) => - index.trim().startsWith('-') - ? { includes: acc.includes, excludes: [...acc.excludes, index] } - : { includes: [...acc.includes, index], excludes: acc.excludes }, + (acc: { includes: string[]; excludes: string[] }, index) => { + if (index.trim().startsWith('-')) { + acc.excludes.push(index); + } else { + acc.includes.push(index); + } + return acc; + }, { includes: [], excludes: [] } ); return [...allSorted.includes.sort(), ...allSorted.excludes.sort()]; @@ -18,6 +22,9 @@ export const sortWithExcludesAtEnd = (indices: string[]) => { export const ensurePatternFormat = (patternList: string[]): string[] => sortWithExcludesAtEnd([ ...new Set( - patternList.reduce((acc: string[], pattern: string) => [...pattern.split(','), ...acc], []) + patternList.reduce((acc: string[], pattern: string) => { + acc.unshift(...pattern.split(',')); + return acc; + }, []) ), ]); diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/utils.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/utils.ts index a200afdd34199..597ca7ee4d4d2 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/utils.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/utils.ts @@ -20,6 +20,7 @@ export interface OutputError { message: string; statusCode: number; } + export interface BulkError { // Id can be single id or stringified ids. id?: string; @@ -193,6 +194,7 @@ export const convertToSnakeCase = >( } return Object.keys(obj).reduce((acc, item) => { const newKey = snakeCase(item); - return { ...acc, [newKey]: obj[item] }; + (acc as Record)[newKey] = obj[item]; + return acc; }, {}); }; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_monitoring/logic/rule_execution_log/event_log/aggregations/execution_results/index.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_monitoring/logic/rule_execution_log/event_log/aggregations/execution_results/index.ts index e4e394fd16149..348bc15ed41d0 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_monitoring/logic/rule_execution_log/event_log/aggregations/execution_results/index.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_monitoring/logic/rule_execution_log/event_log/aggregations/execution_results/index.ts @@ -362,10 +362,10 @@ export const formatSortForBucketSort = (sort: estypes.Sort) => { */ export const formatSortForTermsSort = (sort: estypes.Sort) => { return (sort as estypes.SortCombinations[]).map((s) => - Object.keys(s).reduce( - (acc, curr) => ({ ...acc, [SORT_FIELD_TO_AGG_MAPPING[curr]]: get(s, `${curr}.order`) }), - {} - ) + Object.keys(s).reduce((acc, curr) => { + (acc as Record)[SORT_FIELD_TO_AGG_MAPPING[curr]] = get(s, `${curr}.order`); + return acc; + }, {}) ); }; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_types/eql/wrap_sequences_factory.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_types/eql/wrap_sequences_factory.ts index e21f09438e8b8..204243ab40da1 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_types/eql/wrap_sequences_factory.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_types/eql/wrap_sequences_factory.ts @@ -36,9 +36,8 @@ export const wrapSequencesFactory = publicBaseUrl: string | undefined; }): WrapSequences => (sequences, buildReasonMessage) => - sequences.reduce( - (acc: Array>, sequence) => [ - ...acc, + sequences.reduce((acc: Array>, sequence) => { + acc.push( ...buildAlertGroupFromSequence( ruleExecutionLogger, sequence, @@ -49,7 +48,7 @@ export const wrapSequencesFactory = indicesToQuery, alertTimestampOverride, publicBaseUrl - ), - ], - [] - ); + ) + ); + return acc; + }, []); diff --git a/x-pack/plugins/security_solution/server/lib/timeline/saved_object/timelines/index.ts b/x-pack/plugins/security_solution/server/lib/timeline/saved_object/timelines/index.ts index e966a2d9f9f32..2494271a038a2 100644 --- a/x-pack/plugins/security_solution/server/lib/timeline/saved_object/timelines/index.ts +++ b/x-pack/plugins/security_solution/server/lib/timeline/saved_object/timelines/index.ts @@ -725,10 +725,10 @@ export const getSelectedTimelines = async ( const savedObjects = await Promise.resolve( savedObjectsClient.bulkGet( - (exportedIds ?? []).reduce( - (acc, timelineId) => [...acc, { id: timelineId, type: timelineSavedObjectType }], - [] as Array<{ id: string; type: string }> - ) + (exportedIds ?? []).reduce((acc, timelineId) => { + acc.push({ id: timelineId, type: timelineSavedObjectType }); + return acc; + }, [] as Array<{ id: string; type: string }>) ) ); @@ -740,13 +740,12 @@ export const getSelectedTimelines = async ( if (savedObject.error == null) { const populatedTimeline = timelineFieldsMigrator.populateFieldsFromReferences(savedObject); - return { - errors: acc.errors, - timelines: [...acc.timelines, convertSavedObjectToSavedTimeline(populatedTimeline)], - }; + acc.timelines.push(convertSavedObjectToSavedTimeline(populatedTimeline)); + return acc; } - return { errors: [...acc.errors, savedObject.error], timelines: acc.timelines }; + acc.errors.push(savedObject.error); + return acc; }, { timelines: [] as TimelineSavedObject[], diff --git a/x-pack/plugins/security_solution/server/search_strategy/security_solution/factory/risk_score/kpi/index.ts b/x-pack/plugins/security_solution/server/search_strategy/security_solution/factory/risk_score/kpi/index.ts index 333b59bc15c04..eee0e812306ba 100644 --- a/x-pack/plugins/security_solution/server/search_strategy/security_solution/factory/risk_score/kpi/index.ts +++ b/x-pack/plugins/security_solution/server/search_strategy/security_solution/factory/risk_score/kpi/index.ts @@ -36,10 +36,10 @@ export const kpiRiskScore: SecuritySolutionFactory = { const riskBuckets = getOr([], 'aggregations.risk.buckets', response.rawResponse); const result: Record = riskBuckets.reduce( - (cummulative: Record, bucket: AggBucket) => ({ - ...cummulative, - [bucket.key]: getOr(0, 'unique_entries.value', bucket), - }), + (cummulative: Record, bucket: AggBucket) => { + cummulative[bucket.key] = getOr(0, 'unique_entries.value', bucket); + return cummulative; + }, {} ); diff --git a/x-pack/plugins/security_solution/server/search_strategy/security_solution/factory/users/all/index.ts b/x-pack/plugins/security_solution/server/search_strategy/security_solution/factory/users/all/index.ts index a8eab4d4b92db..8ee4d6d04f15f 100644 --- a/x-pack/plugins/security_solution/server/search_strategy/security_solution/factory/users/all/index.ts +++ b/x-pack/plugins/security_solution/server/search_strategy/security_solution/factory/users/all/index.ts @@ -110,13 +110,11 @@ async function enhanceEdges( isNewRiskScoreModuleInstalled ); const usersRiskByUserName: Record | undefined = - userRiskData?.hits.hits.reduce( - (acc, hit) => ({ - ...acc, - [hit._source?.user.name ?? '']: hit._source?.user?.risk?.calculated_level, - }), - {} - ); + userRiskData?.hits.hits.reduce((acc, hit) => { + (acc as Record)[hit._source?.user.name ?? ''] = + hit._source?.user?.risk?.calculated_level; + return acc; + }, {}); return usersRiskByUserName ? edges.map(({ name, lastSeen, domain }) => ({ diff --git a/x-pack/plugins/security_solution_serverless/server/endpoint/services/metering_service.ts b/x-pack/plugins/security_solution_serverless/server/endpoint/services/metering_service.ts index 765ffcfeb76a4..0135672194083 100644 --- a/x-pack/plugins/security_solution_serverless/server/endpoint/services/metering_service.ts +++ b/x-pack/plugins/security_solution_serverless/server/endpoint/services/metering_service.ts @@ -61,7 +61,8 @@ export class EndpointMeteringService { projectId: cloudSetup?.serverless?.projectId, }); - return [...acc, record]; + acc.push(record); + return acc; }, [] as UsageRecord[]); }; diff --git a/x-pack/plugins/spaces/server/capabilities/capabilities_switcher.ts b/x-pack/plugins/spaces/server/capabilities/capabilities_switcher.ts index e3183185022f6..b5d9be07d91af 100644 --- a/x-pack/plugins/spaces/server/capabilities/capabilities_switcher.ts +++ b/x-pack/plugins/spaces/server/capabilities/capabilities_switcher.ts @@ -63,14 +63,19 @@ function toggleDisabledFeatures( ) { const disabledFeatureKeys = activeSpace.disabledFeatures; - const [enabledFeatures, disabledFeatures] = features.reduce( + const { enabledFeatures, disabledFeatures } = features.reduce( (acc, feature) => { if (disabledFeatureKeys.includes(feature.id)) { - return [acc[0], [...acc[1], feature]]; + acc.disabledFeatures.push(feature); + } else { + acc.enabledFeatures.push(feature); } - return [[...acc[0], feature], acc[1]]; + return acc; }, - [[], []] as [KibanaFeature[], KibanaFeature[]] + { enabledFeatures: [], disabledFeatures: [] } as { + enabledFeatures: KibanaFeature[]; + disabledFeatures: KibanaFeature[]; + } ); const navLinks = capabilities.navLinks; diff --git a/x-pack/plugins/stack_connectors/server/connector_types/jira/service.ts b/x-pack/plugins/stack_connectors/server/connector_types/jira/service.ts index 771c5f25e92d6..7e742ff578345 100644 --- a/x-pack/plugins/stack_connectors/server/connector_types/jira/service.ts +++ b/x-pack/plugins/stack_connectors/server/connector_types/jira/service.ts @@ -454,10 +454,10 @@ export const createExternalService = ( }); const fields = res.data.values.reduce( - (acc: { [x: string]: {} }, value: { fieldId: string }) => ({ - ...acc, - [value.fieldId]: { ...value }, - }), + (acc: { [x: string]: {} }, value: { fieldId: string }) => { + (acc as Record)[value.fieldId] = { ...value }; + return acc; + }, {} ); return normalizeFields(fields); @@ -484,13 +484,12 @@ export const createExternalService = ( const currentListOfFields = Object.keys(acc); return currentListOfFields.length === 0 ? fieldTypesByIssue - : currentListOfFields.reduce( - (add: GetCommonFieldsResponse, field) => - Object.keys(fieldTypesByIssue).includes(field) - ? { ...add, [field]: acc[field] } - : add, - {} - ); + : currentListOfFields.reduce((add: GetCommonFieldsResponse, field) => { + if (Object.keys(fieldTypesByIssue).includes(field)) { + (add as Record)[field] = acc[field]; + } + return add; + }, {}); }, {}); } catch (error) { // errors that happen here would be thrown in the contained async calls diff --git a/x-pack/plugins/stack_connectors/server/connector_types/lib/servicenow/utils.ts b/x-pack/plugins/stack_connectors/server/connector_types/lib/servicenow/utils.ts index 2e6ba5327ed2b..256b8a97b5e1f 100644 --- a/x-pack/plugins/stack_connectors/server/connector_types/lib/servicenow/utils.ts +++ b/x-pack/plugins/stack_connectors/server/connector_types/lib/servicenow/utils.ts @@ -26,10 +26,10 @@ import * as i18n from './translations'; export const prepareIncident = (useOldApi: boolean, incident: PartialIncident): PartialIncident => useOldApi ? incident - : Object.entries(incident).reduce( - (acc, [key, value]) => ({ ...acc, [`${FIELD_PREFIX}${key}`]: value }), - {} as Incident - ); + : Object.entries(incident).reduce((acc, [key, value]) => { + (acc as Record)[`${FIELD_PREFIX}${key}`] = value; + return acc; + }, {} as Incident); const createErrorMessage = (errorResponse?: ServiceNowError): string => { if (errorResponse == null) { diff --git a/x-pack/plugins/stack_connectors/server/connector_types/servicenow_itom/api.ts b/x-pack/plugins/stack_connectors/server/connector_types/servicenow_itom/api.ts index c68f1d4419eb1..9baec9f877e2c 100644 --- a/x-pack/plugins/stack_connectors/server/connector_types/servicenow_itom/api.ts +++ b/x-pack/plugins/stack_connectors/server/connector_types/servicenow_itom/api.ts @@ -37,13 +37,12 @@ const formatTimeOfEvent = (timeOfEvent: string | null): string | undefined => { const removeNullValues = ( params: ExecutorSubActionAddEventParams ): ExecutorSubActionAddEventParams => - (Object.keys(params) as Array).reduce( - (acc, key) => ({ - ...acc, - ...(params[key] != null ? { [key]: params[key] } : {}), - }), - {} as ExecutorSubActionAddEventParams - ); + (Object.keys(params) as Array).reduce((acc, key) => { + if (params[key] != null) { + (acc as Record)[key] = params[key]; + } + return acc; + }, {} as ExecutorSubActionAddEventParams); export const prepareParams = ( params: ExecutorSubActionAddEventParams