Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cloud Security]Misconfiguration preview & Refactor CSP Plugin to include new package #190105

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
6517be3
kick off misconfiguration flyout
animehart Jul 24, 2024
6a609d0
Merge branch 'main' into support-alerts-host-preview
animehart Jul 24, 2024
457da53
more stuff
animehart Jul 24, 2024
7183328
update
animehart Jul 25, 2024
bc336b4
update
animehart Jul 25, 2024
5ddf177
Merge branch 'main' into support-alerts-host-preview
animehart Jul 30, 2024
cdd6568
update colors
animehart Jul 31, 2024
875015e
added cypress and clean up
animehart Jul 31, 2024
3187a52
first push
animehart Aug 8, 2024
f86e7d2
refactor part 1
animehart Aug 8, 2024
0a425e4
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Aug 8, 2024
11ef98c
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine Aug 8, 2024
e74b284
refactor part 2
animehart Aug 8, 2024
32dfd1e
Merge branch 'misconfiguration-preview-refactor-package' of github.co…
animehart Aug 8, 2024
7ac9384
fix conflict
animehart Aug 8, 2024
0dc7f84
updated i18n.json
animehart Aug 9, 2024
d3ef3de
fix i18n
animehart Aug 9, 2024
846ee3d
updated package.json
animehart Aug 9, 2024
da69272
more refactor
animehart Aug 9, 2024
041dd92
update
animehart Aug 9, 2024
eb51a72
more refactor
animehart Aug 9, 2024
a371893
clean up
animehart Aug 10, 2024
1296a8d
reverting useKibana, testing in CI
animehart Aug 10, 2024
2e84041
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Aug 10, 2024
b264344
fix useKibana
animehart Aug 12, 2024
5335a65
Merge branch 'misconfiguration-preview-refactor-package' of github.co…
animehart Aug 12, 2024
6656625
fix
animehart Aug 12, 2024
8539ff2
preview only shows up under certain condition
animehart Aug 13, 2024
0c06dcd
changed so that component only gets rendered when indices is not empt…
animehart Aug 14, 2024
b48d13a
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Aug 14, 2024
c583d4d
fix conflict + fix ci
animehart Aug 14, 2024
b428713
Merge branch 'misconfiguration-preview-refactor-package' of github.co…
animehart Aug 14, 2024
dcae120
fix ci
animehart Aug 14, 2024
f46f40d
quick check fix
animehart Aug 14, 2024
23bb270
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Aug 14, 2024
c8922f9
clean up + update cypress
animehart Aug 14, 2024
b8f4efb
Merge branch 'misconfiguration-preview-refactor-package' of github.co…
animehart Aug 14, 2024
c7113be
fix ci
animehart Aug 14, 2024
cbb5b51
more cleanup
animehart Aug 14, 2024
6b3eab0
addressing pr comments
animehart Aug 16, 2024
9f1cc37
pr comments
animehart Aug 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ x-pack/plugins/cloud_integrations/cloud_full_story @elastic/kibana-core
x-pack/test/cloud_integration/plugins/saml_provider @elastic/kibana-core
x-pack/plugins/cloud_integrations/cloud_links @elastic/kibana-core
x-pack/plugins/cloud @elastic/kibana-core
x-pack/packages/kbn-cloud-security-posture @elastic/kibana-cloud-security-posture
x-pack/packages/kbn-cloud-security-posture-common @elastic/kibana-cloud-security-posture
x-pack/plugins/cloud_security_posture @elastic/kibana-cloud-security-posture
packages/shared-ux/code_editor/impl @elastic/appex-sharedux
packages/shared-ux/code_editor/mocks @elastic/appex-sharedux
Expand Down Expand Up @@ -1426,6 +1428,7 @@ x-pack/plugins/cloud_integrations/cloud_full_story/server/config.ts @elastic/kib
/x-pack/test/security_solution_cypress/cypress/screens/common @elastic/security-detections-response @elastic/security-threat-hunting
/x-pack/test/security_solution_cypress/cypress/support @elastic/security-detections-response @elastic/security-threat-hunting
/x-pack/test/security_solution_cypress/cypress/urls @elastic/security-threat-hunting-investigations @elastic/security-detection-engine
/x-pack/test/security_solution_cypress/cypress/e2e/cloud_security_posture @elastic/kibana-cloud-security-posture

