Run applies all resources found in the given path (file or directory)
(ctx context.Context, path string)
| 60 | |
| 61 | // Run applies all resources found in the given path (file or directory) |
| 62 | func (a *Apply) Run(ctx context.Context, path string) ([]*ApplyResult, error) { |
| 63 | docs, err := ParseYAMLPath(path) |
| 64 | if err != nil { |
| 65 | return nil, err |
| 66 | } |
| 67 | |
| 68 | // Apply contracts |
| 69 | var results []*ApplyResult |
| 70 | for _, doc := range docs { |
| 71 | switch doc.Kind { |
| 72 | case KindContract: |
| 73 | changed, err := ApplyContractFromRawData(ctx, a.cfg.CPConnection, doc.RawData) |
| 74 | if err != nil { |
| 75 | return results, fmt.Errorf("%s/%s: %w", doc.Kind, doc.Name, err) |
| 76 | } |
| 77 | results = append(results, &ApplyResult{Kind: doc.Kind, Name: doc.Name, Changed: changed}) |
| 78 | default: |
| 79 | return results, fmt.Errorf("unsupported kind %q", doc.Kind) |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | return results, nil |
| 84 | } |
| 85 | |
| 86 | // ParseYAMLPath collects all YAML files from a path (file or directory), |
| 87 | // reads them, and splits multi-document files into individual YAMLDoc entries. |