File size: 1,016 Bytes
6165ba9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import json
import copy
from typing import Dict, Any

def export_aibom(aibom: Dict[str, Any], bom_type: str = "cyclonedx", spec_version: str = "1.6") -> str:
    """

    Exports the internal AIBOM object into a specified format and specification version.

    Returns the generated SBOM as a formatted JSON string.

    """
    # Create a deep copy to avoid modifying the original unified object
    output = copy.deepcopy(aibom)
    
    if bom_type.lower() == "cyclonedx":
        output["bomFormat"] = "CycloneDX"
        output["specVersion"] = spec_version
        # Any specific CycloneDX mappings or adjustments can be placed here over time.
        
    elif bom_type.lower() == "spdx":
        # Placeholder for future SPDX generation logic
        output["bomFormat"] = "SPDX"
        output["specVersion"] = spec_version
        # Since spdx mapping logic to AIBOM isn't fully built yet, this serves as the routing hook
        pass
        
    return json.dumps(output, indent=2)