/x-pack/plugins/security_solution/common/ecs @elastic/security-threat-hunting-investigations
/x-pack/plugins/security_solution/common/test @elastic/security-detections-response @elastic/security-threat-hunting
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@
"@kbn/cloud-integration-saml-provider-plugin": "link:x-pack/test/cloud_integration/plugins/saml_provider",
"@kbn/cloud-links-plugin": "link:x-pack/plugins/cloud_integrations/cloud_links",
"@kbn/cloud-plugin": "link:x-pack/plugins/cloud",
"@kbn/cloud-security-posture": "link:x-pack/packages/kbn-cloud-security-posture",
"@kbn/cloud-security-posture-common": "link:x-pack/packages/kbn-cloud-security-posture-common",
"@kbn/cloud-security-posture-plugin": "link:x-pack/plugins/cloud_security_posture",
"@kbn/code-editor": "link:packages/shared-ux/code_editor/impl",
"@kbn/code-editor-mock": "link:packages/shared-ux/code_editor/mocks",
Expand Down
4 changes: 4 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@
"@kbn/cloud-links-plugin/*": ["x-pack/plugins/cloud_integrations/cloud_links/*"],
"@kbn/cloud-plugin": ["x-pack/plugins/cloud"],
"@kbn/cloud-plugin/*": ["x-pack/plugins/cloud/*"],
"@kbn/cloud-security-posture": ["x-pack/packages/kbn-cloud-security-posture"],
"@kbn/cloud-security-posture/*": ["x-pack/packages/kbn-cloud-security-posture/*"],
"@kbn/cloud-security-posture-common": ["x-pack/packages/kbn-cloud-security-posture-common"],
"@kbn/cloud-security-posture-common/*": ["x-pack/packages/kbn-cloud-security-posture-common/*"],
"@kbn/cloud-security-posture-plugin": ["x-pack/plugins/cloud_security_posture"],
"@kbn/cloud-security-posture-plugin/*": ["x-pack/plugins/cloud_security_posture/*"],
"@kbn/code-editor": ["packages/shared-ux/code_editor/impl"],
Expand Down
6 changes: 5 additions & 1 deletion x-pack/.i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
"xpack.cloudDefend": "plugins/cloud_defend",
"xpack.cloudLinks": "plugins/cloud_integrations/cloud_links",
"xpack.cloudDataMigration": "plugins/cloud_integrations/cloud_data_migration",
"xpack.csp": "plugins/cloud_security_posture",
"xpack.csp": [
"plugins/cloud_security_posture",
"packages/kbn-cloud-security-posture-common",
"packages/kbn-cloud-security-posture"
],
"xpack.customBranding": "plugins/custom_branding",
"xpack.dashboard": "plugins/dashboard_enhanced",
"xpack.dataQuality": "plugins/data_quality",
Expand Down
9 changes: 9 additions & 0 deletions x-pack/packages/kbn-cloud-security-posture-common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# @kbn/cloud-security-posture-common

This package provides common code consumed in both the browser, i.e. the
`packages/cloud-security-posture` package and `plugins/cloud_security_posture` plugin, and on the server, i.e. the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

packages/kbn-cloud-security-posture

`plugins/cloud_security_posture` plugin.

## Maintainers

Maintained by the Cloud Security Posture Team
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Cloud Risk Management team. Though the team name might change, so maybe worth just mentioning the overarching Cloud Security Team

20 changes: 20 additions & 0 deletions x-pack/packages/kbn-cloud-security-posture-common/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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.
*/
export const KSPM_POLICY_TEMPLATE = 'kspm';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that these are copied over from the cloud_security_posture plugin. The idea of the common package is that we would use the code from this package everywhere. Ideally we shouldn't have any duplicated code after we are done with the creation of shared packages. If you are concerned with the PR size, we can do it in the follow up PR, but right away, without creating tech debt tickets

