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

Method GetContainer

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

GetContainer returns a container by ID with host and image info.

(ctx context.Context, id string)

Source from the content-addressed store, hash-verified

195
196// GetContainer returns a container by ID with host and image info.
197func (s *DockerStore) GetContainer(ctx context.Context, id string) (*ContainerDetail, error) {
198 d := s.db.DB(ctx)
199 c, err := d.Queries.GetContainerByID(ctx, id)
200 if err != nil {
201 return nil, err
202 }
203
204 hostRows, _ := d.Queries.GetDockerHostsByIDs(ctx, []string{c.HostID})
205 var hostPtr *HostInfo
206 if len(hostRows) > 0 {
207 hostPtr = dockerHostDetailRowToHostInfo(hostRows[0])
208 }
209
210 var dockerImage *models.DockerImage
211 var imageUpdates []models.DockerImageUpdate
212 var similar []models.DockerContainer
213 if c.ImageID != nil && *c.ImageID != "" {
214 img, err := d.Queries.GetImageByID(ctx, *c.ImageID)
215 if err == nil {
216 dockerImage = ptr(dbDockerImageToModel(img))
217 updates, _ := d.Queries.GetImageUpdatesByImageID(ctx, *c.ImageID)
218 imageUpdates = make([]models.DockerImageUpdate, len(updates))
219 for i := range updates {
220 imageUpdates[i] = dbDockerImageUpdateToModel(updates[i])
221 }
222 }
223 sim, _ := d.Queries.GetContainersByImageID(ctx, db.GetContainersByImageIDParams{ImageID: c.ImageID, ID: id})
224 similar = make([]models.DockerContainer, len(sim))
225 for i := range sim {
226 similar[i] = dbDockerContainerToModel(sim[i])
227 }
228 }
229
230 return &ContainerDetail{
231 Container: dbDockerContainerToModel(c),
232 Host: hostPtr,
233 DockerImages: dockerImage,
234 DockerImageUpdates: imageUpdates,
235 SimilarContainers: similar,
236 }, nil
237}
238
239func ptr[T any](v T) *T { return &v }
240

Callers

nothing calls this directly

Calls 11

ptrFunction · 0.85
dbDockerImageToModelFunction · 0.85
dbDockerContainerToModelFunction · 0.85
DBMethod · 0.65
GetContainerByIDMethod · 0.65
GetDockerHostsByIDsMethod · 0.65
GetImageByIDMethod · 0.65

Tested by

no test coverage detected