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

Move Functions from CSP to Shared packages #212663

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

animehart
Copy link
Contributor

@animehart animehart commented Feb 27, 2025

Summary

As a part of Expandable Findings flyout, we will need to move some Constants, Types, Functions, Components into Security Solution plugin or Shared package

This PR is phase 2 for Findings (Misconfiguration flyout) which include moving functions into shared package or security solution plugin

@animehart
Copy link
Contributor Author

/ci

@animehart
Copy link
Contributor Author

/ci

@animehart
Copy link
Contributor Author

/ci

@animehart
Copy link
Contributor Author

/ci

@animehart
Copy link
Contributor Author

/ci

@animehart
Copy link
Contributor Author

/ci

@animehart
Copy link
Contributor Author

/ci

@animehart
Copy link
Contributor Author

/ci

@animehart
Copy link
Contributor Author

/ci

@animehart
Copy link
Contributor Author

/ci

@animehart
Copy link
Contributor Author

/ci

@animehart
Copy link
Contributor Author

/ci

@animehart
Copy link
Contributor Author

/ci

@animehart
Copy link
Contributor Author

/ci

@animehart animehart marked this pull request as ready for review March 3, 2025 18:11
@animehart animehart requested a review from a team as a code owner March 3, 2025 18:11
@animehart animehart added v9.0.0 v9.1.0 release_note:skip Skip the PR/issue when compiling release notes backport:skip This commit does not require backporting Team:Cloud Security Cloud Security team related labels Mar 3, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-cloud-security-posture (Team:Cloud Security)

Copy link
Contributor

@seanrathier seanrathier left a comment

Choose a reason for hiding this comment

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

A couple of comments. I would like to hear your opions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we group these under utils? A lot of the code in the shared package will be utils
I prefer if all the related code in the shared package is grouped by similar directories. All the types and functions related rules should be in a directory called rules

rules
 - types.ts
 - create_detection_rules.ts
 - detection_rules.ts

Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 This needs discussion, but IMO

I think the types should stay co-located with the code unless they are reused by more than 1 module (file), then it may be better to locate them at a high level in the file structure.

Even if the type is exported out of the library, if only one module in the library is using it, it should be colocated.

If we have a type in the library for shared usage with other libraries and no share package module uses it, it could be in this type of types file.

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 in this case, we should put RuleCreateProps type in create_detection_rule.ts file as its only being used there ? or should we can just do your first suggestion where we put all those thing into 1 sub folder (rules in this case) ?

Copy link
Contributor

Choose a reason for hiding this comment

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

so in this case, we should put RuleCreateProps type in create_detection_rule.ts file as its only being used there ?

Yes

Comment on lines 8 to 10
import { Truthy } from 'lodash';

export const truthy = <T>(value: T): value is Truthy<T> => !!value;
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed that we were importing only the Truthy type from Lodash without actually using any Lodash functions. I think this is a bit of an odd pattern because Lodash is primarily a utility library, so importing only the type instead of simply using the truthy function directly from lodash doesn't seem to make much sense.

If the case is that we had to customize the lodash's truthy function because it doesn't work for us out of the box, I think it's better to create our own Truthy type as well (based on lodash):

Suggested change
import { Truthy } from 'lodash';
export const truthy = <T>(value: T): value is Truthy<T> => !!value;
type Truthy<T> = T extends null | undefined | false | "" | 0 | 0n ? never : T;
export const truthy = <T>(value: T): value is Truthy<T> => !!value;

Copy link
Contributor

@opauloh opauloh left a comment

Choose a reason for hiding this comment

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

looks good overall, just a few questions


export const CLOUD_SECURITY_POSTURE_PACKAGE_NAME = 'cloud_security_posture';

export const FINDINGS_INDEX_NAME = 'logs-cloud_security_posture.findings';
export const FINDINGS_INDEX_PATTERN = 'logs-cloud_security_posture.findings-default*';
// export const FINDINGS_INDEX_PATTERN = 'logs-cloud_security_posture.findings-default*';
Copy link
Contributor

Choose a reason for hiding this comment

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

is there any reason to keep the comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope
I missed this
Thanks !

@@ -168,7 +170,7 @@ const getFlyoutDescriptionList = (finding: CspFinding): EuiDescriptionListProps[
].filter(truthy);

const FindingsTab = ({ tab, finding }: { finding: CspFinding; tab: FindingsTab }) => {
const { application } = useKibana().services;
const { application } = useKibana<CoreStart & CspClientPluginStartDeps>().services;
Copy link
Contributor

Choose a reason for hiding this comment

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

We have been using this combined type in a quite few places now, I think it's time to add a dedicate type?

i.e

export type CspUseKibanaServices = CoreStart & CspClientPluginStartDeps

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmmm I remembered we did that but we revert to combined type maybe I remembered it wrongly ?
There's a reason why we did this in the first place

@animehart animehart requested review from seanrathier and opauloh March 5, 2025 13:06
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
cloudSecurityPosture 705 707 +2
securitySolution 7106 7108 +2
total +4

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/cloud-security-posture-common 135 147 +12

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
cloudSecurityPosture 503.7KB 503.7KB -4.0B

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
@kbn/cloud-security-posture-common 2 3 +1
Unknown metric groups

API count

id before after diff
@kbn/cloud-security-posture-common 137 149 +12

History

Copy link
Contributor

@seanrathier seanrathier left a comment

Choose a reason for hiding this comment

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

Thanks for changing the structure. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:Cloud Security Cloud Security team related v9.0.0 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants