Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
Emyrk merged 8 commits intomainfromstevenmasley/audit_types
Mar 10, 2023
Merged
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Move code around
  • Loading branch information
@Emyrk
Emyrk committedMar 10, 2023
commit87cda86b954d8fc664864e14027518df1d5299b6
68 changes: 34 additions & 34 deletionsenterprise/audit/table.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,40 +49,6 @@ func (t *Table) Add(key string, value map[string]Action) *Table {
return t
}

// 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) {
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
}

// AuditableResources contains a definitive list of all auditable resources and
// which fields are auditable. All resource types must be valid audit.Auditable
// types.
Expand DownExpand Up@@ -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) {
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.
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp