use directly S3 event types instead of re-defining them (#3511)
This commit is contained in:
+4
-3
@@ -41,6 +41,7 @@ import (
|
||||
minio "github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/encrypt"
|
||||
"github.com/minio/minio-go/v7/pkg/lifecycle"
|
||||
"github.com/minio/minio-go/v7/pkg/notification"
|
||||
"github.com/minio/minio-go/v7/pkg/replication"
|
||||
"github.com/minio/minio/pkg/console"
|
||||
)
|
||||
@@ -200,19 +201,19 @@ func (f *fsClient) Watch(ctx context.Context, options WatchOptions) (*WatchObjec
|
||||
Time: UTCNow().Format(timeFormatFS),
|
||||
Size: i.Size(),
|
||||
Path: event.Path(),
|
||||
Type: EventCreate,
|
||||
Type: notification.ObjectCreatedPut,
|
||||
}}
|
||||
} else if IsDeleteEvent(event.Event()) {
|
||||
eventChan <- []EventInfo{{
|
||||
Time: UTCNow().Format(timeFormatFS),
|
||||
Path: event.Path(),
|
||||
Type: EventRemove,
|
||||
Type: notification.ObjectRemovedDelete,
|
||||
}}
|
||||
} else if IsGetEvent(event.Event()) {
|
||||
eventChan <- []EventInfo{{
|
||||
Time: UTCNow().Format(timeFormatFS),
|
||||
Path: event.Path(),
|
||||
Type: EventAccessed,
|
||||
Type: notification.ObjectAccessedGet,
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-28
@@ -652,7 +652,7 @@ func (c *S3Client) notificationToEventsInfo(ninfo notification.Info) []EventInfo
|
||||
Size: record.S3.Object.Size,
|
||||
UserMetadata: record.S3.Object.UserMetadata,
|
||||
Path: u.String(),
|
||||
Type: EventCreateCopy,
|
||||
Type: notification.ObjectCreatedCopy,
|
||||
Host: record.Source.Host,
|
||||
Port: record.Source.Port,
|
||||
UserAgent: record.Source.UserAgent,
|
||||
@@ -663,7 +663,7 @@ func (c *S3Client) notificationToEventsInfo(ninfo notification.Info) []EventInfo
|
||||
Size: record.S3.Object.Size,
|
||||
UserMetadata: record.S3.Object.UserMetadata,
|
||||
Path: u.String(),
|
||||
Type: EventCreatePutRetention,
|
||||
Type: notification.EventType("s3:ObjectCreated:PutRetention"),
|
||||
Host: record.Source.Host,
|
||||
Port: record.Source.Port,
|
||||
UserAgent: record.Source.UserAgent,
|
||||
@@ -674,7 +674,7 @@ func (c *S3Client) notificationToEventsInfo(ninfo notification.Info) []EventInfo
|
||||
Size: record.S3.Object.Size,
|
||||
UserMetadata: record.S3.Object.UserMetadata,
|
||||
Path: u.String(),
|
||||
Type: EventCreatePutLegalHold,
|
||||
Type: notification.EventType("s3:ObjectCreated:PutLegalHold"),
|
||||
Host: record.Source.Host,
|
||||
Port: record.Source.Port,
|
||||
UserAgent: record.Source.UserAgent,
|
||||
@@ -685,41 +685,19 @@ func (c *S3Client) notificationToEventsInfo(ninfo notification.Info) []EventInfo
|
||||
Size: record.S3.Object.Size,
|
||||
UserMetadata: record.S3.Object.UserMetadata,
|
||||
Path: u.String(),
|
||||
Type: EventCreate,
|
||||
Type: notification.ObjectCreatedPut,
|
||||
Host: record.Source.Host,
|
||||
Port: record.Source.Port,
|
||||
UserAgent: record.Source.UserAgent,
|
||||
}
|
||||
}
|
||||
} else if strings.HasPrefix(record.EventName, "s3:ObjectRemoved:") {
|
||||
} else {
|
||||
eventsInfo[i] = EventInfo{
|
||||
Time: record.EventTime,
|
||||
Size: record.S3.Object.Size,
|
||||
UserMetadata: record.S3.Object.UserMetadata,
|
||||
Path: u.String(),
|
||||
Type: EventRemove,
|
||||
Host: record.Source.Host,
|
||||
Port: record.Source.Port,
|
||||
UserAgent: record.Source.UserAgent,
|
||||
}
|
||||
} else if record.EventName == notification.ObjectAccessedGet {
|
||||
eventsInfo[i] = EventInfo{
|
||||
Time: record.EventTime,
|
||||
Size: record.S3.Object.Size,
|
||||
UserMetadata: record.S3.Object.UserMetadata,
|
||||
Path: u.String(),
|
||||
Type: EventAccessedRead,
|
||||
Host: record.Source.Host,
|
||||
Port: record.Source.Port,
|
||||
UserAgent: record.Source.UserAgent,
|
||||
}
|
||||
} else if record.EventName == notification.ObjectAccessedHead {
|
||||
eventsInfo[i] = EventInfo{
|
||||
Time: record.EventTime,
|
||||
Size: record.S3.Object.Size,
|
||||
UserMetadata: record.S3.Object.UserMetadata,
|
||||
Path: u.String(),
|
||||
Type: EventAccessedStat,
|
||||
Type: notification.EventType(record.EventName),
|
||||
Host: record.Source.Host,
|
||||
Port: record.Source.Port,
|
||||
UserAgent: record.Source.UserAgent,
|
||||
|
||||
+5
-6
@@ -34,6 +34,7 @@ import (
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/encrypt"
|
||||
"github.com/minio/minio-go/v7/pkg/notification"
|
||||
"github.com/minio/minio/pkg/console"
|
||||
)
|
||||
|
||||
@@ -451,16 +452,14 @@ func (mj *mirrorJob) watchMirrorEvents(ctx context.Context, events []EventInfo)
|
||||
targetURL := newClientURL(expandedTargetPath)
|
||||
tgtSSE := getSSE(targetPath, mj.opts.encKeyDB[targetAlias])
|
||||
|
||||
if (event.Type == EventCreate) ||
|
||||
(event.Type == EventCreateCopy) ||
|
||||
(event.Type == EventCreatePutRetention) {
|
||||
if strings.HasPrefix(string(event.Type), "s3:ObjectCreated:") {
|
||||
sourceModTime, _ := time.Parse(time.RFC3339Nano, event.Time)
|
||||
mirrorURL := URLs{
|
||||
SourceAlias: sourceAlias,
|
||||
SourceContent: &ClientContent{
|
||||
URL: *sourceURL,
|
||||
RetentionEnabled: event.Type == EventCreatePutRetention,
|
||||
LegalHoldEnabled: event.Type == EventCreatePutLegalHold,
|
||||
RetentionEnabled: event.Type == notification.EventType("s3:ObjectCreated:PutRetention"),
|
||||
LegalHoldEnabled: event.Type == notification.EventType("s3:ObjectCreated:PutLegalHold"),
|
||||
Size: event.Size,
|
||||
Time: sourceModTime,
|
||||
Metadata: event.UserMetadata,
|
||||
@@ -482,7 +481,7 @@ func (mj *mirrorJob) watchMirrorEvents(ctx context.Context, events []EventInfo)
|
||||
mj.parallel.queueTask(func() URLs {
|
||||
return mj.doMirrorWatch(ctx, targetPath, tgtSSE, mirrorURL)
|
||||
})
|
||||
} else if event.Type == EventRemove {
|
||||
} else if event.Type == notification.ObjectRemovedDelete {
|
||||
if strings.Contains(event.UserAgent, uaMirrorAppName) {
|
||||
continue
|
||||
}
|
||||
|
||||
+6
-5
@@ -27,6 +27,7 @@ import (
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio-go/v7/pkg/notification"
|
||||
"github.com/minio/minio/pkg/console"
|
||||
)
|
||||
|
||||
@@ -99,10 +100,10 @@ func checkWatchSyntax(ctx *cli.Context) {
|
||||
type watchMessage struct {
|
||||
Status string `json:"status"`
|
||||
Event struct {
|
||||
Time string `json:"time"`
|
||||
Size int64 `json:"size"`
|
||||
Path string `json:"path"`
|
||||
Type EventType `json:"type"`
|
||||
Time string `json:"time"`
|
||||
Size int64 `json:"size"`
|
||||
Path string `json:"path"`
|
||||
Type notification.EventType `json:"type"`
|
||||
} `json:"events"`
|
||||
Source struct {
|
||||
Host string `json:"host,omitempty"`
|
||||
@@ -120,7 +121,7 @@ func (u watchMessage) JSON() string {
|
||||
|
||||
func (u watchMessage) String() string {
|
||||
msg := console.Colorize("Time", fmt.Sprintf("[%s] ", u.Event.Time))
|
||||
if u.Event.Type == EventCreate {
|
||||
if strings.HasPrefix(string(u.Event.Type), "s3:ObjectCreated:") {
|
||||
msg += console.Colorize("Size", fmt.Sprintf("%6s ", humanize.IBytes(uint64(u.Event.Size))))
|
||||
} else {
|
||||
msg += fmt.Sprintf("%6s ", "")
|
||||
|
||||
+2
-30
@@ -22,35 +22,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
|
||||
// EventType represents the type of the event occurred.
|
||||
type EventType string
|
||||
|
||||
const (
|
||||
// EventCreate notifies when a new object is created
|
||||
EventCreate EventType = "ObjectCreated"
|
||||
|
||||
// EventCreateCopy notifies when there was a server side copy
|
||||
EventCreateCopy EventType = "ObjectCreated:Copy"
|
||||
|
||||
// EventRemove notifies when a new object is deleted
|
||||
EventRemove = "ObjectRemoved"
|
||||
|
||||
// Following are MinIO server specific events
|
||||
|
||||
// EventCreatePutRetention notifies when a retention configuration is added to an object
|
||||
EventCreatePutRetention EventType = "ObjectCreated:PutRetention"
|
||||
|
||||
// EventCreatePutLegalHold notifies when a legal hold configuration is added to an object
|
||||
EventCreatePutLegalHold EventType = "ObjectCreated:PutLegalHold"
|
||||
|
||||
// EventAccessed notifies when an object is accessed.
|
||||
EventAccessed = "ObjectAccessed"
|
||||
// EventAccessedRead notifies when an object is accessed (specifically read/get).
|
||||
EventAccessedRead = "ObjectAccessed:Read"
|
||||
// EventAccessedStat notifies when an object is accessed (specifically stat).
|
||||
EventAccessedStat = "ObjectAccessed:Stat"
|
||||
"github.com/minio/minio-go/v7/pkg/notification"
|
||||
)
|
||||
|
||||
// EventInfo contains the information of the event that occurred and the source
|
||||
@@ -60,10 +32,10 @@ type EventInfo struct {
|
||||
Size int64
|
||||
UserMetadata map[string]string
|
||||
Path string
|
||||
Type EventType
|
||||
Host string
|
||||
Port string
|
||||
UserAgent string
|
||||
Type notification.EventType
|
||||
}
|
||||
|
||||
// WatchOptions contains watch configuration options
|
||||
|
||||
Reference in New Issue
Block a user