SendComplianceData sends compliance scan data to the server
(ctx context.Context, payload *models.CompliancePayload)
| 280 | |
| 281 | // SendComplianceData sends compliance scan data to the server |
| 282 | func (c *Client) SendComplianceData(ctx context.Context, payload *models.CompliancePayload) (*models.ComplianceResponse, error) { |
| 283 | url := fmt.Sprintf("%s/api/%s/compliance/scans", c.config.PatchmonServer, c.config.APIVersion) |
| 284 | |
| 285 | c.logger.WithFields(logrus.Fields{ |
| 286 | "url": url, |
| 287 | "method": "POST", |
| 288 | "scans": len(payload.Scans), |
| 289 | }).Debug("Sending compliance data to server") |
| 290 | |
| 291 | resp, err := c.client.R(). |
| 292 | SetContext(ctx). |
| 293 | SetHeader("Content-Type", "application/json"). |
| 294 | SetHeader("X-API-ID", c.credentials.APIID). |
| 295 | SetHeader("X-API-KEY", c.credentials.APIKey). |
| 296 | SetBody(payload). |
| 297 | SetResult(&models.ComplianceResponse{}). |
| 298 | Post(url) |
| 299 | |
| 300 | if err != nil { |
| 301 | return nil, fmt.Errorf("compliance data request failed: %w", err) |
| 302 | } |
| 303 | |
| 304 | if resp.StatusCode() != 200 { |
| 305 | c.logger.WithField("response", resp.String()).Debug("Full error response from compliance data request") |
| 306 | return nil, fmt.Errorf("compliance data request failed with status %d: %s", resp.StatusCode(), truncateResponse(resp.String(), 200)) |
| 307 | } |
| 308 | |
| 309 | result, ok := resp.Result().(*models.ComplianceResponse) |
| 310 | if !ok { |
| 311 | return nil, fmt.Errorf("invalid response format") |
| 312 | } |
| 313 | |
| 314 | return result, nil |
| 315 | } |
| 316 | |
| 317 | // SSGVersionResponse represents the server's response to GET /compliance/ssg-version. |
| 318 | type SSGVersionResponse struct { |
no test coverage detected