MCPcopy Index your code
hub / github.com/PatchMon/PatchMon / GetImage

Method GetImage

server-source-code/internal/store/docker.go:339–372  ·  view source on GitHub ↗

GetImage returns an image by ID with containers and hosts.

(ctx context.Context, id string)

Source from the content-addressed store, hash-verified

337
338// GetImage returns an image by ID with containers and hosts.
339func (s *DockerStore) GetImage(ctx context.Context, id string) (*ImageDetail, error) {
340 d := s.db.DB(ctx)
341 img, err := d.Queries.GetImageByID(ctx, id)
342 if err != nil {
343 return nil, err
344 }
345
346 containers, _ := d.Queries.GetContainersByImageIDAll(ctx, &id)
347 hostIDs := make(map[string]bool)
348 for _, c := range containers {
349 hostIDs[c.HostID] = true
350 }
351 ids := make([]string, 0, len(hostIDs))
352 for hid := range hostIDs {
353 ids = append(ids, hid)
354 }
355
356 var hosts []HostInfo
357 if len(ids) > 0 {
358 hostRows, _ := d.Queries.GetDockerHostsMinimalByIDs(ctx, ids)
359 hosts = make([]HostInfo, len(hostRows))
360 for i := range hostRows {
361 hosts[i] = *dockerHostRowToHostInfo(hostRows[i])
362 }
363 }
364
365 return &ImageDetail{
366 Image: dbDockerImageToModel(img),
367 Hosts: hosts,
368 TotalContainers: len(containers),
369 TotalHosts: len(hosts),
370 DockerContainers: convertContainers(containers),
371 }, nil
372}
373
374func convertContainers(dc []db.DockerContainer) []models.DockerContainer {
375 out := make([]models.DockerContainer, len(dc))

Callers

nothing calls this directly

Calls 7

dockerHostRowToHostInfoFunction · 0.85
dbDockerImageToModelFunction · 0.85
convertContainersFunction · 0.85
DBMethod · 0.65
GetImageByIDMethod · 0.65

Tested by

no test coverage detected