File tree Expand file tree Collapse file tree 4 files changed +19
-0
lines changed
Expand file tree Collapse file tree 4 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -168,6 +168,10 @@ var settings = []Setting{
168168 name : config .Rootless ,
169169 set : SetBool ,
170170 },
171+ {
172+ name : config .MaxAuditEntries ,
173+ set : SetInt ,
174+ },
171175}
172176
173177// ConfigCmd represents the config command
Original file line number Diff line number Diff line change @@ -325,6 +325,7 @@ func setupViper() {
325325 viper .SetDefault (config .ReminderWaitPeriodInHours , 24 )
326326 viper .SetDefault (config .WantNoneDriverWarning , true )
327327 viper .SetDefault (config .WantVirtualBoxDriverWarning , true )
328+ viper .SetDefault (config .MaxAuditEntries , 1000 )
328329}
329330
330331func addToPath (dir string ) {
Original file line number Diff line number Diff line change @@ -98,6 +98,9 @@ func LogCommandEnd(id string) error {
9898 return err
9999 }
100100 var entriesNeedsToUpdate int
101+
102+ startIndex := getStartIndex (len (rowSlice ))
103+ rowSlice = rowSlice [startIndex :]
101104 for _ , v := range rowSlice {
102105 if v .id == id {
103106 v .endTime = time .Now ().Format (constants .TimeFormat )
@@ -118,6 +121,15 @@ func LogCommandEnd(id string) error {
118121 return nil
119122}
120123
124+ func getStartIndex (entryCount int ) int {
125+ maxEntries := viper .GetInt (config .MaxAuditEntries )
126+ startIndex := entryCount - maxEntries
127+ if maxEntries <= 0 || startIndex <= 0 {
128+ return 0
129+ }
130+ return startIndex
131+ }
132+
121133// shouldLog returns if the command should be logged.
122134func shouldLog () bool {
123135 // in rare chance we get here without a command, don't log
Original file line number Diff line number Diff line change @@ -54,6 +54,8 @@ const (
5454 AddonListFlag = "addons"
5555 // EmbedCerts represents the config for embedding certificates in kubeconfig
5656 EmbedCerts = "EmbedCerts"
57+ // MaxAuditEntries is the maximum number of audit entries to retain
58+ MaxAuditEntries = "MaxAuditEntries"
5759)
5860
5961var (
You can’t perform that action at this time.
0 commit comments