2018-03-15 16:03:41 -04:00
|
|
|
/*
|
2019-04-09 14:39:42 -04:00
|
|
|
* MinIO Cloud Storage, (C) 2018 MinIO, Inc.
|
2018-03-15 16:03:41 -04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
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.
|
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 (
|
|
|
|
ObjectAccessedAll Name = 1 + iota
|
|
|
|
ObjectAccessedGet
|
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
|
|
|
|
ObjectCreatedAll
|
|
|
|
ObjectCreatedCompleteMultipartUpload
|
|
|
|
ObjectCreatedCopy
|
|
|
|
ObjectCreatedPost
|
|
|
|
ObjectCreatedPut
|
2019-11-20 16:18:09 -05:00
|
|
|
ObjectCreatedPutRetention
|
2020-01-16 18:41:56 -05:00
|
|
|
ObjectCreatedPutLegalHold
|
2018-03-15 16:03:41 -04:00
|
|
|
ObjectRemovedAll
|
|
|
|
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
|
|
|
ObjectReplicationAll
|
|
|
|
ObjectReplicationFailed
|
|
|
|
ObjectReplicationMissedThreshold
|
|
|
|
ObjectReplicationReplicatedAfterThreshold
|
|
|
|
ObjectReplicationNotTracked
|
2018-03-15 16:03:41 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// Expand - returns expanded values of abbreviated event type.
|
|
|
|
func (name Name) Expand() []Name {
|
|
|
|
switch name {
|
2020-07-20 15:52:49 -04:00
|
|
|
case BucketCreated:
|
|
|
|
return []Name{BucketCreated}
|
|
|
|
case BucketRemoved:
|
|
|
|
return []Name{BucketRemoved}
|
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,
|
|
|
|
}
|
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,
|
|
|
|
ObjectReplicationNotTracked,
|
|
|
|
ObjectReplicationMissedThreshold,
|
|
|
|
ObjectReplicationReplicatedAfterThreshold,
|
|
|
|
}
|
2018-03-15 16:03:41 -04:00
|
|
|
default:
|
|
|
|
return []Name{name}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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"
|
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-09-16 19:04:55 -04:00
|
|
|
case ObjectReplicationFailed:
|
2020-07-21 20:49:56 -04:00
|
|
|
return "s3:Replication:OperationFailedReplication"
|
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"
|
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
|
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
|
|
|
|
case "s3:Replication:OperationMissedThreshold":
|
|
|
|
return ObjectReplicationMissedThreshold, nil
|
|
|
|
case "s3:Replication:OperationReplicatedAfterThreshold":
|
|
|
|
return ObjectReplicationReplicatedAfterThreshold, nil
|
|
|
|
case "s3:Replication:OperationNotTracked":
|
|
|
|
return ObjectReplicationNotTracked, nil
|
2018-03-15 16:03:41 -04:00
|
|
|
default:
|
|
|
|
return 0, &ErrInvalidEventName{s}
|
|
|
|
}
|
|
|
|
}
|