export const CSPM_POLICY_TEMPLATE = 'cspm';
export const CDR_LATEST_NATIVE_MISCONFIGURATIONS_INDEX_PATTERN =
'logs-cloud_security_posture.findings_latest-default';
export const CDR_LATEST_THIRD_PARTY_MISCONFIGURATIONS_INDEX_PATTERN =
'logs-*_latest_misconfigurations_cdr';
export const CDR_MISCONFIGURATIONS_INDEX_PATTERN = `${CDR_LATEST_NATIVE_MISCONFIGURATIONS_INDEX_PATTERN},${CDR_LATEST_THIRD_PARTY_MISCONFIGURATIONS_INDEX_PATTERN}`;
export const LATEST_FINDINGS_RETENTION_POLICY = '26h';
export const MAX_FINDINGS_TO_LOAD = 500;
export const CSP_GET_BENCHMARK_RULES_STATE_ROUTE_PATH =
'/internal/cloud_security_posture/rules/_get_states';
export const CSP_GET_BENCHMARK_RULES_STATE_API_CURRENT_VERSION = '1';
export const STATUS_ROUTE_PATH = '/internal/cloud_security_posture/status';
export const STATUS_API_CURRENT_VERSION = '1';
13 changes: 13 additions & 0 deletions x-pack/packages/kbn-cloud-security-posture-common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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.
*/

export * from './types';
export * from './constants';
export * from './schema/csp_finding';
export type { CspBenchmarkRulesStates } from './types/latest';
export { showErrorToast } from './utils/show_error_toast';
export { buildMutedRulesFilter } from './utils/helpers';
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

{
"id": "@kbn/cloud-security-posture-common",
"owner": "@elastic/kibana-cloud-security-posture",
"type": "shared-common"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@kbn/cloud-security-posture-common",
"private": true,
"version": "1.0.0",
"license": "Elastic License 2.0",
"description": "Shared components for cloud security posture, both client and server side"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,37 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

// TODO: this needs to be defined in a versioned schema
import type { EcsDataStream, EcsEvent } from '@elastic/ecs';
import { CspBenchmarkRuleMetadata } from '../types/latest';
import { TypeOf, schema } from '@kbn/config-schema';
import { CSPM_POLICY_TEMPLATE, KSPM_POLICY_TEMPLATE } from '../constants';

export type CspBenchmarkRuleMetadata = TypeOf<typeof cspBenchmarkRuleMetadataSchema>;

export const cspBenchmarkRuleMetadataSchema = schema.object({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see it is duplicated from the v3 rule type. Longer term I think we will need to move all the common schemas and types here, versioned and have it here as a source of truth. Let's think how to get rid of this duplication now, eg. import in the v3 from the common and reexport . But overall we still need this TODO TODO: this needs to be defined in a versioned schema because this schema should be versioned and the all the versions should live in the common package

audit: schema.string(),
benchmark: schema.object({
name: schema.string(),
posture_type: schema.maybe(
schema.oneOf([schema.literal(CSPM_POLICY_TEMPLATE), schema.literal(KSPM_POLICY_TEMPLATE)])
),
id: schema.string(),
version: schema.string(),
rule_number: schema.maybe(schema.string()),
}),
default_value: schema.maybe(schema.string()),
description: schema.string(),
id: schema.string(),
impact: schema.maybe(schema.string()),
name: schema.string(),
profile_applicability: schema.string(),
rationale: schema.string(),
references: schema.maybe(schema.string()),
rego_rule_id: schema.string(),
remediation: schema.string(),
section: schema.string(),
tags: schema.arrayOf(schema.string()),
version: schema.string(),
});

export interface CspFinding {
'@timestamp': string;
Expand Down
23 changes: 23 additions & 0 deletions x-pack/packages/kbn-cloud-security-posture-common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node",
]
},
"include": [
"**/*.ts",
"**/*.tsx",
],
"exclude": [
"target/**/*"
],
"kbn_references": [
"@kbn/config-schema",
"@kbn/data-views-plugin",
"@kbn/core",
"@kbn/i18n",
]
}
43 changes: 43 additions & 0 deletions x-pack/packages/kbn-cloud-security-posture-common/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.
*/

export type CspStatusCode =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's make sure there are no duplications left in our plugin, we should be using types from the common package

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so for this one specifically, there seems to be an issue with Telemetry where it doesn't seem to like it when I'm using this type from the package
I have discussed this issue with @CohenIdo but still can't find the fix for it, thus we decided to have 2 separate copy

