github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/cmd/bucket-lifecycle-audit.go (about)

     1  // Copyright (c) 2023 MinIO, Inc.
     2  //
     3  // This file is part of MinIO Object Storage stack
     4  //
     5  // This program is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU Affero General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // This program is distributed in the hope that it will be useful
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  // GNU Affero General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU Affero General Public License
    16  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17  
    18  package cmd
    19  
    20  import "github.com/minio/minio/internal/bucket/lifecycle"
    21  
    22  //go:generate stringer -type lcEventSrc -trimprefix lcEventSrc_ $GOFILE
    23  type lcEventSrc uint8
    24  
    25  //revive:disable:var-naming Underscores is used here to indicate where common prefix ends and the enumeration name begins
    26  const (
    27  	lcEventSrc_None lcEventSrc = iota
    28  	lcEventSrc_Heal
    29  	lcEventSrc_Scanner
    30  	lcEventSrc_Decom
    31  	lcEventSrc_Rebal
    32  	lcEventSrc_s3HeadObject
    33  	lcEventSrc_s3GetObject
    34  	lcEventSrc_s3ListObjects
    35  	lcEventSrc_s3PutObject
    36  	lcEventSrc_s3CopyObject
    37  	lcEventSrc_s3CompleteMultipartUpload
    38  )
    39  
    40  //revive:enable:var-naming
    41  type lcAuditEvent struct {
    42  	lifecycle.Event
    43  	source lcEventSrc
    44  }
    45  
    46  func (lae lcAuditEvent) Tags() map[string]interface{} {
    47  	event := lae.Event
    48  	src := lae.source
    49  	const (
    50  		ilmSrc                     = "ilm-src"
    51  		ilmAction                  = "ilm-action"
    52  		ilmDue                     = "ilm-due"
    53  		ilmRuleID                  = "ilm-rule-id"
    54  		ilmTier                    = "ilm-tier"
    55  		ilmNewerNoncurrentVersions = "ilm-newer-noncurrent-versions"
    56  		ilmNoncurrentDays          = "ilm-noncurrent-days"
    57  	)
    58  	tags := make(map[string]interface{}, 5)
    59  	if src > lcEventSrc_None {
    60  		tags[ilmSrc] = src.String()
    61  	}
    62  	tags[ilmAction] = event.Action.String()
    63  	tags[ilmRuleID] = event.RuleID
    64  
    65  	if !event.Due.IsZero() {
    66  		tags[ilmDue] = event.Due
    67  	}
    68  
    69  	// rule with Transition/NoncurrentVersionTransition in effect
    70  	if event.StorageClass != "" {
    71  		tags[ilmTier] = event.StorageClass
    72  	}
    73  
    74  	// rule with NewernoncurrentVersions in effect
    75  	if event.NewerNoncurrentVersions > 0 {
    76  		tags[ilmNewerNoncurrentVersions] = event.NewerNoncurrentVersions
    77  	}
    78  	if event.NoncurrentDays > 0 {
    79  		tags[ilmNoncurrentDays] = event.NoncurrentDays
    80  	}
    81  	return tags
    82  }
    83  
    84  func newLifecycleAuditEvent(src lcEventSrc, event lifecycle.Event) lcAuditEvent {
    85  	return lcAuditEvent{
    86  		Event:  event,
    87  		source: src,
    88  	}
    89  }