(plugin fetcher)
| 44 | ) |
| 45 | |
| 46 | func getPluginNameFromContent(plugin fetcher) (string, error) { |
| 47 | content, err := plugin.Fetch() |
| 48 | if err != nil { |
| 49 | return "", err |
| 50 | } |
| 51 | m := map[string]any{} |
| 52 | if err := json.Unmarshal(content, &m); err != nil { |
| 53 | return "", err |
| 54 | } |
| 55 | name, ok := m["name"].(string) |
| 56 | if !ok || name == "" { |
| 57 | return "", |
| 58 | fmt.Errorf("%w in plugin %s", errNameMissing, plugin.LockfileKey()) |
| 59 | } |
| 60 | if !nameRegex.MatchString(name) { |
| 61 | return "", usererr.New( |
| 62 | "plugin %s has an invalid name %q. Name must match %s", |
| 63 | plugin.LockfileKey(), name, nameRegex, |
| 64 | ) |
| 65 | } |
| 66 | return name, nil |
| 67 | } |
no test coverage detected