| 'indexed' // latest findings index exists and has results
| 'indexing' // index timeout was not surpassed since installation, assumes data is being indexed
| 'unprivileged' // user lacks privileges for the latest findings index
| 'index-timeout' // index timeout was surpassed since installation
| 'not-deployed' // no healthy agents were deployed
| 'not-installed' // number of installed csp integrations is 0;
| 'waiting_for_results'; // have healthy agents but no findings at all, assumes data is being indexed for the 1st time

export type IndexStatus =
| 'not-empty' // Index contains documents
| 'empty' // Index doesn't contain documents (or doesn't exist)
| 'unprivileged'; // User doesn't have access to query the index

export interface IndexDetails {
index: string;
status: IndexStatus;
}

export interface BaseCspSetupBothPolicy {
status: CspStatusCode;
installedPackagePolicies: number;
healthyAgents: number;
}

export interface BaseCspSetupStatus {
indicesDetails: IndexDetails[];
latestPackageVersion: string;
cspm: BaseCspSetupBothPolicy;
kspm: BaseCspSetupBothPolicy;
vuln_mgmt: BaseCspSetupBothPolicy;
isPluginInitialized: boolean;
installedPackageVersion?: string | undefined;
}

export type CspSetupStatus = BaseCspSetupStatus;
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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { schema, TypeOf } from '@kbn/config-schema';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having the latest without the versioned types doesn't seem like the right approach. It shows I guess that we need to move the whole types with all the versions to the common package

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i mean in this case, I think we can just import + re-export the versioned types in the latest file in csp plugin
wdyt ?
the file naming in the package is kinda confusing, my bad

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the first iteration it might work, but eventually I think the source of truth for the versioned schema should be the common package, as we are using types and schemas in both the plugin and in the package


export type CspBenchmarkRulesStates = TypeOf<typeof rulesStates>;
const ruleStateAttributes = schema.object({
muted: schema.boolean(),
benchmark_id: schema.string(),
benchmark_version: schema.string(),
rule_number: schema.string(),
rule_id: schema.string(),
});

const rulesStates = schema.recordOf(schema.string(), ruleStateAttributes);
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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 { QueryDslQueryContainer } from '@kbn/data-views-plugin/common/types';
import { i18n } from '@kbn/i18n';
import { CspBenchmarkRulesStates } from '../types/latest';

export const extractErrorMessage = (e: unknown, defaultMessage = 'Unknown Error'): string => {
if (e instanceof Error) return e.message;
if (typeof e === 'string') return e;

return i18n.translate('xpack.csp.findings.errorMessage.default', {
defaultMessage,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure the dynamic default message will work. I don't know the i18n tooling in depth, but I guess it creates the translation files out of the default message and it can't be fully dynamic. I think it should be a constant string. As I can see it was copied from x-pack/plugins/cloud_security_posture/common/utils/helpers.ts where the i18n wasn't solved. Let's first remove the duplication and also keep the i18n solution out of the scope of this PR

});
};

