From e8f59a588886f10eb4d37bfd80742a9239190ee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Kopyci=C5=84ski?= Date: Tue, 19 Apr 2022 11:09:32 +0200 Subject: [PATCH] [Osquery] Update eslint config (#129637) --- .eslintrc.js | 14 ++++++++++++++ .../osquery/common/ecs/ecs_fields/extend_map.ts | 1 + x-pack/plugins/osquery/cypress/plugins/index.ts | 1 + x-pack/plugins/osquery/cypress/tasks/login.ts | 2 ++ .../action_results/action_agents_status_bar.tsx | 3 +++ .../osquery/public/agents/agent_grouper.test.ts | 2 ++ .../plugins/osquery/public/agents/agent_grouper.ts | 4 ++++ .../plugins/osquery/public/agents/agents_table.tsx | 3 +++ x-pack/plugins/osquery/public/agents/helpers.ts | 12 ++++++++++++ .../osquery/public/agents/use_agent_details.ts | 1 + .../osquery/public/agents/use_agent_groups.ts | 1 + .../osquery/public/agents/use_osquery_policies.ts | 1 + x-pack/plugins/osquery/public/common/helpers.ts | 1 + .../public/common/hooks/use_breadcrumbs.tsx | 2 ++ .../public/common/hooks/use_discover_link.tsx | 1 + .../public/common/hooks/use_error_toast.tsx | 2 ++ .../public/common/lib/kibana/kibana_react.ts | 1 + .../osquery/public/components/empty_state.tsx | 1 + .../osquery/public/components/main_navigation.tsx | 1 + .../public/components/manage_integration_link.tsx | 1 + x-pack/plugins/osquery/public/editor/index.tsx | 1 + .../osquery/public/editor/osquery_tables.ts | 3 +++ .../public/fleet_integration/config_uploader.tsx | 2 ++ ...azy_osquery_managed_custom_button_extension.tsx | 1 + ...uery_managed_policy_create_import_extension.tsx | 1 + .../lazy_osquery_managed_policy_edit_extension.tsx | 1 + ...uery_managed_policy_create_import_extension.tsx | 2 ++ .../public/fleet_integration/use_fetch_status.tsx | 1 + x-pack/plugins/osquery/public/index.ts | 1 + .../osquery/public/live_queries/form/index.tsx | 3 +++ x-pack/plugins/osquery/public/packs/form/index.tsx | 2 ++ .../osquery/public/packs/form/pack_uploader.tsx | 4 ++++ .../public/packs/form/policy_id_combobox_field.tsx | 1 + .../osquery/public/packs/form/queries_field.tsx | 1 + x-pack/plugins/osquery/public/packs/form/utils.ts | 2 ++ .../public/packs/pack_queries_status_table.tsx | 5 +++++ .../plugins/osquery/public/packs/packs_table.tsx | 1 + .../packs/queries/ecs_mapping_editor_field.tsx | 8 ++++++++ .../queries/platform_checkbox_group_field.tsx | 2 ++ .../public/packs/queries/platforms/helpers.tsx | 2 ++ .../public/packs/queries/platforms/index.tsx | 1 + .../osquery/public/packs/queries/query_flyout.tsx | 1 + .../public/packs/queries/use_pack_query_form.tsx | 4 ++++ .../osquery/public/packs/queries/validations.ts | 1 + .../osquery/public/packs/use_create_pack.ts | 1 + .../osquery/public/packs/use_delete_pack.ts | 1 + .../osquery/public/packs/use_pack_query_errors.ts | 1 + .../osquery/public/packs/use_update_pack.ts | 1 + x-pack/plugins/osquery/public/plugin.ts | 1 + .../osquery/public/results/results_table.tsx | 3 +++ .../public/routes/saved_queries/list/index.tsx | 1 + .../osquery/public/saved_queries/form/index.tsx | 1 + .../saved_queries/form/use_saved_query_form.tsx | 6 ++++++ .../saved_queries/saved_queries_dropdown.tsx | 1 + .../public/saved_queries/use_create_saved_query.ts | 1 + .../shared_components/lazy_osquery_action.tsx | 1 + .../osquery_action/use_is_osquery_available.ts | 1 + .../osquery/server/lib/parse_agent_groups.ts | 6 ++++++ .../osquery/server/lib/telemetry/filters.ts | 3 +++ .../osquery/server/lib/telemetry/receiver.ts | 1 + .../plugins/osquery/server/lib/telemetry/sender.ts | 6 ++++++ .../plugins/osquery/server/lib/telemetry/task.ts | 3 +++ .../osquery/server/lib/telemetry/tasks/packs.ts | 1 + .../server/lib/telemetry/tasks/saved_queries.ts | 1 + .../server/routes/action/create_action_route.ts | 2 ++ .../plugins/osquery/server/routes/asset/utils.ts | 1 + .../server/routes/pack/create_pack_route.ts | 2 ++ .../server/routes/pack/delete_pack_route.ts | 1 + .../osquery/server/routes/pack/find_pack_route.ts | 1 + .../server/routes/pack/update_pack_route.ts | 7 +++++++ x-pack/plugins/osquery/server/routes/pack/utils.ts | 2 ++ .../server/routes/status/create_status_route.ts | 1 + .../osquery/server/routes/usage/recorder.test.ts | 1 + x-pack/plugins/osquery/server/routes/utils.ts | 1 + .../osquery/factory/actions/all/index.ts | 1 + .../osquery/factory/actions/results/index.ts | 1 + .../osquery/factory/agents/index.ts | 1 + .../osquery/factory/results/index.ts | 1 + .../server/search_strategy/osquery/index.ts | 1 + x-pack/plugins/osquery/server/usage/collector.ts | 2 ++ x-pack/plugins/osquery/server/usage/fetchers.ts | 5 +++++ .../plugins/osquery/server/utils/runtime_types.ts | 11 +++++++++++ 82 files changed, 189 insertions(+) diff --git a/.eslintrc.js b/.eslintrc.js index 08af34d24e7f5..3c1c455fc3295 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1452,6 +1452,20 @@ module.exports = { plugins: ['react', '@typescript-eslint'], files: ['x-pack/plugins/osquery/**/*.{js,mjs,ts,tsx}'], rules: { + 'padding-line-between-statements': [ + 'error', + { + blankLine: 'always', + prev: ['block-like'], + next: ['*'], + }, + { + blankLine: 'always', + prev: ['*'], + next: ['return'], + }, + ], + 'padded-blocks': ['error', 'always'], 'arrow-body-style': ['error', 'as-needed'], 'prefer-arrow-callback': 'error', 'no-unused-vars': 'off', diff --git a/x-pack/plugins/osquery/common/ecs/ecs_fields/extend_map.ts b/x-pack/plugins/osquery/common/ecs/ecs_fields/extend_map.ts index 184e6b4f32566..af8c3ded4a1d1 100644 --- a/x-pack/plugins/osquery/common/ecs/ecs_fields/extend_map.ts +++ b/x-pack/plugins/osquery/common/ecs/ecs_fields/extend_map.ts @@ -11,5 +11,6 @@ export const extendMap = ( ): Readonly> => Object.entries(map).reduce>((accum, [key, value]) => { accum[`${path}.${key}`] = `${path}.${value}`; + return accum; }, {}); diff --git a/x-pack/plugins/osquery/cypress/plugins/index.ts b/x-pack/plugins/osquery/cypress/plugins/index.ts index 5c0aa5e4c4cfd..7e135eb15c56e 100644 --- a/x-pack/plugins/osquery/cypress/plugins/index.ts +++ b/x-pack/plugins/osquery/cypress/plugins/index.ts @@ -25,6 +25,7 @@ module.exports = (on: any, config: any) => { // eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-extraneous-dependencies require('@cypress/code-coverage/task')(on, config); + // `on` is used to hook into various events Cypress emits // `config` is the resolved Cypress config return config; diff --git a/x-pack/plugins/osquery/cypress/tasks/login.ts b/x-pack/plugins/osquery/cypress/tasks/login.ts index 9dbdc40a35605..77d53ab470830 100644 --- a/x-pack/plugins/osquery/cypress/tasks/login.ts +++ b/x-pack/plugins/osquery/cypress/tasks/login.ts @@ -64,6 +64,7 @@ export const getUrlWithRoute = (role: ROLES, route: string) => { port: kibana.port, } as UrlObject)}${route.startsWith('/') ? '' : '/'}${route}`; cy.log(`origin: ${theUrl}`); + return theUrl; }; @@ -92,6 +93,7 @@ export const constructUrlWithUser = (user: User, route: string) => { const builtUrl = new URL(strUrl); cy.log(`origin: ${builtUrl.href}`); + return builtUrl.href; }; diff --git a/x-pack/plugins/osquery/public/action_results/action_agents_status_bar.tsx b/x-pack/plugins/osquery/public/action_results/action_agents_status_bar.tsx index def52bf511215..9a826457cf8cd 100644 --- a/x-pack/plugins/osquery/public/action_results/action_agents_status_bar.tsx +++ b/x-pack/plugins/osquery/public/action_results/action_agents_status_bar.tsx @@ -27,15 +27,18 @@ export const AgentStatusBar: React.FC<{ }> = ({ agentStatus }) => { const palette = useMemo(() => { let stop = 0; + return AGENT_STATUSES.reduce((acc, status) => { stop += agentStatus[status] || 0; acc.push({ stop, color: getColorForAgentStatus(status), }); + return acc; }, [] as Array<{ stop: number; color: string }>); }, [agentStatus]); + return ( genGroup(el + i)), [AGENT_GROUP_KEY.Policy]: new Array(3).fill('test policy ').map((el, i) => genGroup(el + i)), @@ -109,6 +110,7 @@ describe('AgentGrouper', () => { }); }; } + it('should generate policy options', genGroupTest(AGENT_GROUP_KEY.Policy, 'policy')); it('should generate platform options', genGroupTest(AGENT_GROUP_KEY.Platform, 'platform')); }); diff --git a/x-pack/plugins/osquery/public/agents/agent_grouper.ts b/x-pack/plugins/osquery/public/agents/agent_grouper.ts index 8d234ec8cf905..f0bf423672269 100644 --- a/x-pack/plugins/osquery/public/agents/agent_grouper.ts +++ b/x-pack/plugins/osquery/public/agents/agent_grouper.ts @@ -78,12 +78,14 @@ export class AgentGrouper { if (!data?.length || key === AGENT_GROUP_KEY.All) { return; } + const group = this.groups[key]; if (append) { group.data.push(...data); } else { group.data = data; } + group.size = data.length; } @@ -91,6 +93,7 @@ export class AgentGrouper { if (total < 0) { return; } + this.groups[AGENT_GROUP_KEY.All].size = total; } @@ -124,6 +127,7 @@ export class AgentGrouper { break; } } + return opts; } } diff --git a/x-pack/plugins/osquery/public/agents/agents_table.tsx b/x-pack/plugins/osquery/public/agents/agents_table.tsx index fac74086670c2..55e63456fe916 100644 --- a/x-pack/plugins/osquery/public/agents/agents_table.tsx +++ b/x-pack/plugins/osquery/public/agents/agents_table.tsx @@ -108,6 +108,7 @@ const AgentsTableComponent: React.FC = ({ agentSelection, onCh getNumOverlapped(selectedGroups, groups.overlap) ); } + onChange(newAgentSelection); setSelectedOptions(selection); }, @@ -131,6 +132,7 @@ const AgentsTableComponent: React.FC = ({ agentSelection, onCh } } }; + if (agentSelection && !defaultValueInitialized.current && options.length) { if (agentSelection.allAgentsSelected) { const allAgentsOptions = find(['label', ALL_AGENTS_LABEL], options); @@ -175,6 +177,7 @@ const AgentsTableComponent: React.FC = ({ agentSelection, onCh const renderOption = useCallback((option, searchVal, contentClassName) => { const { label, value } = option; + return value?.groupType === AGENT_GROUP_KEY.Agent ? ( diff --git a/x-pack/plugins/osquery/public/agents/helpers.ts b/x-pack/plugins/osquery/public/agents/helpers.ts index 71a67ef1f623a..1c23eac3ca201 100644 --- a/x-pack/plugins/osquery/public/agents/helpers.ts +++ b/x-pack/plugins/osquery/public/agents/helpers.ts @@ -30,8 +30,10 @@ export const getNumOverlapped = ( sum += policies[pol] ?? 0; }); }); + return sum; }; + interface Aggs extends estypes.AggregationsTermsAggregateBase { buckets: AggregationDataPoint[]; } @@ -51,6 +53,7 @@ export const processAggregations = (aggs: Record 0) { overlap[key] = platformPolicies.buckets.reduce((acc: { [key: string]: number }, pol) => { acc[pol.key] = pol.doc_count; + return acc; }, {} as { [key: string]: number }); } @@ -63,13 +66,16 @@ export const processAggregations = (aggs: Record { const visColorsBehindText = euiPaletteColorBlindBehindText(); const typeColors = new Map(); + return (type: AGENT_GROUP_KEY) => { if (!typeColors.has(type)) { typeColors.set(type, visColorsBehindText[typeColors.size]); } + return typeColors.get(type); }; }; @@ -80,6 +86,7 @@ export const getNumAgentsInGrouping = (selectedGroups: SelectedGroups) => { const group = selectedGroups[g]; sum += Object.keys(group).reduce((acc, k) => acc + group[k], 0); }); + return sum; }; @@ -90,6 +97,7 @@ export const generateAgentCheck = .map((group) => { const selectedGroup = selectedGroups[group]; const agentGroup = groups[group]; + // check if the agent platform/policy is selected return selectedGroup[agentGroup]; }) @@ -124,6 +132,7 @@ export const generateAgentSelection = (selection: GroupOption[]) => { // we don't need to calculate diffs when all agents are selected selectedGroups.platform[key] = value.size; } + newAgentSelection.platformsSelected.push(key); break; case AGENT_GROUP_KEY.Policy: @@ -132,6 +141,7 @@ export const generateAgentSelection = (selection: GroupOption[]) => { // we don't need to calculate diffs when all agents are selected selectedGroups.policy[key] = value.size; } + newAgentSelection.policiesSelected.push(key); break; case AGENT_GROUP_KEY.Agent: @@ -140,6 +150,7 @@ export const generateAgentSelection = (selection: GroupOption[]) => { // we don't need to count how many agents are selected if they are all selected selectedAgents.push(value); } + newAgentSelection.agents.push(key); break; default: @@ -148,5 +159,6 @@ export const generateAgentSelection = (selection: GroupOption[]) => { console.error(`unknown group type ${groupType}`); } } + return { newAgentSelection, selectedGroups, selectedAgents }; }; diff --git a/x-pack/plugins/osquery/public/agents/use_agent_details.ts b/x-pack/plugins/osquery/public/agents/use_agent_details.ts index bc3fc085d1c65..b343d75262905 100644 --- a/x-pack/plugins/osquery/public/agents/use_agent_details.ts +++ b/x-pack/plugins/osquery/public/agents/use_agent_details.ts @@ -21,6 +21,7 @@ interface UseAgentDetails { export const useAgentDetails = ({ agentId, silent, skip }: UseAgentDetails) => { const { http } = useKibana().services; const setErrorToast = useErrorToast(); + return useQuery( ['agentDetails', agentId], () => http.get(`/internal/osquery/fleet_wrapper/agents/${agentId}`), diff --git a/x-pack/plugins/osquery/public/agents/use_agent_groups.ts b/x-pack/plugins/osquery/public/agents/use_agent_groups.ts index 4cea34906776f..2dba1c471a786 100644 --- a/x-pack/plugins/osquery/public/agents/use_agent_groups.ts +++ b/x-pack/plugins/osquery/public/agents/use_agent_groups.ts @@ -88,6 +88,7 @@ export const useAgentGroups = ({ osqueryPolicies, osqueryPoliciesLoading }: UseA setPolicies( newPolicies.map((p) => { const name = agentPolicyById[p.id]?.name ?? p.name; + return { ...p, name, diff --git a/x-pack/plugins/osquery/public/agents/use_osquery_policies.ts b/x-pack/plugins/osquery/public/agents/use_osquery_policies.ts index 759e9f22c71b8..679aeef1bd23b 100644 --- a/x-pack/plugins/osquery/public/agents/use_osquery_policies.ts +++ b/x-pack/plugins/osquery/public/agents/use_osquery_policies.ts @@ -33,6 +33,7 @@ export const useOsqueryPolicies = () => { }), } ); + return useMemo( () => ({ osqueryPoliciesLoading, osqueryPolicies }), [osqueryPoliciesLoading, osqueryPolicies] diff --git a/x-pack/plugins/osquery/public/common/helpers.ts b/x-pack/plugins/osquery/public/common/helpers.ts index 4f9efbe839ffd..5f83330fe9ee1 100644 --- a/x-pack/plugins/osquery/public/common/helpers.ts +++ b/x-pack/plugins/osquery/public/common/helpers.ts @@ -26,6 +26,7 @@ export const generateTablePaginationOptions = ( limit: number ): PaginationInputPaginated => { const cursorStart = activePage * limit; + return { activePage, cursorStart, diff --git a/x-pack/plugins/osquery/public/common/hooks/use_breadcrumbs.tsx b/x-pack/plugins/osquery/public/common/hooks/use_breadcrumbs.tsx index d2093b1aa4b9b..5891fd4ae9d78 100644 --- a/x-pack/plugins/osquery/public/common/hooks/use_breadcrumbs.tsx +++ b/x-pack/plugins/osquery/public/common/hooks/use_breadcrumbs.tsx @@ -163,6 +163,7 @@ export function useBreadcrumbs(page: Page, values: DynamicPagePathValues = {}) { const href = breadcrumb.href ? http.basePath.prepend(`${BASE_PATH}${breadcrumb.href}`) : undefined; + return { ...breadcrumb, href, @@ -171,6 +172,7 @@ export function useBreadcrumbs(page: Page, values: DynamicPagePathValues = {}) { if (ev.metaKey || ev.altKey || ev.ctrlKey || ev.shiftKey) { return; } + ev.preventDefault(); application.navigateToUrl(href); } diff --git a/x-pack/plugins/osquery/public/common/hooks/use_discover_link.tsx b/x-pack/plugins/osquery/public/common/hooks/use_discover_link.tsx index 854adb691b6ec..ca294c044d05b 100644 --- a/x-pack/plugins/osquery/public/common/hooks/use_discover_link.tsx +++ b/x-pack/plugins/osquery/public/common/hooks/use_discover_link.tsx @@ -43,6 +43,7 @@ export const useDiscoverLink = ({ filters }: UseDiscoverLink) => { }); setDiscoverUrl(newUrl); }; + getDiscoverUrl(); }, [filters, locator]); diff --git a/x-pack/plugins/osquery/public/common/hooks/use_error_toast.tsx b/x-pack/plugins/osquery/public/common/hooks/use_error_toast.tsx index a922790fd5ce9..42a8b23143a53 100644 --- a/x-pack/plugins/osquery/public/common/hooks/use_error_toast.tsx +++ b/x-pack/plugins/osquery/public/common/hooks/use_error_toast.tsx @@ -14,10 +14,12 @@ export const useErrorToast = () => { const { notifications: { toasts }, } = useKibana().services; + return (error?: unknown, opts?: ErrorToastOptions) => { if (errorToast) { toasts.remove(errorToast); } + if (error) { setErrorToast( // @ts-expect-error update types diff --git a/x-pack/plugins/osquery/public/common/lib/kibana/kibana_react.ts b/x-pack/plugins/osquery/public/common/lib/kibana/kibana_react.ts index 7f142c4c5907e..f58467cc9a5dc 100644 --- a/x-pack/plugins/osquery/public/common/lib/kibana/kibana_react.ts +++ b/x-pack/plugins/osquery/public/common/lib/kibana/kibana_react.ts @@ -36,6 +36,7 @@ const useRouterNavigate = ( onClickCallback?: Parameters[2] ) => { const history = useHistory(); + return reactRouterNavigate(history, to, onClickCallback); }; diff --git a/x-pack/plugins/osquery/public/components/empty_state.tsx b/x-pack/plugins/osquery/public/components/empty_state.tsx index ba475306f5f42..d789aa28204eb 100644 --- a/x-pack/plugins/osquery/public/components/empty_state.tsx +++ b/x-pack/plugins/osquery/public/components/empty_state.tsx @@ -38,6 +38,7 @@ const OsqueryAppEmptyStateComponent = () => { (event) => { if (!isModifiedEvent(event) && isLeftClickEvent(event)) { event.preventDefault(); + return navigateToApp(INTEGRATIONS_PLUGIN_ID, { path: pagePathGetters.integration_details_overview({ pkgkey: OSQUERY_INTEGRATION_NAME, diff --git a/x-pack/plugins/osquery/public/components/main_navigation.tsx b/x-pack/plugins/osquery/public/components/main_navigation.tsx index 73b6435fd8f33..db016575db866 100644 --- a/x-pack/plugins/osquery/public/components/main_navigation.tsx +++ b/x-pack/plugins/osquery/public/components/main_navigation.tsx @@ -22,6 +22,7 @@ enum Section { export const MainNavigation = () => { const location = useLocation(); const section = useMemo(() => location.pathname.split('/')[1] ?? 'overview', [location.pathname]); + return (