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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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?


var rule *creationRule

Expand Down
7 changes: 7 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,13 @@ func TestLoadConfigFileWithOnlyDestinationRules(t *testing.T) {
assert.Nil(t, err)
}

func TestLoadConfigFileWithBackslashInPath(t *testing.T) {
conf, err := parseCreationRuleForFile(parseConfigFile(sampleConfigWithPath, t), "/conf/path", "foo\\bar2000", nil)
assert.Nil(t, err)
assert.Equal(t, "2", conf.KeyGroups[0][0].ToString())
assert.Equal(t, "1", conf.KeyGroups[0][1].ToString())
}

func TestKeyGroupsForFile(t *testing.T) {
conf, err := parseCreationRuleForFile(parseConfigFile(sampleConfig, t), "/conf/path", "foobar2000", nil)
assert.Nil(t, err)
Expand Down
Loading