(artifact Artifact)
| 301 | } |
| 302 | |
| 303 | func ValidateArtifact(artifact Artifact) error { |
| 304 | artifact.GOOS = normalizeGOOS(artifact.GOOS) |
| 305 | artifact.GOARCH = normalizeGOARCH(artifact.GOARCH) |
| 306 | artifact.URL = strings.TrimSpace(artifact.URL) |
| 307 | artifact.SHA256 = strings.ToLower(strings.TrimSpace(artifact.SHA256)) |
| 308 | if artifact.GOOS == "" { |
| 309 | return fmt.Errorf("missing goos") |
| 310 | } |
| 311 | if artifact.GOARCH == "" { |
| 312 | return fmt.Errorf("missing goarch") |
| 313 | } |
| 314 | if artifact.URL == "" { |
| 315 | return fmt.Errorf("missing url") |
| 316 | } |
| 317 | parsed, errParse := url.Parse(artifact.URL) |
| 318 | if errParse != nil || parsed.Scheme == "" || parsed.Host == "" { |
| 319 | return fmt.Errorf("invalid artifact url") |
| 320 | } |
| 321 | if parsed.Scheme != "https" && parsed.Scheme != "http" { |
| 322 | return fmt.Errorf("artifact url must use http or https") |
| 323 | } |
| 324 | if hasSensitiveQueryParameter(parsed) { |
| 325 | return fmt.Errorf("artifact url contains sensitive query parameter") |
| 326 | } |
| 327 | if artifact.SHA256 == "" { |
| 328 | return fmt.Errorf("missing sha256") |
| 329 | } |
| 330 | if len(artifact.SHA256) != sha256.Size*2 { |
| 331 | return fmt.Errorf("invalid sha256 length") |
| 332 | } |
| 333 | if _, errDecode := hex.DecodeString(artifact.SHA256); errDecode != nil { |
| 334 | return fmt.Errorf("invalid sha256: %w", errDecode) |
| 335 | } |
| 336 | if artifact.Size < 0 { |
| 337 | return fmt.Errorf("invalid size") |
| 338 | } |
| 339 | return nil |
| 340 | } |
| 341 | |
| 342 | func PluginPlatforms(plugin Plugin) []Platform { |
| 343 | if PluginInstallType(plugin) != InstallTypeDirect { |
no test coverage detected