- Notifications
You must be signed in to change notification settings - Fork928
chore: Ensure all audit types in ResourceTable match APGL#6563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from1 commit
Commits
Show all changes
8 commits Select commitHold shift + click to select a range
1bacac9
chore: Ensure all audit types in ResourceTable match APGL
Emyrk87cda86
Move code around
Emyrk00837a5
Implement more checks to ensure all tracked fields are present
Emyrk31e4c53
Make "Add" unexported
Emyrk68f3196
Make gen, removed some fields
Emyrk47ef0e4
Add unit test to ensure all types are represented in audit table
Emyrk55dd298
Trade compile time safety for syntax
Emyrk0bee7c8
remove unused function
EmyrkFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Move code around
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commit87cda86b954d8fc664864e14027518df1d5299b6
There are no files selected for viewing
68 changes: 34 additions & 34 deletionsenterprise/audit/table.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -49,40 +49,6 @@ func (t *Table) Add(key string, value map[string]Action) *Table { | ||
return t | ||
} | ||
// AuditableResources contains a definitive list of all auditable resources and | ||
// which fields are auditable. All resource types must be valid audit.Auditable | ||
// types. | ||
@@ -210,6 +176,40 @@ var AuditableResources = (&Table{}). | ||
"uuid": ActionTrack, | ||
})) | ||
// entry is a helper function that ensures all entries in the table are valid | ||
// audit.Auditable types. It also ensures all json tags have a corresponding | ||
// action. | ||
func entry[A audit.Auditable](v A, f map[string]Action) (string, map[string]Action) { | ||
Emyrk marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
vt := reflect.TypeOf(v) | ||
for vt.Kind() == reflect.Ptr { | ||
vt = vt.Elem() | ||
} | ||
// This should never happen because audit.Audible only allows structs in | ||
// its union. | ||
if vt.Kind() != reflect.Struct { | ||
panic(fmt.Sprintf("audit table entry value must be a struct, got %T", v)) | ||
} | ||
name := structName(vt) | ||
// Ensure all json tags have a corresponding action. | ||
for i := 0; i < vt.NumField(); i++ { | ||
field := vt.Field(i) | ||
if !field.IsExported() { | ||
continue | ||
} | ||
if field.Tag.Get("json") == "-" { | ||
// This field is explicitly ignored. | ||
continue | ||
} | ||
if _, ok := f[field.Name]; !ok { | ||
panic(fmt.Sprintf("audit table entry missing action for field %q in type %q", field.Name, name)) | ||
} | ||
} | ||
return structName(vt), f | ||
} | ||
// auditMap converts a map of struct pointers to a map of struct names as | ||
// strings. It's a convenience wrapper so that structs can be passed in by value | ||
// instead of manually typing struct names as strings. | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.