export const buildMutedRulesFilter = (
rulesStates: CspBenchmarkRulesStates
): QueryDslQueryContainer[] => {
const mutedRules = Object.fromEntries(
Object.entries(rulesStates).filter(([key, value]) => value.muted === true)
);

const mutedRulesFilterQuery = Object.keys(mutedRules).map((key) => {
const rule = mutedRules[key];
return {
bool: {
must: [
{ term: { 'rule.benchmark.id': rule.benchmark_id } },
{ term: { 'rule.benchmark.version': rule.benchmark_version } },
{ term: { 'rule.benchmark.rule_number': rule.rule_number } },
],
},
};
});

return mutedRulesFilterQuery;
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import type { CoreStart } from '@kbn/core/public';
import { i18n } from '@kbn/i18n';
import { extractErrorMessage } from '../../../common/utils/helpers';
import { extractErrorMessage } from './helpers';

const SEARCH_FAILED_TEXT = i18n.translate(
'xpack.csp.findings.findingsErrorToast.searchFailedTitle',
Expand Down
9 changes: 9 additions & 0 deletions x-pack/packages/kbn-cloud-security-posture/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# @kbn/cloud-security-posture

This package includes
- Hooks that's used on Flyout component that's used in Alerts page on Security Solution Plugins as well as components on CSP plugin
- Utilities and types thats used for the Hooks above as well as in CSP plugins

## Maintainers

Maintained by the Cloud Security Posture Team
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as for the common package let's update the team name

16 changes: 16 additions & 0 deletions x-pack/packages/kbn-cloud-security-posture/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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.
*/

export * from './type';
export { useMisconfigurationPreview } from './src/hooks/use_misconfiguration_preview';
export { useGetCspBenchmarkRulesStatesApi } from './src/hooks/use_get_benchmark_rules_state_api';
export { useCspSetupStatusApi } from './src/hooks/use_csp_setup_status_api';
export {
getAggregationCount,
getFindingsCountAggQuery,
isIndexWithDocsAvailable,
} from './src/utils/utils';
5 changes: 5 additions & 0 deletions x-pack/packages/kbn-cloud-security-posture/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "@kbn/cloud-security-posture",
"owner": "@elastic/kibana-cloud-security-posture",
"type": "shared-browser"
}
7 changes: 7 additions & 0 deletions x-pack/packages/kbn-cloud-security-posture/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@kbn/cloud-security-posture",
"private": true,
"version": "1.0.0",
"license": "Elastic License 2.0",
"description": "Shared components for cloud security posture, client side"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
*/

import { useQuery, type UseQueryOptions } from '@tanstack/react-query';
import { useKibana } from '../hooks/use_kibana';
import { type CspSetupStatus } from '../../../common/types_old';
import { STATUS_API_CURRENT_VERSION, STATUS_ROUTE_PATH } from '../../../common/constants';
import { useKibana } from '@kbn/kibana-react-plugin/public';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it make sense to move our typed useKibana from x-pack/plugins/cloud_security_posture/public/common/hooks/use_kibana.ts to the common plugin and use it everywhere? otherwise we will be providing these CoreStart & CspClientPluginStartDeps types everywhere or would have duplicated useKibana hook between our plugin and the common package

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally I did that but there seems to be an issue when I moved our useKibana to the package (things starts to fail) and separate from that issue I also had a discussion with @opauloh where we think that it might be better to have 2 different useKibana due to plugin dependencies

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's see if we can bring it back as a part of a smaller PR separately so it's easier to reason about. If not, using the hook directly from @kbn/kibana-react-plugin/public is fine, we might just need to create a type to not repeat CoreStart & CspClientPluginStartDeps all the time

import type { CoreStart } from '@kbn/core/public';
import { STATUS_API_CURRENT_VERSION, STATUS_ROUTE_PATH } from '@kbn/cloud-security-posture-common';
import type { CspSetupStatus } from '@kbn/cloud-security-posture-common';
import type { CspClientPluginStartDeps } from '../../type';

const getCspSetupStatusQueryKey = 'csp_status_key';

export const useCspSetupStatusApi = (
options?: UseQueryOptions<CspSetupStatus, unknown, CspSetupStatus>
) => {
const { http } = useKibana().services;
const { http } = useKibana<CoreStart & CspClientPluginStartDeps>().services;
return useQuery<CspSetupStatus, unknown, CspSetupStatus>(
[getCspSetupStatusQueryKey],
() => http.get<CspSetupStatus>(STATUS_ROUTE_PATH, { version: STATUS_API_CURRENT_VERSION }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
*/

import { useQuery } from '@tanstack/react-query';
import { CspBenchmarkRulesStates } from '../../../../common/types/latest';
import {
CSP_GET_BENCHMARK_RULES_STATE_API_CURRENT_VERSION,
CSP_GET_BENCHMARK_RULES_STATE_ROUTE_PATH,
} from '../../../../common/constants';
import { useKibana } from '../../../common/hooks/use_kibana';
CspBenchmarkRulesStates,
} from '@kbn/cloud-security-posture-common';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import type { CoreStart } from '@kbn/core/public';
import type { CspClientPluginStartDeps } from '../../type';

export const getRuleStatesKey = ['get_rules_state_key'];

export const useGetCspBenchmarkRulesStatesApi = () => {
const { http } = useKibana().services;
const { http } = useKibana<CoreStart & CspClientPluginStartDeps>().services;
return useQuery<CspBenchmarkRulesStates, unknown, CspBenchmarkRulesStates>(getRuleStatesKey, () =>
http.get<CspBenchmarkRulesStates>(CSP_GET_BENCHMARK_RULES_STATE_ROUTE_PATH, {
version: CSP_GET_BENCHMARK_RULES_STATE_API_CURRENT_VERSION,
Expand Down
Loading