From 13c4ce3617f25b265c3477fec7c854bf83c1d982 Mon Sep 17 00:00:00 2001 From: Krishnan Parthasarathi Date: Tue, 21 Mar 2017 23:02:17 +0530 Subject: [PATCH] Add notification for object access via GET/HEAD (#3941) The following notification event types are available for all targets, s3:ObjectAccessed:Get s3:ObjectAccessed:Head s3:ObjectAccessed:* --- cmd/bucket-notification-datatypes.go | 8 ++++++++ cmd/bucket-notification-handlers_test.go | 1 + cmd/bucket-notification-utils.go | 3 +++ cmd/object-handlers.go | 16 ++++++++++++++++ 4 files changed, 28 insertions(+) diff --git a/cmd/bucket-notification-datatypes.go b/cmd/bucket-notification-datatypes.go index 02695b36f..d9a888778 100644 --- a/cmd/bucket-notification-datatypes.go +++ b/cmd/bucket-notification-datatypes.go @@ -94,6 +94,10 @@ const ( ObjectCreatedCompleteMultipartUpload // ObjectRemovedDelete is s3:ObjectRemoved:Delete ObjectRemovedDelete + // ObjectAccessedGet is s3:ObjectAccessed:Get + ObjectAccessedGet + // ObjectAccessedHead is s3:ObjectAccessed:Head + ObjectAccessedHead ) // Stringer interface for event name. @@ -109,6 +113,10 @@ func (eventName EventName) String() string { return "s3:ObjectCreated:CompleteMultipartUpload" case ObjectRemovedDelete: return "s3:ObjectRemoved:Delete" + case ObjectAccessedGet: + return "s3:ObjectAccessed:Get" + case ObjectAccessedHead: + return "s3:ObjectAccessed:Head" default: return "s3:Unknown" } diff --git a/cmd/bucket-notification-handlers_test.go b/cmd/bucket-notification-handlers_test.go index d4db4445c..c1b7c9ebf 100644 --- a/cmd/bucket-notification-handlers_test.go +++ b/cmd/bucket-notification-handlers_test.go @@ -268,6 +268,7 @@ func testListenBucketNotificationNilHandler(obj ObjectLayer, instanceType, bucke []string{"*.jpg"}, []string{ "s3:ObjectCreated:*", "s3:ObjectRemoved:*", + "s3:ObjectAccessed:*", }), 0, nil, credentials.AccessKey, credentials.SecretKey) if tErr != nil { t.Fatalf("%s: Failed to create HTTP testRequest for ListenBucketNotification: %v", instanceType, tErr) diff --git a/cmd/bucket-notification-utils.go b/cmd/bucket-notification-utils.go index d58de93d9..a421a7d66 100644 --- a/cmd/bucket-notification-utils.go +++ b/cmd/bucket-notification-utils.go @@ -29,6 +29,9 @@ var suppportedEventTypes = map[string]struct{}{ // Object removed event types. "s3:ObjectRemoved:*": {}, "s3:ObjectRemoved:Delete": {}, + "s3:ObjectAccessed:Get": {}, + "s3:ObjectAccessed:Head": {}, + "s3:ObjectAccessed:*": {}, } // checkEvent - checks if an event is supported. diff --git a/cmd/object-handlers.go b/cmd/object-handlers.go index 7e423fd6c..062512598 100644 --- a/cmd/object-handlers.go +++ b/cmd/object-handlers.go @@ -173,6 +173,14 @@ func (api objectAPIHandlers) GetObjectHandler(w http.ResponseWriter, r *http.Req // call wrter.Write(nil) to set appropriate headers. writer.Write(nil) } + + // Notify object accessed via a GET request. + eventNotify(eventData{ + Type: ObjectAccessedGet, + Bucket: bucket, + ObjInfo: objInfo, + ReqParams: extractReqParams(r), + }) } // HeadObjectHandler - HEAD Object @@ -221,6 +229,14 @@ func (api objectAPIHandlers) HeadObjectHandler(w http.ResponseWriter, r *http.Re // Successful response. w.WriteHeader(http.StatusOK) + + // Notify object accessed via a HEAD request. + eventNotify(eventData{ + Type: ObjectAccessedHead, + Bucket: bucket, + ObjInfo: objInfo, + ReqParams: extractReqParams(r), + }) } // Extract metadata relevant for an CopyObject operation based on conditional