MCPcopy Create free account
hub / github.com/PatchMon/PatchMon / ListContainers

Method ListContainers

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

ListContainers returns containers with host info.

(ctx context.Context, params ContainerListParams)

Source from the content-addressed store, hash-verified

119
120// ListContainers returns containers with host info.
121func (s *DockerStore) ListContainers(ctx context.Context, params ContainerListParams) ([]ContainerWithHost, int, error) {
122 d := s.db.DB(ctx)
123 skip, take := validatePagination(params.Page, params.Limit, 10000)
124
125 arg := db.ListContainersParams{Limit: safeconv.ClampToInt32(take), Offset: safeconv.ClampToInt32(skip)}
126 if params.Status != "" {
127 arg.Status = &params.Status
128 }
129 if params.HostID != "" {
130 arg.HostID = &params.HostID
131 }
132 if params.ImageID != "" {
133 arg.ImageID = &params.ImageID
134 }
135 if params.Search != "" {
136 arg.Search = &params.Search
137 }
138
139 countArg := db.CountContainersParams{}
140 if params.Status != "" {
141 countArg.Status = &params.Status
142 }
143 if params.HostID != "" {
144 countArg.HostID = &params.HostID
145 }
146 if params.ImageID != "" {
147 countArg.ImageID = &params.ImageID
148 }
149 if params.Search != "" {
150 countArg.Search = &params.Search
151 }
152
153 total, err := d.Queries.CountContainers(ctx, countArg)
154 if err != nil {
155 return nil, 0, err
156 }
157
158 containers, err := d.Queries.ListContainers(ctx, arg)
159 if err != nil {
160 return nil, 0, err
161 }
162
163 if len(containers) == 0 {
164 return []ContainerWithHost{}, int(total), nil
165 }
166
167 hostIDs := make(map[string]bool)
168 for _, c := range containers {
169 hostIDs[c.HostID] = true
170 }
171 ids := make([]string, 0, len(hostIDs))
172 for id := range hostIDs {
173 ids = append(ids, id)
174 }
175
176 hosts, err := d.Queries.GetDockerHostsMinimalByIDs(ctx, ids)
177 if err != nil {
178 return nil, 0, err

Callers

nothing calls this directly

Calls 7

validatePaginationFunction · 0.85
dockerHostRowToHostInfoFunction · 0.85
dbDockerContainerToModelFunction · 0.85
DBMethod · 0.65
CountContainersMethod · 0.65
ListContainersMethod · 0.65

Tested by

no test coverage detected