| 183 | } |
| 184 | |
| 185 | func readSnapshotSource(input []byte) (app.SnapshotSpec, error) { |
| 186 | // Define a temporary struct to capture the wrapped spec so we |
| 187 | // can read snapshot data correctly from a cluster record |
| 188 | var wrapper struct { |
| 189 | Spec *app.SnapshotSpec `yaml:"spec"` |
| 190 | } |
| 191 | |
| 192 | // Attempt to unmarshal into the wrapper to check for cluster record format |
| 193 | if err := yaml.Unmarshal(input, &wrapper); err == nil && wrapper.Spec != nil { |
| 194 | // If successful and spec exists, return it directly |
| 195 | log.Debugf("Read application snapshot from cluster record format") |
| 196 | return *wrapper.Spec, nil |
| 197 | } |
| 198 | |
| 199 | // If we didn't find a snapshot under the .spec top level key then |
| 200 | // assume we're looking at the bare snapshot data |
| 201 | var spec app.SnapshotSpec |
| 202 | if err := yaml.Unmarshal(input, &spec); err != nil { |
| 203 | log.Debugf("Problem parsing application snapshot from file %s", input) |
| 204 | return app.SnapshotSpec{}, fmt.Errorf("unable to parse Snapshot specification from %s: %w", input, err) |
| 205 | } |
| 206 | |
| 207 | log.Debugf("Read application snapshot from file %s", input) |
| 208 | return spec, nil |
| 209 | } |
| 210 | |
| 211 | // For an image index, remove the original component and replace it with an expanded component with all its image manifests |
| 212 | // Do not raise an error if the image is inaccessible, it will be handled as a violation when evaluated against the policy |