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

Method SendDockerData

agent-source-code/internal/client/client.go:173–205  ·  view source on GitHub ↗

SendDockerData sends Docker integration data to the server

(ctx context.Context, payload *models.DockerPayload)

Source from the content-addressed store, hash-verified

171
172// SendDockerData sends Docker integration data to the server
173func (c *Client) SendDockerData(ctx context.Context, payload *models.DockerPayload) (*models.DockerResponse, error) {
174 url := fmt.Sprintf("%s/api/%s/integrations/docker", c.config.PatchmonServer, c.config.APIVersion)
175
176 c.logger.WithFields(logrus.Fields{
177 "url": url,
178 "method": "POST",
179 }).Debug("Sending Docker data to server")
180
181 resp, err := c.client.R().
182 SetContext(ctx).
183 SetHeader("Content-Type", "application/json").
184 SetHeader("X-API-ID", c.credentials.APIID).
185 SetHeader("X-API-KEY", c.credentials.APIKey).
186 SetBody(payload).
187 SetResult(&models.DockerResponse{}).
188 Post(url)
189
190 if err != nil {
191 return nil, fmt.Errorf("docker data request failed: %w", err)
192 }
193
194 if resp.StatusCode() != 200 {
195 c.logger.WithField("response", resp.String()).Debug("Full error response from docker data request")
196 return nil, fmt.Errorf("docker data request failed with status %d: %s", resp.StatusCode(), truncateResponse(resp.String(), 200))
197 }
198
199 result, ok := resp.Result().(*models.DockerResponse)
200 if !ok {
201 return nil, fmt.Errorf("invalid response format")
202 }
203
204 return result, nil
205}
206
207// GetIntegrationStatus gets the current integration status from server
208func (c *Client) GetIntegrationStatus(ctx context.Context) (*models.IntegrationStatusResponse, error) {

Callers 2

refreshDockerInventoryFunction · 0.80
sendDockerDataFunction · 0.80

Calls 1

truncateResponseFunction · 0.85

Tested by

no test coverage detected