2021-04-18 15:41:13 -04:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-03-15 16:03:41 -04:00
|
|
|
|
|
|
|
package event
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"encoding/xml"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Name - event type enum.
|
|
|
|
// Refer http://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html#notification-how-to-event-types-and-destinations
|
2020-07-20 15:52:49 -04:00
|
|
|
// for most basic values we have since extend this and its not really much applicable other than a reference point.
|
2020-11-16 01:16:41 -05:00
|
|
|
// "s3:Replication:OperationCompletedReplication" is a MinIO extension.
|
2018-03-15 16:03:41 -04:00
|
|
|
type Name int
|
|
|
|
|
2020-07-20 15:52:49 -04:00
|
|
|
// Values of event Name
|
2018-03-15 16:03:41 -04:00
|
|
|
const (
|
2022-07-05 17:45:49 -04:00
|
|
|
// Single event types (does not require expansion)
|
|
|
|
|
|
|
|
ObjectAccessedGet Name = 1 + iota
|
2019-11-20 16:18:09 -05:00
|
|
|
ObjectAccessedGetRetention
|
2020-01-16 18:41:56 -05:00
|
|
|
ObjectAccessedGetLegalHold
|
2018-03-15 16:03:41 -04:00
|
|
|
ObjectAccessedHead
|
|
|
|
ObjectCreatedCompleteMultipartUpload
|
|
|
|
ObjectCreatedCopy
|
|
|
|
ObjectCreatedPost
|
|
|
|
ObjectCreatedPut
|
2019-11-20 16:18:09 -05:00
|
|
|
ObjectCreatedPutRetention
|
2020-01-16 18:41:56 -05:00
|
|
|
ObjectCreatedPutLegalHold
|
2021-02-01 16:52:51 -05:00
|
|
|
ObjectCreatedPutTagging
|
|
|
|
ObjectCreatedDeleteTagging
|
2018-03-15 16:03:41 -04:00
|
|
|
ObjectRemovedDelete
|
2020-06-12 23:04:01 -04:00
|
|
|
ObjectRemovedDeleteMarkerCreated
|
2020-07-20 15:52:49 -04:00
|
|
|
BucketCreated
|
|
|
|
BucketRemoved
|
2020-09-16 19:04:55 -04:00
|
|
|
ObjectReplicationFailed
|
2020-11-16 01:16:41 -05:00
|
|
|
ObjectReplicationComplete
|
2020-09-16 19:04:55 -04:00
|
|
|
ObjectReplicationMissedThreshold
|
|
|
|
ObjectReplicationReplicatedAfterThreshold
|
|
|
|
ObjectReplicationNotTracked
|
2020-11-12 15:12:09 -05:00
|
|
|
ObjectRestorePostInitiated
|
|
|
|
ObjectRestorePostCompleted
|
2020-12-07 16:53:28 -05:00
|
|
|
ObjectTransitionFailed
|
|
|
|
ObjectTransitionComplete
|
2022-07-05 17:45:49 -04:00
|
|
|
|
|
|
|
objectSingleTypesEnd
|
|
|
|
// Start Compound types that require expansion:
|
|
|
|
|
|
|
|
ObjectAccessedAll
|
|
|
|
ObjectCreatedAll
|
|
|
|
ObjectRemovedAll
|
|
|
|
ObjectReplicationAll
|
|
|
|
ObjectRestorePostAll
|
|
|
|
ObjectTransitionAll
|
2018-03-15 16:03:41 -04:00
|
|
|
)
|
|
|
|
|
2022-07-05 17:45:49 -04:00
|
|
|
// The number of single names should not exceed 64.
|
|
|
|
// This will break masking. Use bit 63 as extension.
|
|
|
|
var _ = uint64(1 << objectSingleTypesEnd)
|
|
|
|
|
2018-03-15 16:03:41 -04:00
|
|
|
// Expand - returns expanded values of abbreviated event type.
|
|
|
|
func (name Name) Expand() []Name {
|
|
|
|
switch name {
|
2022-07-05 17:45:49 -04:00
|
|
|
|
2018-03-15 16:03:41 -04:00
|
|
|
case ObjectAccessedAll:
|
2020-09-15 00:32:52 -04:00
|
|
|
return []Name{
|
|
|
|
ObjectAccessedGet, ObjectAccessedHead,
|
|
|
|
ObjectAccessedGetRetention, ObjectAccessedGetLegalHold,
|
|
|
|
}
|
2018-03-15 16:03:41 -04:00
|
|
|
case ObjectCreatedAll:
|
2020-09-15 00:32:52 -04:00
|
|
|
return []Name{
|
|
|
|
ObjectCreatedCompleteMultipartUpload, ObjectCreatedCopy,
|
|
|
|
ObjectCreatedPost, ObjectCreatedPut,
|
|
|
|
ObjectCreatedPutRetention, ObjectCreatedPutLegalHold,
|
2021-02-01 16:52:51 -05:00
|
|
|
ObjectCreatedPutTagging, ObjectCreatedDeleteTagging,
|
2020-09-15 00:32:52 -04:00
|
|
|
}
|
2018-03-15 16:03:41 -04:00
|
|
|
case ObjectRemovedAll:
|
2020-09-15 00:32:52 -04:00
|
|
|
return []Name{
|
|
|
|
ObjectRemovedDelete,
|
|
|
|
ObjectRemovedDeleteMarkerCreated,
|
|
|
|
}
|
2020-09-16 19:04:55 -04:00
|
|
|
case ObjectReplicationAll:
|
|
|
|
return []Name{
|
|
|
|
ObjectReplicationFailed,
|
2020-11-16 01:16:41 -05:00
|
|
|
ObjectReplicationComplete,
|
2020-09-16 19:04:55 -04:00
|
|
|
ObjectReplicationNotTracked,
|
|
|
|
ObjectReplicationMissedThreshold,
|
|
|
|
ObjectReplicationReplicatedAfterThreshold,
|
|
|
|
}
|
2020-11-12 15:12:09 -05:00
|
|
|
case ObjectRestorePostAll:
|
|
|
|
return []Name{
|
|
|
|
ObjectRestorePostInitiated,
|
|
|
|
ObjectRestorePostCompleted,
|
|
|
|
}
|
2020-12-07 16:53:28 -05:00
|
|
|
case ObjectTransitionAll:
|
|
|
|
return []Name{
|
|
|
|
ObjectTransitionFailed,
|
|
|
|
ObjectTransitionComplete,
|
|
|
|
}
|
2018-03-15 16:03:41 -04:00
|
|
|
default:
|
|
|
|
return []Name{name}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-05 17:45:49 -04:00
|
|
|
// Mask returns the type as mask.
|
|
|
|
// Compound "All" types are expanded.
|
|
|
|
func (name Name) Mask() uint64 {
|
|
|
|
if name < objectSingleTypesEnd {
|
|
|
|
return 1 << (name - 1)
|
|
|
|
}
|
|
|
|
var mask uint64
|
|
|
|
for _, n := range name.Expand() {
|
|
|
|
mask |= 1 << (n - 1)
|
|
|
|
}
|
|
|
|
return mask
|
|
|
|
}
|
|
|
|
|
2018-03-15 16:03:41 -04:00
|
|
|
// String - returns string representation of event type.
|
|
|
|
func (name Name) String() string {
|
|
|
|
switch name {
|
2020-07-20 15:52:49 -04:00
|
|
|
case BucketCreated:
|
|
|
|
return "s3:BucketCreated:*"
|
|
|
|
case BucketRemoved:
|
|
|
|
return "s3:BucketRemoved:*"
|
2018-03-15 16:03:41 -04:00
|
|
|
case ObjectAccessedAll:
|
|
|
|
return "s3:ObjectAccessed:*"
|
|
|
|
case ObjectAccessedGet:
|
|
|
|
return "s3:ObjectAccessed:Get"
|
2019-11-20 16:18:09 -05:00
|
|
|
case ObjectAccessedGetRetention:
|
|
|
|
return "s3:ObjectAccessed:GetRetention"
|
2020-01-16 18:41:56 -05:00
|
|
|
case ObjectAccessedGetLegalHold:
|
|
|
|
return "s3:ObjectAccessed:GetLegalHold"
|
2018-03-15 16:03:41 -04:00
|
|
|
case ObjectAccessedHead:
|
|
|
|
return "s3:ObjectAccessed:Head"
|
|
|
|
case ObjectCreatedAll:
|
|
|
|
return "s3:ObjectCreated:*"
|
|
|
|
case ObjectCreatedCompleteMultipartUpload:
|
|
|
|
return "s3:ObjectCreated:CompleteMultipartUpload"
|
|
|
|
case ObjectCreatedCopy:
|
|
|
|
return "s3:ObjectCreated:Copy"
|
|
|
|
case ObjectCreatedPost:
|
|
|
|
return "s3:ObjectCreated:Post"
|
|
|
|
case ObjectCreatedPut:
|
|
|
|
return "s3:ObjectCreated:Put"
|
2021-02-01 16:52:51 -05:00
|
|
|
case ObjectCreatedPutTagging:
|
|
|
|
return "s3:ObjectCreated:PutTagging"
|
|
|
|
case ObjectCreatedDeleteTagging:
|
|
|
|
return "s3:ObjectCreated:DeleteTagging"
|
2019-11-20 16:18:09 -05:00
|
|
|
case ObjectCreatedPutRetention:
|
2019-11-20 19:35:01 -05:00
|
|
|
return "s3:ObjectCreated:PutRetention"
|
2020-01-16 18:41:56 -05:00
|
|
|
case ObjectCreatedPutLegalHold:
|
|
|
|
return "s3:ObjectCreated:PutLegalHold"
|
2018-03-15 16:03:41 -04:00
|
|
|
case ObjectRemovedAll:
|
|
|
|
return "s3:ObjectRemoved:*"
|
|
|
|
case ObjectRemovedDelete:
|
|
|
|
return "s3:ObjectRemoved:Delete"
|
2020-06-12 23:04:01 -04:00
|
|
|
case ObjectRemovedDeleteMarkerCreated:
|
|
|
|
return "s3:ObjectRemoved:DeleteMarkerCreated"
|
2020-11-16 01:16:41 -05:00
|
|
|
case ObjectReplicationAll:
|
|
|
|
return "s3:Replication:*"
|
2020-09-16 19:04:55 -04:00
|
|
|
case ObjectReplicationFailed:
|
2020-07-21 20:49:56 -04:00
|
|
|
return "s3:Replication:OperationFailedReplication"
|
2020-11-16 01:16:41 -05:00
|
|
|
case ObjectReplicationComplete:
|
|
|
|
return "s3:Replication:OperationCompletedReplication"
|
2020-09-16 19:04:55 -04:00
|
|
|
case ObjectReplicationNotTracked:
|
|
|
|
return "s3:Replication:OperationNotTracked"
|
|
|
|
case ObjectReplicationMissedThreshold:
|
|
|
|
return "s3:Replication:OperationMissedThreshold"
|
|
|
|
case ObjectReplicationReplicatedAfterThreshold:
|
|
|
|
return "s3:Replication:OperationReplicatedAfterThreshold"
|
2020-11-12 15:12:09 -05:00
|
|
|
case ObjectRestorePostInitiated:
|
|
|
|
return "s3:ObjectRestore:Post"
|
|
|
|
case ObjectRestorePostCompleted:
|
|
|
|
return "s3:ObjectRestore:Completed"
|
2020-12-07 16:53:28 -05:00
|
|
|
case ObjectTransitionAll:
|
|
|
|
return "s3:ObjectTransition:*"
|
|
|
|
case ObjectTransitionFailed:
|
|
|
|
return "s3:ObjectTransition:Failed"
|
|
|
|
case ObjectTransitionComplete:
|
|
|
|
return "s3:ObjectTransition:Complete"
|
2018-03-15 16:03:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
// MarshalXML - encodes to XML data.
|
|
|
|
func (name Name) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
|
|
|
return e.EncodeElement(name.String(), start)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalXML - decodes XML data.
|
|
|
|
func (name *Name) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
|
|
|
var s string
|
|
|
|
if err := d.DecodeElement(&s, &start); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
eventName, err := ParseName(s)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
*name = eventName
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// MarshalJSON - encodes to JSON data.
|
|
|
|
func (name Name) MarshalJSON() ([]byte, error) {
|
|
|
|
return json.Marshal(name.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalJSON - decodes JSON data.
|
|
|
|
func (name *Name) UnmarshalJSON(data []byte) error {
|
|
|
|
var s string
|
|
|
|
if err := json.Unmarshal(data, &s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
eventName, err := ParseName(s)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
*name = eventName
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParseName - parses string to Name.
|
|
|
|
func ParseName(s string) (Name, error) {
|
|
|
|
switch s {
|
2020-07-20 15:52:49 -04:00
|
|
|
case "s3:BucketCreated:*":
|
|
|
|
return BucketCreated, nil
|
|
|
|
case "s3:BucketRemoved:*":
|
|
|
|
return BucketRemoved, nil
|
2018-03-15 16:03:41 -04:00
|
|
|
case "s3:ObjectAccessed:*":
|
|
|
|
return ObjectAccessedAll, nil
|
|
|
|
case "s3:ObjectAccessed:Get":
|
|
|
|
return ObjectAccessedGet, nil
|
2019-11-20 16:18:09 -05:00
|
|
|
case "s3:ObjectAccessed:GetRetention":
|
|
|
|
return ObjectAccessedGetRetention, nil
|
2020-01-16 18:41:56 -05:00
|
|
|
case "s3:ObjectAccessed:GetLegalHold":
|
|
|
|
return ObjectAccessedGetLegalHold, nil
|
2018-03-15 16:03:41 -04:00
|
|
|
case "s3:ObjectAccessed:Head":
|
|
|
|
return ObjectAccessedHead, nil
|
|
|
|
case "s3:ObjectCreated:*":
|
|
|
|
return ObjectCreatedAll, nil
|
|
|
|
case "s3:ObjectCreated:CompleteMultipartUpload":
|
|
|
|
return ObjectCreatedCompleteMultipartUpload, nil
|
|
|
|
case "s3:ObjectCreated:Copy":
|
|
|
|
return ObjectCreatedCopy, nil
|
|
|
|
case "s3:ObjectCreated:Post":
|
|
|
|
return ObjectCreatedPost, nil
|
|
|
|
case "s3:ObjectCreated:Put":
|
|
|
|
return ObjectCreatedPut, nil
|
2019-11-20 16:18:09 -05:00
|
|
|
case "s3:ObjectCreated:PutRetention":
|
|
|
|
return ObjectCreatedPutRetention, nil
|
2020-01-16 18:41:56 -05:00
|
|
|
case "s3:ObjectCreated:PutLegalHold":
|
|
|
|
return ObjectCreatedPutLegalHold, nil
|
2021-02-01 16:52:51 -05:00
|
|
|
case "s3:ObjectCreated:PutTagging":
|
|
|
|
return ObjectCreatedPutTagging, nil
|
|
|
|
case "s3:ObjectCreated:DeleteTagging":
|
|
|
|
return ObjectCreatedDeleteTagging, nil
|
2018-03-15 16:03:41 -04:00
|
|
|
case "s3:ObjectRemoved:*":
|
|
|
|
return ObjectRemovedAll, nil
|
|
|
|
case "s3:ObjectRemoved:Delete":
|
|
|
|
return ObjectRemovedDelete, nil
|
2020-06-12 23:04:01 -04:00
|
|
|
case "s3:ObjectRemoved:DeleteMarkerCreated":
|
|
|
|
return ObjectRemovedDeleteMarkerCreated, nil
|
2020-09-16 19:04:55 -04:00
|
|
|
case "s3:Replication:*":
|
|
|
|
return ObjectReplicationAll, nil
|
2020-07-21 20:49:56 -04:00
|
|
|
case "s3:Replication:OperationFailedReplication":
|
2020-09-16 19:04:55 -04:00
|
|
|
return ObjectReplicationFailed, nil
|
2020-11-16 01:16:41 -05:00
|
|
|
case "s3:Replication:OperationCompletedReplication":
|
|
|
|
return ObjectReplicationComplete, nil
|
2020-09-16 19:04:55 -04:00
|
|
|
case "s3:Replication:OperationMissedThreshold":
|
|
|
|
return ObjectReplicationMissedThreshold, nil
|
|
|
|
case "s3:Replication:OperationReplicatedAfterThreshold":
|
|
|
|
return ObjectReplicationReplicatedAfterThreshold, nil
|
|
|
|
case "s3:Replication:OperationNotTracked":
|
|
|
|
return ObjectReplicationNotTracked, nil
|
2020-11-12 15:12:09 -05:00
|
|
|
case "s3:ObjectRestore:*":
|
|
|
|
return ObjectRestorePostAll, nil
|
|
|
|
case "s3:ObjectRestore:Post":
|
|
|
|
return ObjectRestorePostInitiated, nil
|
|
|
|
case "s3:ObjectRestore:Completed":
|
|
|
|
return ObjectRestorePostCompleted, nil
|
2020-12-07 16:53:28 -05:00
|
|
|
case "s3:ObjectTransition:Failed":
|
|
|
|
return ObjectTransitionFailed, nil
|
|
|
|
case "s3:ObjectTransition:Complete":
|
|
|
|
return ObjectTransitionComplete, nil
|
|
|
|
case "s3:ObjectTransition:*":
|
|
|
|
return ObjectTransitionAll, nil
|
2018-03-15 16:03:41 -04:00
|
|
|
default:
|
|
|
|
return 0, &ErrInvalidEventName{s}
|
|
|
|
}
|
|
|
|
}
|