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

🐛 Properly target the region filter. #3225

Merged
merged 8 commits into from
Feb 28, 2024

Conversation

montera82
Copy link
Contributor

@montera82 montera82 commented Feb 6, 2024

Introduction

This PR ensures we can properly filter by region.

cnquery shell aws --filters all:region=us-east-2  
cnquery shell aws --filters region=us-east-2 
cnquery shell aws --filters ec2:region=us-east-2

Relates to Issue : mondoohq/cnspec#1047

Copy link
Contributor

github-actions bot commented Feb 6, 2024

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@montera82 montera82 marked this pull request as draft February 6, 2024 23:43
@montera82
Copy link
Contributor Author

I have read the Mondoo CLA Document and I hereby sign the CLA

@montera82
Copy link
Contributor Author

recheck

@montera82 montera82 marked this pull request as ready for review February 8, 2024 20:04
Copy link
Member

@chris-rock chris-rock left a comment

Choose a reason for hiding this comment

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

Thank you @montera82 for this contribution. I added a few comments to help with the implementation.

providers/aws/config/config.go Outdated Show resolved Hide resolved
providers/aws/provider/provider.go Show resolved Hide resolved
providers/aws/connection/connection.go Outdated Show resolved Hide resolved
montera82 and others added 3 commits February 12, 2024 11:06
@montera82 montera82 marked this pull request as draft February 12, 2024 10:57
@montera82
Copy link
Contributor Author

montera82 commented Feb 12, 2024

Hi @chris-rock, thanks for your feedbacks. I implemented them, but doing a few tests shows that it quering with --filters ec2:region=us-east-2 still not fixed, as it returns data for all the regions instead of 1. I will set more time to look again at it, for now marked the PR as draft.

@montera82 montera82 marked this pull request as ready for review February 21, 2024 13:13
Copy link
Member

@chris-rock chris-rock left a comment

Choose a reason for hiding this comment

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

Thank you @montera82 for this great improvement

case k == "ec2:region":
d.Ec2DiscoveryFilters.Regions = append(d.Ec2DiscoveryFilters.Regions, v)
case k == "all:region":
case k == "all:region", k == "region":
Copy link
Member

Choose a reason for hiding this comment

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

nice addition

@@ -125,18 +125,15 @@ func parseOptsToFilters(opts map[string]string) DiscoveryFilters {
for k, v := range opts {
switch {
case strings.HasPrefix(k, "ec2:tag:"):
d.Ec2DiscoveryFilters.Tags[strings.TrimPrefix("ec2:tag:", k)] = v
d.Ec2DiscoveryFilters.Tags[strings.TrimPrefix(k, "ec2:tag:")] = v
Copy link
Member

Choose a reason for hiding this comment

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

thank you for that fix

@@ -617,6 +617,9 @@ func (a *mqlAwsEc2) getInstances(conn *connection.AwsConnection) []*jobpool.Job
if err != nil {
return []*jobpool.Job{{Err: err}}
}
if len(conn.Filters.Ec2DiscoveryFilters.Regions) > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Nice addition!

@@ -112,20 +112,23 @@ func containsInterfaceSlice(sl []interface{}, s string) bool {
}

func instanceMatchesFilters(instance *mqlAwsEc2Instance, filters connection.DiscoveryFilters) bool {
Copy link
Member

Choose a reason for hiding this comment

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

This method requires additional testing to ensure we cover all edge cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, more test is always nice, if i invest more time i would definately find some of those cases!

@chris-rock chris-rock merged commit 01818c3 into mondoohq:main Feb 28, 2024
5 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Feb 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants