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

check for multiple inverse matches #1332

Merged
merged 4 commits into from
Jul 2, 2023

Conversation

mistadave
Copy link
Contributor

Current behaviour

The check checkEventConditionPatterns returns after first match is true, which doesn't allow to check multiple wildcards inverse.

New behaviour

This change allows in the event rules to set multiple path filters with inverse matches.
Which allows for matching to any kind of file except for those inverse matches (acts as an exclusions list).
image
All tests on the eventmanager_test.go passed.

Known limitations

Probably doesn't work with mixed path filters. Which I think does not make sense anyway, because a matching pattern always exclude any other inverse matches.

Changes

  • update function checkEventConditionPatterns for multiple inverse patterns
    • Use the matches variable to keep track of the state if condition matches pattern.
  • extend TestDoubleStarMatching with inverse flag
  • write test for multiple douple start matches, also for inverse matches

@mistadave mistadave requested a review from drakkan as a code owner June 20, 2023 10:32
@drakkan
Copy link
Owner

drakkan commented Jun 21, 2023

Hello, thank you for your contribution. I'll give a look the next weekend. Can you please fix the DCO check in the meantime?

return false
}
} else if checkEventConditionPattern(p, name) {
matches = true
Copy link
Owner

Choose a reason for hiding this comment

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

Can we just return true here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes that possible, will update that

@drakkan
Copy link
Owner

drakkan commented Jun 25, 2023

This patch can be merged but please apply the same logic also in checkEventGroupConditionPatters

func checkEventGroupConditionPatters(groups []sdk.GroupMapping, patterns []dataprovider.ConditionPattern) bool {

to have uniform behavior. Thank you!

@mistadave
Copy link
Contributor Author

Hello drakkan,
I've added direct return and added same behaviour to checkEventGroupConditionPatterns(). Did also find a spellmistake.

@drakkan
Copy link
Owner

drakkan commented Jun 29, 2023

Hello drakkan, I've added direct return and added same behaviour to checkEventGroupConditionPatterns(). Did also find a spellmistake.

Thank you, but please fix the DCO check. I'll do some tests with groups this weekend to make sure the behavior is uniform.

@mistadave
Copy link
Contributor Author

Yes, just saw it. Will fix them.

Signed-off-by: David Stäheli <mistrdave@gmail.com>
Signed-off-by: David Stäheli <mistrdave@gmail.com>
Signed-off-by: David Stäheli <mistrdave@gmail.com>
Signed-off-by: David Stäheli <mistrdave@gmail.com>
@mistadave mistadave force-pushed the pathfilter-multiple-inverse branch from 1235cc9 to 099c56d Compare June 29, 2023 10:24
@drakkan drakkan merged commit f78e4b0 into drakkan:main Jul 2, 2023
@drakkan
Copy link
Owner

drakkan commented Jul 2, 2023

checkEventGroupConditionPatterns seems not consistent, for example if you have something like this

Patterns := []dataprovider.ConditionPattern{
		{
			Pattern:      "group1",
			InverseMatch: true,
		},
		{
			Pattern:      "group2",
			InverseMatch: true,
		},
	}

groups = []sdk.GroupMapping{
		{
			Name: "group1",
			Type: sdk.GroupTypePrimary,
		},
		{
			Name: "group4",
			Type: sdk.GroupTypePrimary,
		},
	}

I think the check should return false because groups must not contains group1 and group4, with your changes it returns true. I'll try to fix myself

@drakkan drakkan mentioned this pull request Jul 2, 2023
@drakkan
Copy link
Owner

drakkan commented Apr 18, 2024

Hello @mistadave

thank you again for this contribution. We have recently updated our contribution policy and we now require signing a CLA. Agreeing to the CLA clarifies your rights as a contributor and at the same time protects SFTPGo and its users.

More details here

You can use the following URL to sign the CLA

https://cla-assistant.io/drakkan/sftpgo?pullRequest=1332

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants