Skip to content

Commit

Permalink
[Osquery] Fix 7.16.0 BC1 issues (#116074)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrykkopycinski authored Oct 26, 2021
1 parent 645cecd commit f6dd54a
Show file tree
Hide file tree
Showing 30 changed files with 460 additions and 177 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@
"react-moment-proptypes": "^1.7.0",
"react-monaco-editor": "^0.41.2",
"react-popper-tooltip": "^2.10.1",
"react-query": "^3.27.0",
"react-query": "^3.28.0",
"react-redux": "^7.2.0",
"react-resizable": "^1.7.5",
"react-resize-detector": "^4.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ const AgentsPolicyLinkComponent: React.FC<AgentsPolicyLinkProps> = ({ policyId }
const {
application: { getUrlForApp, navigateToApp },
} = useKibana().services;

const { data } = useAgentPolicy({ policyId });

const href = useMemo(
() =>
getUrlForApp(PLUGIN_ID, {
path: `#` + pagePathGetters.policy_details({ policyId })[1],
path: pagePathGetters.policy_details({ policyId })[1],
}),
[getUrlForApp, policyId]
);
Expand All @@ -45,7 +44,7 @@ const AgentsPolicyLinkComponent: React.FC<AgentsPolicyLinkProps> = ({ policyId }
event.preventDefault();

return navigateToApp(PLUGIN_ID, {
path: `#` + pagePathGetters.policy_details({ policyId })[1],
path: pagePathGetters.policy_details({ policyId })[1],
});
}
},
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/osquery/public/agents/agent_id_to_name.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const AgentIdToNameComponent: React.FC<AgentIdToNameProps> = ({ agentId }) => {
<EuiLink
className="eui-textTruncate"
href={getUrlForApp(PLUGIN_ID, {
path: `#` + pagePathGetters.agent_details({ agentId })[1],
path: pagePathGetters.agent_details({ agentId })[1],
})}
target="_blank"
>
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/osquery/public/agents/agents_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ interface AgentsTableProps {
}

const perPage = 10;
const DEBOUNCE_DELAY = 100; // ms
const DEBOUNCE_DELAY = 300; // ms

const AgentsTableComponent: React.FC<AgentsTableProps> = ({ agentSelection, onChange }) => {
// search related
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/osquery/public/agents/use_agent_policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export const useAgentPolicies = (policyIds: string[] = []) => {
queryFn: () => http.get(`/internal/osquery/fleet_wrapper/agent_policies/${policyId}`),
enabled: policyIds.length > 0,
onSuccess: () => setErrorToast(),
onError: (error) =>
setErrorToast(error as Error, {
onError: (error: Error) =>
setErrorToast(error, {
title: i18n.translate('xpack.osquery.action_policy_details.fetchError', {
defaultMessage: 'Error while fetching policy details',
}),
Expand Down

Large diffs are not rendered by default.

37 changes: 0 additions & 37 deletions x-pack/plugins/osquery/public/components/beta_badge.tsx

This file was deleted.

132 changes: 132 additions & 0 deletions x-pack/plugins/osquery/public/fleet_integration/config_uploader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { EuiLink, EuiFormRow, EuiFilePicker, EuiSpacer } from '@elastic/eui';
import React, { useCallback, useState, useRef } from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';

const SUPPORTED_CONFIG_EXTENSIONS = ['application/json', 'text/plain'];

const ExampleConfigLink = React.memo(() => (
<EuiLink
href="https://github.com/osquery/osquery/blob/master/tools/deployment/osquery.example.conf"
target="_blank"
>
<FormattedMessage
id="xpack.osquery.configUploader.exampleConfigLinkLabel"
defaultMessage="Example config"
/>
</EuiLink>
));

ExampleConfigLink.displayName = 'ExampleOsqueryConfigLink';

interface ConfigUploaderProps {
onChange: (payload: Record<string, unknown>) => void;
}

const ConfigUploaderComponent: React.FC<ConfigUploaderProps> = ({ onChange }) => {
const filePickerRef = useRef<EuiFilePicker>(null);
const [isInvalid, setIsInvalid] = useState<string | null>(null);
// @ts-expect-error update types
let fileReader;

const handleFileRead = () => {
// @ts-expect-error update types
const content = fileReader.result;

let parsedContent;

try {
parsedContent = JSON.parse(content.replaceAll('\\\n', ''), (key, value) => {
if (key === 'query') {
// remove any multiple spaces from the query
return value.replaceAll(/\s(?=\s)/gm, '');
}
return value;
});

setIsInvalid(null);
} catch (error) {
setIsInvalid(error);
// @ts-expect-error update types
filePickerRef.current?.removeFiles(new Event('fake'));
}

onChange(parsedContent);
// @ts-expect-error update types
filePickerRef.current?.removeFiles(new Event('fake'));
};

// @ts-expect-error update types
// eslint-disable-next-line react-hooks/exhaustive-deps
const handleFileChosen = (file) => {
fileReader = new FileReader();
fileReader.onloadend = handleFileRead;
fileReader.readAsText(file);
};

const handleInputChange = useCallback(
(inputFiles) => {
if (!inputFiles.length) {
return;
}

if (
inputFiles.length &&
((!!inputFiles[0].type.length &&
!SUPPORTED_CONFIG_EXTENSIONS.includes(inputFiles[0].type)) ??
!inputFiles[0].name.endsWith('.conf'))
) {
setIsInvalid(
i18n.translate('xpack.osquery.configUploader.unsupportedFileTypeText', {
defaultMessage:
'File type {fileType} is not supported, please upload {supportedFileTypes} config file',
values: {
fileType: inputFiles[0].type,
supportedFileTypes: SUPPORTED_CONFIG_EXTENSIONS.join(' or '),
},
})
);
// @ts-expect-error update types
filePickerRef.current?.removeFiles(new Event('fake'));
return;
}

handleFileChosen(inputFiles[0]);
},
[handleFileChosen]
);

return (
<>
<EuiSpacer size="xl" />
<EuiFormRow
fullWidth
labelAppend={<ExampleConfigLink />}
isInvalid={!!isInvalid}
error={<>{`${isInvalid}`}</>}
>
<EuiFilePicker
ref={filePickerRef}
id="osquery_config_picker"
initialPromptText={i18n.translate('xpack.osquery.configUploader.initialPromptTextLabel', {
defaultMessage: 'Select or drag and drop osquery config file',
})}
onChange={handleInputChange}
display="large"
fullWidth
isInvalid={!!isInvalid}
accept={SUPPORTED_CONFIG_EXTENSIONS.join(',')}
/>
</EuiFormRow>
</>
);
};

export const ConfigUploader = React.memo(ConfigUploaderComponent);
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ import { useKibana, isModifiedEvent, isLeftClickEvent } from '../common/lib/kiba

interface NavigationButtonsProps {
isDisabled?: boolean;
integrationPolicyId?: string | undefined;
agentPolicyId?: string | undefined;
}

const NavigationButtonsComponent: React.FC<NavigationButtonsProps> = ({
isDisabled = false,
integrationPolicyId,
agentPolicyId,
}) => {
const {
Expand Down Expand Up @@ -52,19 +50,19 @@ const NavigationButtonsComponent: React.FC<NavigationButtonsProps> = ({
);

const packsHref = getUrlForApp(PLUGIN_ID, {
path: integrationPolicyId ? `/packs/${integrationPolicyId}/edit` : `/packs`,
path: `/packs`,
});

const packsClick = useCallback(
(event) => {
if (!isModifiedEvent(event) && isLeftClickEvent(event)) {
event.preventDefault();
navigateToApp(PLUGIN_ID, {
path: integrationPolicyId ? `/packs/${integrationPolicyId}/edit` : `/packs`,
path: `/packs`,
});
}
},
[navigateToApp, integrationPolicyId]
[navigateToApp]
);

return (
Expand Down
Loading

0 comments on commit f6dd54a

Please sign in to comment.