GetPluginName extracts the plugin name from an OCI reference using proper reference parsing
(source string)
| 182 | |
| 183 | // GetPluginName extracts the plugin name from an OCI reference using proper reference parsing |
| 184 | func GetPluginName(source string) (string, error) { |
| 185 | ref, err := newReference(source) |
| 186 | if err != nil { |
| 187 | return "", fmt.Errorf("invalid OCI reference: %w", err) |
| 188 | } |
| 189 | |
| 190 | // Extract plugin name from the repository path |
| 191 | // e.g., "ghcr.io/user/plugin-name:v1.0.0" -> Repository: "user/plugin-name" |
| 192 | repository := ref.Repository |
| 193 | if repository == "" { |
| 194 | return "", errors.New("invalid OCI reference: missing repository") |
| 195 | } |
| 196 | |
| 197 | // Get the last part of the repository path as the plugin name |
| 198 | parts := strings.Split(repository, "/") |
| 199 | pluginName := parts[len(parts)-1] |
| 200 | |
| 201 | if pluginName == "" { |
| 202 | return "", fmt.Errorf("invalid OCI reference: cannot determine plugin name from repository %s", repository) |
| 203 | } |
| 204 | |
| 205 | return pluginName, nil |
| 206 | } |
| 207 | |
| 208 | // PullPluginOptWithProv configures the pull to fetch provenance data |
| 209 | func PullPluginOptWithProv(withProv bool) PluginPullOption { |
searching dependent graphs…