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

feat: normalize path for creation rules #1523

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

Conversation

Prince213
Copy link

Fixes #1036.

This may be a breaking change. 🤔

@devstein devstein requested a review from a team June 10, 2024 23:16
Copy link
Contributor

@felixfontein felixfontein 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 your contribution!

@@ -368,6 +368,8 @@ func parseCreationRuleForFile(conf *configFile, confPath, filePath string, kmsEn

// compare file path relative to path of config file
filePath = strings.TrimPrefix(filePath, configDir+string(filepath.Separator))
// replace \ with /
filePath = filepath.ToSlash(filePath)
Copy link
Contributor

Choose a reason for hiding this comment

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

For everyone using regexes that support both Windows and Unix paths, this is not a breaking change. But for users that use Windows paths exclusively and wrote their regexes that way, it's a breaking change since their regexes won't work anymore.

To avoid breaking changes, we'll have to (for some time) keep the old behavior, but warn the user if it will change in the future. So better do something like:

Suggested change
filePath = filepath.ToSlash(filePath)
filePathAlt := filepath.ToSlash(filePath)

here, and below before calling reg.MatchString(filePath) do newMatch := reg.MatchString(filePathAlt) and then emit a warning if it's value is different from reg.MatchString(filePath).

Copy link
Author

Choose a reason for hiding this comment

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

Let's also add a option to silence that warning (by opting in to the new behavior).

Copy link
Contributor

Choose a reason for hiding this comment

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

In Ansible we usually proceed as follows:

  1. Add a new option that allows to select the behavior. The default is the old behavior.
  2. A version later, deprecate the option's default value - i.e. start warning the user if they didn't specify a value for that option and if the change to the new default would produce a change. Then users have time to figure out whether they prefer the old or new behavior, and can explicitly set the option to the value they prefer (and as soon as it has a value, there will be no more warnings).
  3. Eventually flip the default of the option to the new value.

@getsops/maintainers what do you think, and what would you prefer?

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.

path_regex doesn't normalize paths with filepath.ToSlash
2 participants