| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | /* | 
					
						
							|  |  |  |  * Minio Cloud Storage, (C) 2016 Minio, Inc. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 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. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-19 07:23:42 +08:00
										 |  |  | package cmd | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-27 10:10:02 +08:00
										 |  |  | import ( | 
					
						
							|  |  |  | 	"encoding/xml" | 
					
						
							|  |  |  | 	"errors" | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-26 08:53:55 +08:00
										 |  |  | // Represents the criteria for the filter rule.
 | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | type filterRule struct { | 
					
						
							| 
									
										
										
										
											2016-07-26 08:53:55 +08:00
										 |  |  | 	Name  string `xml:"Name"` | 
					
						
							|  |  |  | 	Value string `xml:"Value"` | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-26 08:53:55 +08:00
										 |  |  | // Collection of filter rules per service config.
 | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | type keyFilter struct { | 
					
						
							| 
									
										
										
										
											2016-07-26 08:53:55 +08:00
										 |  |  | 	FilterRules []filterRule `xml:"FilterRule,omitempty"` | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-12 16:03:50 +08:00
										 |  |  | type filterStruct struct { | 
					
						
							|  |  |  | 	Key keyFilter `xml:"S3Key,omitempty" json:"S3Key,omitempty"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // ServiceConfig - Common elements of service notification.
 | 
					
						
							|  |  |  | type ServiceConfig struct { | 
					
						
							|  |  |  | 	Events []string     `xml:"Event" json:"Event"` | 
					
						
							|  |  |  | 	Filter filterStruct `xml:"Filter" json:"Filter"` | 
					
						
							|  |  |  | 	ID     string       `xml:"Id" json:"Id"` | 
					
						
							| 
									
										
										
										
											2016-08-24 09:42:30 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Queue SQS configuration.
 | 
					
						
							|  |  |  | type queueConfig struct { | 
					
						
							| 
									
										
										
										
											2016-10-12 16:03:50 +08:00
										 |  |  | 	ServiceConfig | 
					
						
							| 
									
										
										
										
											2016-08-05 13:01:58 +08:00
										 |  |  | 	QueueARN string `xml:"Queue"` | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-26 08:53:55 +08:00
										 |  |  | // Topic SNS configuration, this is a compliance field not used by minio yet.
 | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | type topicConfig struct { | 
					
						
							| 
									
										
										
										
											2016-10-12 16:03:50 +08:00
										 |  |  | 	ServiceConfig | 
					
						
							|  |  |  | 	TopicARN string `xml:"Topic" json:"Topic"` | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-26 08:53:55 +08:00
										 |  |  | // Lambda function configuration, this is a compliance field not used by minio yet.
 | 
					
						
							| 
									
										
										
										
											2016-08-05 13:01:58 +08:00
										 |  |  | type lambdaConfig struct { | 
					
						
							| 
									
										
										
										
											2016-10-12 16:03:50 +08:00
										 |  |  | 	ServiceConfig | 
					
						
							| 
									
										
										
										
											2016-08-05 13:01:58 +08:00
										 |  |  | 	LambdaARN string `xml:"CloudFunction"` | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Notification configuration structure represents the XML format of
 | 
					
						
							|  |  |  | // notification configuration of buckets.
 | 
					
						
							|  |  |  | type notificationConfig struct { | 
					
						
							| 
									
										
										
										
											2016-08-05 13:01:58 +08:00
										 |  |  | 	XMLName       xml.Name       `xml:"NotificationConfiguration"` | 
					
						
							|  |  |  | 	QueueConfigs  []queueConfig  `xml:"QueueConfiguration"` | 
					
						
							|  |  |  | 	LambdaConfigs []lambdaConfig `xml:"CloudFunctionConfiguration"` | 
					
						
							| 
									
										
										
										
											2017-08-24 06:58:02 +08:00
										 |  |  | 	TopicConfigs  []topicConfig  `xml:"TopicConfiguration"` | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-12 16:03:50 +08:00
										 |  |  | // listenerConfig structure represents run-time notification
 | 
					
						
							|  |  |  | // configuration for live listeners
 | 
					
						
							|  |  |  | type listenerConfig struct { | 
					
						
							|  |  |  | 	TopicConfig  topicConfig `json:"TopicConfiguration"` | 
					
						
							|  |  |  | 	TargetServer string      `json:"TargetServer"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-27 10:10:02 +08:00
										 |  |  | // Internal error used to signal notifications not set.
 | 
					
						
							|  |  |  | var errNoSuchNotifications = errors.New("The specified bucket does not have bucket notifications") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | // EventName is AWS S3 event type:
 | 
					
						
							|  |  |  | // http://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html
 | 
					
						
							|  |  |  | type EventName int | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const ( | 
					
						
							|  |  |  | 	// ObjectCreatedPut is s3:ObjectCreated:Put
 | 
					
						
							|  |  |  | 	ObjectCreatedPut EventName = iota | 
					
						
							| 
									
										
										
										
											2016-08-05 13:01:58 +08:00
										 |  |  | 	// ObjectCreatedPost is s3:ObjectCreated:Post
 | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | 	ObjectCreatedPost | 
					
						
							| 
									
										
										
										
											2016-08-05 13:01:58 +08:00
										 |  |  | 	// ObjectCreatedCopy is s3:ObjectCreated:Copy
 | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | 	ObjectCreatedCopy | 
					
						
							|  |  |  | 	// ObjectCreatedCompleteMultipartUpload is s3:ObjectCreated:CompleteMultipartUpload
 | 
					
						
							|  |  |  | 	ObjectCreatedCompleteMultipartUpload | 
					
						
							|  |  |  | 	// ObjectRemovedDelete is s3:ObjectRemoved:Delete
 | 
					
						
							|  |  |  | 	ObjectRemovedDelete | 
					
						
							| 
									
										
										
										
											2017-03-22 01:32:17 +08:00
										 |  |  | 	// ObjectAccessedGet is s3:ObjectAccessed:Get
 | 
					
						
							|  |  |  | 	ObjectAccessedGet | 
					
						
							|  |  |  | 	// ObjectAccessedHead is s3:ObjectAccessed:Head
 | 
					
						
							|  |  |  | 	ObjectAccessedHead | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Stringer interface for event name.
 | 
					
						
							|  |  |  | func (eventName EventName) String() string { | 
					
						
							|  |  |  | 	switch eventName { | 
					
						
							|  |  |  | 	case ObjectCreatedPut: | 
					
						
							|  |  |  | 		return "s3:ObjectCreated:Put" | 
					
						
							|  |  |  | 	case ObjectCreatedPost: | 
					
						
							|  |  |  | 		return "s3:ObjectCreated:Post" | 
					
						
							|  |  |  | 	case ObjectCreatedCopy: | 
					
						
							|  |  |  | 		return "s3:ObjectCreated:Copy" | 
					
						
							|  |  |  | 	case ObjectCreatedCompleteMultipartUpload: | 
					
						
							|  |  |  | 		return "s3:ObjectCreated:CompleteMultipartUpload" | 
					
						
							|  |  |  | 	case ObjectRemovedDelete: | 
					
						
							|  |  |  | 		return "s3:ObjectRemoved:Delete" | 
					
						
							| 
									
										
										
										
											2017-03-22 01:32:17 +08:00
										 |  |  | 	case ObjectAccessedGet: | 
					
						
							|  |  |  | 		return "s3:ObjectAccessed:Get" | 
					
						
							|  |  |  | 	case ObjectAccessedHead: | 
					
						
							|  |  |  | 		return "s3:ObjectAccessed:Head" | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | 	default: | 
					
						
							|  |  |  | 		return "s3:Unknown" | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 08:43:48 +08:00
										 |  |  | // Indentity represents the accessKey who caused the event.
 | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | type identity struct { | 
					
						
							|  |  |  | 	PrincipalID string `json:"principalId"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-26 08:53:55 +08:00
										 |  |  | // Notification event bucket metadata.
 | 
					
						
							|  |  |  | type bucketMeta struct { | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | 	Name          string   `json:"name"` | 
					
						
							|  |  |  | 	OwnerIdentity identity `json:"ownerIdentity"` | 
					
						
							|  |  |  | 	ARN           string   `json:"arn"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-26 08:53:55 +08:00
										 |  |  | // Notification event object metadata.
 | 
					
						
							|  |  |  | type objectMeta struct { | 
					
						
							| 
									
										
										
										
											2017-11-21 07:32:25 +08:00
										 |  |  | 	Key          string            `json:"key"` | 
					
						
							|  |  |  | 	Size         int64             `json:"size,omitempty"` | 
					
						
							|  |  |  | 	ETag         string            `json:"eTag,omitempty"` | 
					
						
							|  |  |  | 	ContentType  string            `json:"contentType,omitempty"` | 
					
						
							|  |  |  | 	UserMetadata map[string]string `json:"userMetadata,omitempty"` | 
					
						
							|  |  |  | 	VersionID    string            `json:"versionId,omitempty"` | 
					
						
							|  |  |  | 	Sequencer    string            `json:"sequencer"` | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 08:43:48 +08:00
										 |  |  | const ( | 
					
						
							|  |  |  | 	// Event schema version number defaulting to the value in S3 spec.
 | 
					
						
							|  |  |  | 	// ref: http://docs.aws.amazon.com/AmazonS3/latest/dev/notification-content-structure.html
 | 
					
						
							|  |  |  | 	eventSchemaVersion = "1.0" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Default ID found in bucket notification configuration.
 | 
					
						
							|  |  |  | 	// ref: http://docs.aws.amazon.com/AmazonS3/latest/dev/notification-content-structure.html
 | 
					
						
							|  |  |  | 	eventConfigID = "Config" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const ( | 
					
						
							|  |  |  | 	// Response element origin endpoint key.
 | 
					
						
							|  |  |  | 	responseOriginEndpointKey = "x-minio-origin-endpoint" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-26 08:53:55 +08:00
										 |  |  | // Notification event server specific metadata.
 | 
					
						
							|  |  |  | type eventMeta struct { | 
					
						
							|  |  |  | 	SchemaVersion   string     `json:"s3SchemaVersion"` | 
					
						
							|  |  |  | 	ConfigurationID string     `json:"configurationId"` | 
					
						
							|  |  |  | 	Bucket          bucketMeta `json:"bucket"` | 
					
						
							|  |  |  | 	Object          objectMeta `json:"object"` | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 08:43:48 +08:00
										 |  |  | const ( | 
					
						
							|  |  |  | 	// Event source static value defaulting to the value in S3 spec.
 | 
					
						
							|  |  |  | 	// ref: http://docs.aws.amazon.com/AmazonS3/latest/dev/notification-content-structure.html
 | 
					
						
							|  |  |  | 	eventSource = "aws:s3" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Event version number defaulting to the value in S3 spec.
 | 
					
						
							|  |  |  | 	// ref: http://docs.aws.amazon.com/AmazonS3/latest/dev/notification-content-structure.html
 | 
					
						
							|  |  |  | 	eventVersion = "2.0" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-23 09:44:35 +08:00
										 |  |  | // sourceInfo represents information on the client that triggered the
 | 
					
						
							|  |  |  | // event notification.
 | 
					
						
							|  |  |  | type sourceInfo struct { | 
					
						
							|  |  |  | 	Host      string `json:"host"` | 
					
						
							|  |  |  | 	Port      string `json:"port"` | 
					
						
							|  |  |  | 	UserAgent string `json:"userAgent"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | // NotificationEvent represents an Amazon an S3 bucket notification event.
 | 
					
						
							|  |  |  | type NotificationEvent struct { | 
					
						
							|  |  |  | 	EventVersion      string            `json:"eventVersion"` | 
					
						
							|  |  |  | 	EventSource       string            `json:"eventSource"` | 
					
						
							|  |  |  | 	AwsRegion         string            `json:"awsRegion"` | 
					
						
							|  |  |  | 	EventTime         string            `json:"eventTime"` | 
					
						
							|  |  |  | 	EventName         string            `json:"eventName"` | 
					
						
							|  |  |  | 	UserIdentity      identity          `json:"userIdentity"` | 
					
						
							|  |  |  | 	RequestParameters map[string]string `json:"requestParameters"` | 
					
						
							|  |  |  | 	ResponseElements  map[string]string `json:"responseElements"` | 
					
						
							| 
									
										
										
										
											2016-07-26 08:53:55 +08:00
										 |  |  | 	S3                eventMeta         `json:"s3"` | 
					
						
							| 
									
										
										
										
											2017-03-23 09:44:35 +08:00
										 |  |  | 	Source            sourceInfo        `json:"source"` | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-05 13:01:58 +08:00
										 |  |  | // Represents the minio sqs type and account id's.
 | 
					
						
							|  |  |  | type arnSQS struct { | 
					
						
							|  |  |  | 	Type      string | 
					
						
							|  |  |  | 	AccountID string | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Stringer for constructing AWS ARN compatible string.
 | 
					
						
							| 
									
										
										
										
											2016-08-05 13:01:58 +08:00
										 |  |  | func (m arnSQS) String() string { | 
					
						
							|  |  |  | 	return minioSqs + serverConfig.GetRegion() + ":" + m.AccountID + ":" + m.Type | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | } |