SendDockerData sends Docker integration data to the server
(ctx context.Context, payload *models.DockerPayload)
| 171 | |
| 172 | // SendDockerData sends Docker integration data to the server |
| 173 | func (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 |
| 208 | func (c *Client) GetIntegrationStatus(ctx context.Context) (*models.IntegrationStatusResponse, error) { |
no test coverage detected