Repository navigation
Let a .v* extension config key apply to any extension version #10
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
Open
vvoland
wants to merge
2
commits into
moby:main
Choose a base branch
from
vvoland:wildcard-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // SPDX-FileCopyrightText: Copyright The Moby Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package extensions | ||
|
|
||
| import "fmt" | ||
|
|
||
| // Config is parsed per-extension configuration delivered by id to Init or the | ||
| // out-of-process startup handshake. | ||
| type Config = map[string]any | ||
|
|
||
| // ValidateExtensionConfigKey reports whether key can key extension | ||
| // configuration. | ||
| // A key is either a full extension id such as org.example.myext.v1, or an | ||
| // extension name without a version, such as org.example.myext, which applies | ||
| // to every version of that extension. | ||
| func ValidateExtensionConfigKey(key ExtensionID) error { | ||
| if ValidateExtensionID(key) != nil && !validExtensionName(string(key)) { | ||
| return fmt.Errorf("invalid extension config key %q: want an extension id like org.example.myext.v1, or a name like org.example.myext for any version", key) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // LookupConfig returns the configuration for extension id from configs. | ||
| // An entry keyed by id takes precedence over one keyed by the extension name, | ||
| // which is id without its version. | ||
| func LookupConfig(configs map[ExtensionID]Config, id ExtensionID) Config { | ||
| if config, ok := configs[id]; ok { | ||
| return config | ||
| } | ||
|
|
||
| name, ok := cutExtensionVersion(id) | ||
| if !ok { | ||
| return nil | ||
| } | ||
|
|
||
| return configs[ExtensionID(name)] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // SPDX-FileCopyrightText: Copyright The Moby Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package extensions | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "gotest.tools/v3/assert" | ||
| ) | ||
|
|
||
| func TestValidateExtensionConfigKey(t *testing.T) { | ||
| valid := []ExtensionID{ | ||
| "org.example.myext.v1", | ||
| "org.example.myext", | ||
| "org.example.s3-volume", | ||
| "org.example.v1", | ||
| } | ||
| for _, key := range valid { | ||
| if err := ValidateExtensionConfigKey(key); err != nil { | ||
| t.Errorf("ValidateExtensionConfigKey(%q) = %v, want nil", key, err) | ||
| } | ||
| } | ||
|
|
||
| invalid := []ExtensionID{ | ||
| "", | ||
| "foo", // only one name segment | ||
| "org.example.myext.v*", // wildcard | ||
| "org.example.myext.*", // wildcard | ||
| "org.example.myext.v1.v2", // name ends in a version | ||
| "Org.Example.myext", // uppercase | ||
| "org.example/evil", // path separator | ||
| } | ||
| for _, key := range invalid { | ||
| if err := ValidateExtensionConfigKey(key); err == nil { | ||
| t.Errorf("ValidateExtensionConfigKey(%q) = nil, want error", key) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestLookupConfig(t *testing.T) { | ||
| exact := Config{"source": "exact"} | ||
| anyVersion := Config{"source": "any version"} | ||
| configs := map[ExtensionID]Config{ | ||
| "org.example.foo.v1": exact, | ||
| "org.example.foo": anyVersion, | ||
| "org.example.bar.v1": {"source": "bar"}, | ||
| } | ||
|
|
||
| for _, tc := range []struct { | ||
| name string | ||
| id ExtensionID | ||
| want Config | ||
| }{ | ||
| {name: "exact id takes precedence", id: "org.example.foo.v1", want: exact}, | ||
| {name: "name key covers other versions", id: "org.example.foo.v2", want: anyVersion}, | ||
| {name: "other extension without a key", id: "org.example.baz.v1", want: nil}, | ||
| {name: "exact key does not cover other versions", id: "org.example.bar.v2", want: nil}, | ||
| {name: "name prefix does not match", id: "org.example.foobar.v1", want: nil}, | ||
| {name: "name key does not cover nested names", id: "org.example.foo.runtime.v1", want: nil}, | ||
| } { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| assert.DeepEqual(t, LookupConfig(configs, tc.id), tc.want) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, having (e.g.) both
com.example.other.runtime.v1andcom.example.other.runtimemakes one config apply to v1, and the other forcom.example.other.runtime.v0,com.example.other.runtime.v2,com.example.other.runtime.v3(any other version), right?Probably works, yes; alternative could be to not allow a mix of versioned and non-versioned for the same match. (Not sure if that's better/clearer though).
Mostly thinking there if there's situations where I would have multiple versions of the same extension installed (could we come up with reasons for that? do we / do we want to allow that?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there's a reason to allow multiple versions of the same extension running at the same time.
For mixing.. I'm thinking if it would make sense to merge them - so the "versionless" kinda acts as a base, and then the per version can adjust it. But I don't think we should do it now.