in pkg/util/log/audit/otel_audit.go [109:182]
func EnsureDefaults(r *msgs.Record) {
setDefault := func(value *string, defaultValue string) {
if *value == "" {
*value = defaultValue
}
}
setDefault(&r.OperationName, Unknown)
setDefault(&r.OperationAccessLevel, Unknown)
setDefault(&r.CallerAgent, Unknown)
if len(r.OperationCategories) == 0 {
r.OperationCategories = []msgs.OperationCategory{msgs.ResourceManagement}
}
for _, category := range r.OperationCategories {
if category == msgs.OCOther && r.OperationCategoryDescription == "" {
r.OperationCategoryDescription = "Other"
}
}
if r.OperationResult == msgs.Failure && r.OperationResultDescription == "" {
r.OperationResultDescription = Unknown
}
if len(r.CallerIdentities) == 0 {
r.CallerIdentities = map[msgs.CallerIdentityType][]msgs.CallerIdentityEntry{
msgs.ApplicationID: {
{Identity: Unknown, Description: Unknown},
},
}
}
for identityType, identities := range r.CallerIdentities {
if len(identities) == 0 {
r.CallerIdentities[identityType] = []msgs.CallerIdentityEntry{{Identity: Unknown, Description: Unknown}}
}
}
if !r.CallerIpAddress.IsValid() || r.CallerIpAddress.IsUnspecified() || r.CallerIpAddress.IsLoopback() || r.CallerIpAddress.IsMulticast() {
r.CallerIpAddress, _ = msgs.ParseAddr("192.168.1.1")
}
if len(r.CallerAccessLevels) == 0 {
r.CallerAccessLevels = []string{Unknown}
}
for i, k := range r.CallerAccessLevels {
if strings.TrimSpace(k) == "" {
r.CallerAccessLevels[i] = Unknown
}
}
if len(r.TargetResources) == 0 {
r.TargetResources = map[string][]msgs.TargetResourceEntry{
Unknown: {
{Name: Unknown, Region: Unknown},
},
}
}
for resourceType, resources := range r.TargetResources {
if strings.TrimSpace(resourceType) == "" {
r.TargetResources[Unknown] = resources
delete(r.TargetResources, resourceType)
}
for _, resource := range resources {
if err := resource.Validate(); err != nil {
resource.Name = Unknown
}
}
}
}