| 278 | } |
| 279 | |
| 280 | func (c *client) GetByName(name string) (string, *Metadata, error) { |
| 281 | pluginFolder, err := c.PluginFolder() |
| 282 | if err != nil { |
| 283 | return "", nil, err |
| 284 | } |
| 285 | |
| 286 | plugins, err := os.ReadDir(pluginFolder) |
| 287 | if err != nil { |
| 288 | if os.IsNotExist(err) { |
| 289 | return "", nil, nil |
| 290 | } |
| 291 | |
| 292 | return "", nil, err |
| 293 | } |
| 294 | |
| 295 | for _, dirEntry := range plugins { |
| 296 | plugin, err := dirEntry.Info() |
| 297 | if err != nil { |
| 298 | continue |
| 299 | } |
| 300 | |
| 301 | metadataFileContents, err := os.ReadFile(filepath.Join(pluginFolder, plugin.Name(), pluginYaml)) |
| 302 | if os.IsNotExist(err) { |
| 303 | _ = os.RemoveAll(filepath.Join(pluginFolder, plugin.Name())) |
| 304 | continue |
| 305 | } |
| 306 | |
| 307 | metadata := Metadata{} |
| 308 | err = yaml.Unmarshal(metadataFileContents, &metadata) |
| 309 | if err != nil { |
| 310 | c.log.Warnf("Error parsing plugin.yaml for plugin %s: %v", plugin, err) |
| 311 | continue |
| 312 | } |
| 313 | |
| 314 | if metadata.Name == name { |
| 315 | decoded, err := Decode(plugin.Name()) |
| 316 | if err != nil { |
| 317 | return "", nil, errors.Wrap(err, "decode plugin path") |
| 318 | } |
| 319 | |
| 320 | metadata.PluginFolder = filepath.Join(pluginFolder, plugin.Name()) |
| 321 | return string(decoded), &metadata, nil |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | return "", nil, nil |
| 326 | } |
| 327 | |
| 328 | func (c *client) Get(path string) (*Metadata, error) { |
| 329 | pluginFolder, err := c.PluginFolder() |