Skip to content

Commit 4d1bf8b

Browse files
committed
cli-plugins: do not change schema version
Per discussion on PR.
1 parent 5a0014a commit 4d1bf8b

File tree

4 files changed

+15
-95
lines changed

4 files changed

+15
-95
lines changed

cli-plugins/manager/candidate_test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,10 @@ func TestValidateCandidate(t *testing.T) {
6565
{name: "builtin alias", c: &fakeCandidate{path: builtinAlias}, invalid: `plugin "alias" duplicates an alias of builtin command "builtin"`},
6666
{name: "fetch failure", c: &fakeCandidate{path: goodPluginPath, exec: false}, invalid: fmt.Sprintf("failed to fetch metadata: faked a failure to exec %q", goodPluginPath)},
6767
{name: "metadata not json", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `xyzzy`}, invalid: "invalid character"},
68-
{name: "empty schemaversion", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{}`}, invalid: `plugin metadata failed validation: "SchemaVersion" field is required`},
69-
{name: "invalid schemaversion", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "xyzzy"}`}, invalid: `plugin metadata failed validation: unknown schema version: xyzzy`},
70-
{name: "no vendor", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0"}`}, invalid: `plugin metadata failed validation: "Vendor" field is required`},
71-
{
72-
name: "empty vendor", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0", "Vendor": ""}`},
73-
invalid: `plugin metadata failed validation: "Vendor" field is required`,
74-
},
68+
{name: "empty schemaversion", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{}`}, invalid: `plugin SchemaVersion "" is not valid`},
69+
{name: "invalid schemaversion", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "xyzzy"}`}, invalid: `plugin SchemaVersion "xyzzy" is not valid`},
70+
{name: "no vendor", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0"}`}, invalid: "plugin metadata does not define a vendor"},
71+
{name: "empty vendor", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0", "Vendor": ""}`}, invalid: "plugin metadata does not define a vendor"},
7572
// This one should work
7673
{name: "valid", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0", "Vendor": "e2e-testing"}`}},
7774
{name: "experimental + allowing experimental", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: metaExperimental}},

cli-plugins/manager/metadata.go

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package manager
22

3-
import "fmt"
4-
53
const (
64
// NamePrefix is the prefix required on all plugin binary names
75
NamePrefix = "docker-"
@@ -14,44 +12,18 @@ const (
1412

1513
// Metadata provided by the plugin.
1614
type Metadata struct {
17-
// SchemaVersion describes the version of this struct. Mandatory.
15+
// SchemaVersion describes the version of this struct. Mandatory, must be "0.1.0"
1816
SchemaVersion string `json:",omitempty"`
19-
// Name of the plugin.
17+
// Vendor is the name of the plugin vendor. Mandatory
18+
Vendor string `json:",omitempty"`
19+
// Name is the name of the plugin.
2020
//
21-
// Mandatory if SchemaVersion >= 0.2.0.
21+
// For compatibility reasons, this field is not mandatory.
2222
Name string `json:",omitempty"`
23-
// Vendor is the name of the plugin vendor. Mandatory.
24-
Vendor string `json:",omitempty"`
2523
// Version is the optional version of this plugin.
2624
Version string `json:",omitempty"`
2725
// ShortDescription should be suitable for a single line help message.
2826
ShortDescription string `json:",omitempty"`
2927
// URL is a pointer to the plugin's homepage.
3028
URL string `json:",omitempty"`
3129
}
32-
33-
// validateMetadata returns an error if any fields are missing or invalid for the
34-
// specified SchemaVersion.
35-
func validateMetadata(meta *Metadata) error {
36-
if meta.SchemaVersion == "" {
37-
return fmt.Errorf("%q field is required", "SchemaVersion")
38-
}
39-
40-
switch meta.SchemaVersion {
41-
case "0.1.0":
42-
// clear fields not supported by version
43-
meta.Name = ""
44-
case "0.2.0":
45-
if meta.Name == "" {
46-
return fmt.Errorf("%q field is required", "Name")
47-
}
48-
default:
49-
return NewPluginError("unknown schema version: %s", meta.SchemaVersion)
50-
}
51-
52-
if meta.Vendor == "" {
53-
return fmt.Errorf("%q field is required", "Vendor")
54-
}
55-
56-
return nil
57-
}

cli-plugins/manager/metadata_test.go

Lines changed: 0 additions & 51 deletions
This file was deleted.

cli-plugins/manager/plugin.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,13 @@ func newPlugin(c Candidate, cmds []*cobra.Command) (Plugin, error) {
9090
p.Err = wrapAsPluginError(err, "invalid metadata")
9191
return p, nil
9292
}
93-
94-
if err := validateMetadata(&p.Metadata); err != nil {
95-
p.Err = wrapAsPluginError(err, "plugin metadata failed validation")
93+
if p.Metadata.SchemaVersion != "0.1.0" {
94+
p.Err = NewPluginError("plugin SchemaVersion %q is not valid, must be 0.1.0", p.Metadata.SchemaVersion)
95+
return p, nil
96+
}
97+
if p.Metadata.Vendor == "" {
98+
p.Err = NewPluginError("plugin metadata does not define a vendor")
9699
return p, nil
97100
}
98-
99101
return p, nil
100102
}

0 commit comments

Comments
 (0)