()
| 69 | } |
| 70 | |
| 71 | func (m *MetadataLegacy) Validate() error { |
| 72 | if !validPluginName.MatchString(m.Name) { |
| 73 | return fmt.Errorf("invalid plugin name %q: must contain only a-z, A-Z, 0-9, _ and -", m.Name) |
| 74 | } |
| 75 | |
| 76 | if m.Version != "" && !isValidSemver(m.Version) { |
| 77 | return fmt.Errorf("invalid plugin version %q: must be valid semver", m.Version) |
| 78 | } |
| 79 | |
| 80 | m.Usage = sanitizeString(m.Usage) |
| 81 | |
| 82 | if len(m.PlatformCommand) > 0 && len(m.Command) > 0 { |
| 83 | return errors.New("both platformCommand and command are set") |
| 84 | } |
| 85 | |
| 86 | if len(m.PlatformHooks) > 0 && len(m.Hooks) > 0 { |
| 87 | return errors.New("both platformHooks and hooks are set") |
| 88 | } |
| 89 | |
| 90 | // Validate downloader plugins |
| 91 | for i, downloader := range m.Downloaders { |
| 92 | if downloader.Command == "" { |
| 93 | return fmt.Errorf("downloader %d has empty command", i) |
| 94 | } |
| 95 | if len(downloader.Protocols) == 0 { |
| 96 | return fmt.Errorf("downloader %d has no protocols", i) |
| 97 | } |
| 98 | for j, protocol := range downloader.Protocols { |
| 99 | if protocol == "" { |
| 100 | return fmt.Errorf("downloader %d has empty protocol at index %d", i, j) |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | return nil |
| 106 | } |
| 107 | |
| 108 | // sanitizeString normalize spaces and removes non-printable characters. |
| 109 | func sanitizeString(str string) string { |
no test coverage detected