InstallToTargets installs an item into multiple target agents in one call. It downloads the source repo once, reads the resource content, then writes it to each target. Install status is recorded per successful target.
(ctx context.Context, kind, installKey string, targetApps []string)
| 366 | // It downloads the source repo once, reads the resource content, then writes it |
| 367 | // to each target. Install status is recorded per successful target. |
| 368 | func (svc *Service) InstallToTargets(ctx context.Context, kind, installKey string, targetApps []string) error { |
| 369 | if len(targetApps) == 0 { |
| 370 | return fmt.Errorf("metadata: no target agents specified") |
| 371 | } |
| 372 | item, err := svc.store.GetItem(ctx, kind, installKey) |
| 373 | if err != nil { |
| 374 | return fmt.Errorf("metadata: item not found: %w", err) |
| 375 | } |
| 376 | |
| 377 | entityKind := entities.Kind(item.Kind) |
| 378 | content := svc.fetchResourceContent(item) |
| 379 | |
| 380 | entity := entities.Entity{ |
| 381 | Kind: entityKind, |
| 382 | Name: item.Name, |
| 383 | Description: item.Description, |
| 384 | Content: content, |
| 385 | Repo: &entities.RepoRef{ |
| 386 | Owner: item.RepoOwner, |
| 387 | Name: item.RepoName, |
| 388 | Branch: item.RepoBranch, |
| 389 | Path: item.ItemPath, |
| 390 | }, |
| 391 | } |
| 392 | |
| 393 | var installed []string |
| 394 | var lastErr error |
| 395 | for _, app := range targetApps { |
| 396 | if _, err := entities.InstallToApp(entity, entityKind, app); err != nil { |
| 397 | lastErr = fmt.Errorf("metadata: install to %s: %w", app, err) |
| 398 | continue |
| 399 | } |
| 400 | installed = append(installed, app) |
| 401 | } |
| 402 | if len(installed) == 0 { |
| 403 | return lastErr |
| 404 | } |
| 405 | if err := svc.store.MarkInstalled(ctx, kind, installKey, strings.Join(installed, ",")); err != nil { |
| 406 | return err |
| 407 | } |
| 408 | return lastErr |
| 409 | } |
| 410 | |
| 411 | // UninstallFromTargets removes an entity from the specified apps and updates |
| 412 | // the metadata store's installed status. |
no test coverage detected