core: push entry table type-checking into for loop (#17220)
This commit refactors the `persistAudit`, `persistAuth`, and `persistMount` code paths to perform `entry.Table` type-checking within the same loop as the entry list appending. This saves cycles in the case of success; however, performs some unnecessary appends in the event that an entry has an incorrect table type/value combination.
This commit is contained in:
parent
cae8fb1218
commit
3ad4d3af6e
|
@ -312,13 +312,6 @@ func (c *Core) persistAudit(ctx context.Context, table *MountTable, localOnly bo
|
|||
return fmt.Errorf("invalid table type given, not persisting")
|
||||
}
|
||||
|
||||
for _, entry := range table.Entries {
|
||||
if entry.Table != table.Type {
|
||||
c.logger.Error("given entry to persist in audit table has wrong table value", "path", entry.Path, "entry_table_type", entry.Table, "actual_type", table.Type)
|
||||
return fmt.Errorf("invalid audit entry found, not persisting")
|
||||
}
|
||||
}
|
||||
|
||||
nonLocalAudit := &MountTable{
|
||||
Type: auditTableType,
|
||||
}
|
||||
|
@ -328,6 +321,11 @@ func (c *Core) persistAudit(ctx context.Context, table *MountTable, localOnly bo
|
|||
}
|
||||
|
||||
for _, entry := range table.Entries {
|
||||
if entry.Table != table.Type {
|
||||
c.logger.Error("given entry to persist in audit table has wrong table value", "path", entry.Path, "entry_table_type", entry.Table, "actual_type", table.Type)
|
||||
return fmt.Errorf("invalid audit entry found, not persisting")
|
||||
}
|
||||
|
||||
if entry.Local {
|
||||
localAudit.Entries = append(localAudit.Entries, entry)
|
||||
} else {
|
||||
|
|
|
@ -672,13 +672,6 @@ func (c *Core) persistAuth(ctx context.Context, table *MountTable, local *bool)
|
|||
return fmt.Errorf("invalid table type given, not persisting")
|
||||
}
|
||||
|
||||
for _, entry := range table.Entries {
|
||||
if entry.Table != table.Type {
|
||||
c.logger.Error("given entry to persist in auth table has wrong table value", "path", entry.Path, "entry_table_type", entry.Table, "actual_type", table.Type)
|
||||
return fmt.Errorf("invalid auth entry found, not persisting")
|
||||
}
|
||||
}
|
||||
|
||||
nonLocalAuth := &MountTable{
|
||||
Type: credentialTableType,
|
||||
}
|
||||
|
@ -688,6 +681,11 @@ func (c *Core) persistAuth(ctx context.Context, table *MountTable, local *bool)
|
|||
}
|
||||
|
||||
for _, entry := range table.Entries {
|
||||
if entry.Table != table.Type {
|
||||
c.logger.Error("given entry to persist in auth table has wrong table value", "path", entry.Path, "entry_table_type", entry.Table, "actual_type", table.Type)
|
||||
return fmt.Errorf("invalid auth entry found, not persisting")
|
||||
}
|
||||
|
||||
if entry.Local {
|
||||
localAuth.Entries = append(localAuth.Entries, entry)
|
||||
} else {
|
||||
|
|
|
@ -1298,13 +1298,6 @@ func (c *Core) persistMounts(ctx context.Context, table *MountTable, local *bool
|
|||
return fmt.Errorf("invalid table type given, not persisting")
|
||||
}
|
||||
|
||||
for _, entry := range table.Entries {
|
||||
if entry.Table != table.Type {
|
||||
c.logger.Error("given entry to persist in mount table has wrong table value", "path", entry.Path, "entry_table_type", entry.Table, "actual_type", table.Type)
|
||||
return fmt.Errorf("invalid mount entry found, not persisting")
|
||||
}
|
||||
}
|
||||
|
||||
nonLocalMounts := &MountTable{
|
||||
Type: mountTableType,
|
||||
}
|
||||
|
@ -1314,6 +1307,11 @@ func (c *Core) persistMounts(ctx context.Context, table *MountTable, local *bool
|
|||
}
|
||||
|
||||
for _, entry := range table.Entries {
|
||||
if entry.Table != table.Type {
|
||||
c.logger.Error("given entry to persist in mount table has wrong table value", "path", entry.Path, "entry_table_type", entry.Table, "actual_type", table.Type)
|
||||
return fmt.Errorf("invalid mount entry found, not persisting")
|
||||
}
|
||||
|
||||
if entry.Local {
|
||||
localMounts.Entries = append(localMounts.Entries, entry)
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue