MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / GenerateAuditEvent

Function GenerateAuditEvent

app/controlplane/pkg/auditor/logentry.go:90–146  ·  view source on GitHub ↗
(entry LogEntry, opts ...GeneratorOption)

Source from the content-addressed store, hash-verified

88}
89
90func GenerateAuditEvent(entry LogEntry, opts ...GeneratorOption) (*EventPayload, error) {
91 options := &GeneratorOptions{}
92 for _, opt := range opts {
93 if err := opt(options); err != nil {
94 return nil, err
95 }
96 }
97
98 descriptionTpl := entry.Description()
99 if descriptionTpl == "" {
100 return nil, errors.New("description is required")
101 }
102
103 description, err := interpolateDescription(descriptionTpl, options)
104 if err != nil {
105 return nil, fmt.Errorf("failed to parse description template: %w", err)
106 }
107
108 actionType := entry.ActionType()
109 if actionType == "" {
110 return nil, errors.New("action type is required")
111 }
112
113 targetType := entry.TargetType()
114 if targetType == "" {
115 return nil, errors.New("target type is required")
116 }
117
118 actionInfo, err := entry.ActionInfo()
119 if err != nil {
120 return nil, fmt.Errorf("failed to get action info: %w", err)
121 }
122
123 // calculate the digest of the log entry
124 digest, err := digest(entry, options.OrgID, options.ActorID)
125 if err != nil {
126 return nil, fmt.Errorf("failed to calculate digest: %w", err)
127 }
128
129 return &EventPayload{
130 EventType: AuditEventType,
131 Timestamp: time.Now(),
132 Data: &AuditEventPayload{
133 Description: description,
134 ActionType: actionType,
135 TargetType: targetType,
136 TargetID: entry.TargetID(),
137 Info: actionInfo,
138 ActorType: options.ActorType,
139 ActorID: options.ActorID,
140 ActorName: options.ActorName,
141 ActorEmail: options.ActorEmail,
142 OrgID: options.OrgID,
143 Digest: digest,
144 },
145 }, nil
146}
147

Callers 10

TestCASBackendEventsFunction · 0.92
TestUserEventsFunction · 0.92
TestOrganizationEventsFunction · 0.92
TestGroupEventsFunction · 0.92
TestCASArtifactEventsFunction · 0.92
TestProjectEventsFunction · 0.92
TestWorkflowEventsFunction · 0.92
TestAPITokenEventsFunction · 0.92
DispatchMethod · 0.85

Calls 7

interpolateDescriptionFunction · 0.85
digestFunction · 0.70
DescriptionMethod · 0.65
ActionTypeMethod · 0.65
TargetTypeMethod · 0.65
ActionInfoMethod · 0.65
TargetIDMethod · 0.65

Tested by 9

TestCASBackendEventsFunction · 0.74
TestUserEventsFunction · 0.74
TestOrganizationEventsFunction · 0.74
TestGroupEventsFunction · 0.74
TestCASArtifactEventsFunction · 0.74
TestProjectEventsFunction · 0.74
TestWorkflowEventsFunction · 0.74
TestAPITokenEventsFunction · 0.74