All oversized iace files now comply with the 500-line hard cap: - hazard_library_ai_sw.go split into ai_sw (false_classification..communication) and ai_fw (unauthorized_access..update_failure) - hazard_library_software_hmi.go split into software_hmi (software_fault+hmi) and config_integration (configuration_error+logging+integration) - hazard_library_machine_safety.go split to keep mechanical/electrical/thermal/emc, safety_functions extracted into hazard_library_safety_functions.go - store_hazards.go split: hazard library queries moved to store_hazard_library.go - store_projects.go split: component and classification ops to store_components.go - store_mitigations.go split: evidence/verification/ref-data to store_evidence.go - hazard_library.go GetBuiltinHazardLibrary() updated to call all sub-functions - All iace tests pass (go test ./internal/iace/...) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
47 lines
1.7 KiB
Go
47 lines
1.7 KiB
Go
package iace
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// hazardUUID generates a deterministic UUID for a hazard library entry
|
|
// based on category and a 1-based index within that category.
|
|
func hazardUUID(category string, index int) uuid.UUID {
|
|
name := fmt.Sprintf("iace.hazard.%s.%d", category, index)
|
|
return uuid.NewSHA1(uuid.NameSpaceDNS, []byte(name))
|
|
}
|
|
|
|
// mustMarshalJSON marshals the given value to json.RawMessage, panicking on error.
|
|
// This is safe to use for static data known at compile time.
|
|
func mustMarshalJSON(v interface{}) json.RawMessage {
|
|
data, err := json.Marshal(v)
|
|
if err != nil {
|
|
panic(fmt.Sprintf("hazard_library: failed to marshal JSON: %v", err))
|
|
}
|
|
return data
|
|
}
|
|
|
|
// GetBuiltinHazardLibrary returns the complete built-in hazard library with 40+
|
|
// template entries for SW/FW/KI hazards in industrial machines. These entries are
|
|
// intended to be seeded into the iace_hazard_library table during initial setup.
|
|
//
|
|
// All entries have IsBuiltin=true and TenantID=nil (system-level templates).
|
|
// UUIDs are deterministic, generated via uuid.NewSHA1 based on category and index.
|
|
func GetBuiltinHazardLibrary() []HazardLibraryEntry {
|
|
var all []HazardLibraryEntry
|
|
all = append(all, builtinHazardsAISW()...)
|
|
all = append(all, builtinHazardsAIFW()...)
|
|
all = append(all, builtinHazardsSoftwareHMI()...)
|
|
all = append(all, builtinHazardsConfigIntegration()...)
|
|
all = append(all, builtinHazardsMachineSafety()...)
|
|
all = append(all, builtinHazardsSafetyFunctions()...)
|
|
all = append(all, builtinHazardsISO12100Mechanical()...)
|
|
all = append(all, builtinHazardsISO12100ElectricalThermal()...)
|
|
all = append(all, builtinHazardsISO12100Pneumatic()...)
|
|
all = append(all, builtinHazardsISO12100Env()...)
|
|
return all
|
|
}
|