| 199 | } |
| 200 | |
| 201 | func (s *Store) GetArtifact(identifier string) (string, error) { |
| 202 | // Load the artifact image from the local store. |
| 203 | // Any error here is propagated so callers can decide whether to re-fetch. |
| 204 | img, err := s.GetArtifactImage(identifier) |
| 205 | if err != nil { |
| 206 | return "", err |
| 207 | } |
| 208 | |
| 209 | // Extract layers from the OCI image. |
| 210 | // A failure indicates an invalid or partially written image. |
| 211 | layers, err := img.Layers() |
| 212 | if err != nil { |
| 213 | return "", ErrStoreCorrupted |
| 214 | } |
| 215 | |
| 216 | // An artifact without layers is considered invalid. |
| 217 | // This should never happen for a correctly stored agent. |
| 218 | if len(layers) == 0 { |
| 219 | return "", ErrStoreCorrupted |
| 220 | } |
| 221 | |
| 222 | // Agents are expected to be stored in the first layer. |
| 223 | // If decompression fails, the local store is considered corrupted. |
| 224 | layer := layers[0] |
| 225 | rc, err := layer.Uncompressed() |
| 226 | if err != nil { |
| 227 | return "", ErrStoreCorrupted |
| 228 | } |
| 229 | defer rc.Close() |
| 230 | |
| 231 | // Read the full layer content into memory. |
| 232 | // Any I/O error here means the artifact cannot be trusted. |
| 233 | var buf bytes.Buffer |
| 234 | if _, err := io.Copy(&buf, rc); err != nil { |
| 235 | return "", ErrStoreCorrupted |
| 236 | } |
| 237 | |
| 238 | return buf.String(), nil |
| 239 | } |
| 240 | |
| 241 | // ListArtifacts returns a list of all stored artifacts |
| 242 | func (s *Store) ListArtifacts() ([]ArtifactMetadata, error) { |