Class: QueryGuard::CLI::BatchReportFormatter
- Inherits:
-
Object
- Object
- QueryGuard::CLI::BatchReportFormatter
- Defined in:
- lib/query_guard/cli/batch_report_formatter.rb
Overview
Formats multiple QueryGuard reports into a single batch request.
Used for bulk ingestion into SaaS platforms. Supports:
- Multiple reports in a single API request
- Batch correlation IDs for tracking across the entire batch
- Per-report tracing for individual finding tracking
- Pagination metadata for large batches
Example:
reports = [
{ report_version: '1.0', findings: [...], ... },
{ report_version: '1.0', findings: [...], ... }
]
batch = BatchReportFormatter.new(
reports: reports,
batch_id: 'batch-123',
correlation_id: 'api-request-456'
)
json_output = batch.generate
Constant Summary collapse
- BATCH_SCHEMA_VERSION =
'1.0'- BATCH_TYPE =
'batch'
Instance Method Summary collapse
-
#build_batch ⇒ Object
Build batch structure and return as hash.
-
#generate ⇒ Object
Generate the complete batch JSON Returns: String (JSON).
-
#initialize(reports:, batch_id: nil, correlation_id: nil, options: {}) ⇒ BatchReportFormatter
constructor
A new instance of BatchReportFormatter.
Constructor Details
#initialize(reports:, batch_id: nil, correlation_id: nil, options: {}) ⇒ BatchReportFormatter
Returns a new instance of BatchReportFormatter.
33 34 35 36 37 38 39 |
# File 'lib/query_guard/cli/batch_report_formatter.rb', line 33 def initialize(reports:, batch_id: nil, correlation_id: nil, options: {}) @reports = Array(reports) @batch_id = batch_id || generate_batch_id @correlation_id = correlation_id || generate_correlation_id = @created_at = Time.now end |
Instance Method Details
#build_batch ⇒ Object
Build batch structure and return as hash
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/query_guard/cli/batch_report_formatter.rb', line 48 def build_batch { batch_version: BATCH_SCHEMA_VERSION, batch_type: BATCH_TYPE, batch_id: @batch_id, correlation_id: @correlation_id, created_at: @created_at.utc.iso8601.gsub('+00:00', 'Z'), report_count: @reports.length, reports: @reports, pagination: build_pagination, stats: build_batch_stats } end |
#generate ⇒ Object
Generate the complete batch JSON Returns: String (JSON)
43 44 45 |
# File 'lib/query_guard/cli/batch_report_formatter.rb', line 43 def generate JSON.pretty_generate(build_batch) end |