Class: QueryGuard::CLI::JsonReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/query_guard/cli/json_reporter.rb

Overview

Generates standardized JSON reports for QueryGuard analysis and check results.

Provides a stable, versioned JSON schema suitable for:

  • SaaS platform ingestion
  • CI/CD integration
  • External tool consumption
  • Compliance and audit archival

Schema version: 1.0 (documented in docs/JSON_REPORT_SCHEMA.md)

Example:

reporter = QueryGuard::CLI::JsonReporter.new(
findings: findings,
command: 'analyze',
path: 'db/migrate',
options: { threshold: 'error' }
)
json_output = reporter.generate

Constant Summary collapse

SCHEMA_VERSION =
'1.0'
TOOL_NAME =
'queryguard'

Instance Method Summary collapse

Constructor Details

#initialize(findings:, command:, path: '.', options: {}) ⇒ JsonReporter

Returns a new instance of JsonReporter.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/query_guard/cli/json_reporter.rb', line 30

def initialize(findings:, command:, path: '.', options: {})
  @findings = findings
  @command = command # 'analyze' or 'check'
  @path = path
  @options = options
  @started_at = Time.now

  # Initialize tracing context (for distributed systems)
  # Can be overridden via options: { request_id, trace_id, span_id, parent_span_id }
  @request_id = options[:request_id] || generate_request_id
  @trace_id = options[:trace_id] || generate_trace_id
  @span_id = options[:span_id] || generate_span_id
  @parent_span_id = options[:parent_span_id]

  # Initialize source metadata collector
  # Can be overridden via options: { source_metadata_collector }
  @source_metadata_collector = options[:source_metadata_collector] || SourceMetadataCollector.new
end

Instance Method Details

#build_report ⇒ Object

Generate report and return as parsed hash (useful for testing)



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/query_guard/cli/json_reporter.rb', line 56

def build_report
  {
    report_version: SCHEMA_VERSION,
    report_type: @command,
    timestamp: Time.now.utc.iso8601.gsub('+00:00', 'Z'),
    tool: build_tool,
    source: build_source,
    summary: build_summary,
    findings: build_findings,
    metadata: ,
    tracing: build_tracing
  }
end

#generate ⇒ Object

Generate the complete JSON report Returns: String (JSON)



51
52
53
# File 'lib/query_guard/cli/json_reporter.rb', line 51

def generate
  JSON.pretty_generate(build_report)
end