-
Couldn't load subscription status.
- Fork 52
feat: added plugin metadata linter #468
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
Conversation
| toolchain go1.24.4 | ||
|
|
||
| require ( | ||
| github.com/Masterminds/semver v1.5.0 |
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.
Callout: Used to validate against the provided min CLI version defined in the metadata and the allowed min CLI version. The package is used in the core CLI.
49639c2 to
47399b3
Compare
| github.com/Masterminds/semver v1.5.0 | ||
| github.com/fatih/color v1.7.1-0.20180516100307-2d684516a886 | ||
| github.com/fatih/structs v1.0.1-0.20171020064819-f5faa72e7309 | ||
| github.com/go-playground/validator/v10 v10.28.0 |
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.
Callout: This package is validation library to support validation using struct tags.
Widely used package under the MIT license. Over 200+ contributors and the last release was 4 days ago.
47399b3 to
2d399b4
Compare
2d399b4 to
7243b11
Compare
docs/plugin_developer_guide.md
Outdated
| - _Commands_: The array of `plugin.Commands` to register the plug-in commands. | ||
| - _Alias_: Alias of the Alias usually is a short name of the command. | ||
| - _Command.Flags_: The command flags (options) which will be displayed as a part of help output of the command. | ||
| - _Alias_ (*optional*): Alias of the Alias usually is a short name of the command. |
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.
Alias of the Alias does not make sense. This pre-existed this PR.
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.
Yeah let me fix that here.
| Namespace string // full qualified name of the command's namespace | ||
| Name string // name of the command | ||
| Namespace string `validate:"required"` // full qualified name of the command's namespace | ||
| Name string `validate:"required,ne=--version"` // name of the command |
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.
Is this a work-around? --version was being interpreted as a command name?
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.
Yeah it was. We need to tell the plug-in devs to remove that as a command.
plugin/plugin.go
Outdated
| type Flag struct { | ||
| Name string // name of the option | ||
| Description string // description of the option | ||
| Name string `validate:"required,excludesall=<>"` // name of the option |
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.
Can you give an example where this is necessary?
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.
Yeah I will add that as comment here. Basically, it prevents flag names like <invalidValue> which is not correct.
| return err.Error() | ||
| } | ||
| case "mincliversion": | ||
| if err := validateCliVersionMinimum(fieldErr.Value().(VersionType), fieldErr.Param()); err != nil { |
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, in the case of mincliversion, fieldErr.Param() will be the minimum value of core CLI allowed (2.0.0)?
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.
Correct
| if minErr != nil { | ||
| return minErr | ||
| } | ||
| specifiedVersion, verErr := semver.NewVersion(versionType.String()) |
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.
specifiedVersion is the min core CLI version the plug-in has defined in its metadata?
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.
Yes
|
@Aerex Please see the questions above, otherwise looking great. |
Context
The purpose of this PR is to add validation for the
plugin.PluginMetadatastruct using struct tags. These tags will validate specific properties on the plugin metadata. They are as follows:PluginMetadata.NamePluginMetadata.VersionPluginMetadata.MinCliVersionMust be at least 2.0.0
PluginMetadata.Namespaces[]There must at least be one namespace
PluginMetadata.Namespaces[].NamePluginMetadata.Commands[]There must be at least one command
PluginMetadata.Commands[].NameNo command name should be called --version
PluginMetadata.Commands[].DescriptionPluginMetadata.Commands[].Usage+PluginMetadata.Commands[].Flags[].NameNo UTF-16 characters allowed
PluginMetadata.Commands[].Flags[].DescriptionThe
Validatorpackage was created to provide a public interface for validating and retrieving validation errors on any given plugin metadata. If there are any errors found, an array ofValidationErrorobjects will be returned where each object represents a single violation. A plugin can have multiple violations on its metadata.Note
+: The usage text will validate against a few basic rules which can be expanded upon in the future. These rules are as follows:
<,[,[) must be closed[arguments]or[options...]). All arguments and flags should be explicit listed in the usage textIn addition, the Plugin Developer Guide has been updated to include more details on what is required and optional when defining a plugin metadata.