You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
179 lines
5.2 KiB
179 lines
5.2 KiB
9 years ago
|
/*
|
||
|
* 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.
|
||
|
*/
|
||
|
|
||
8 years ago
|
package cmd
|
||
9 years ago
|
|
||
9 years ago
|
import (
|
||
|
"encoding/xml"
|
||
|
"errors"
|
||
|
)
|
||
9 years ago
|
|
||
9 years ago
|
// Represents the criteria for the filter rule.
|
||
9 years ago
|
type filterRule struct {
|
||
9 years ago
|
Name string `xml:"Name"`
|
||
|
Value string `xml:"Value"`
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
// Collection of filter rules per service config.
|
||
9 years ago
|
type keyFilter struct {
|
||
9 years ago
|
FilterRules []filterRule `xml:"FilterRule,omitempty"`
|
||
9 years ago
|
}
|
||
|
|
||
|
// Queue SQS configuration.
|
||
|
type queueConfig struct {
|
||
9 years ago
|
Events []string `xml:"Event"`
|
||
|
Filter struct {
|
||
|
Key keyFilter `xml:"S3Key,omitempty"`
|
||
|
}
|
||
9 years ago
|
ID string `xml:"Id"`
|
||
9 years ago
|
QueueARN string `xml:"Queue"`
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
// Topic SNS configuration, this is a compliance field not used by minio yet.
|
||
9 years ago
|
type topicConfig struct {
|
||
9 years ago
|
Events []string `xml:"Event"`
|
||
|
Filter struct {
|
||
|
Key keyFilter `xml:"S3Key"`
|
||
|
}
|
||
9 years ago
|
ID string `xml:"Id"`
|
||
9 years ago
|
TopicARN string `xml:"Topic"`
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
// Lambda function configuration, this is a compliance field not used by minio yet.
|
||
9 years ago
|
type lambdaConfig struct {
|
||
9 years ago
|
Events []string `xml:"Event"`
|
||
|
Filter struct {
|
||
9 years ago
|
Key keyFilter `xml:"S3Key,omitempty"`
|
||
9 years ago
|
}
|
||
9 years ago
|
ID string `xml:"Id"`
|
||
|
LambdaARN string `xml:"CloudFunction"`
|
||
9 years ago
|
}
|
||
|
|
||
|
// Notification configuration structure represents the XML format of
|
||
|
// notification configuration of buckets.
|
||
|
type notificationConfig struct {
|
||
9 years ago
|
XMLName xml.Name `xml:"NotificationConfiguration"`
|
||
|
QueueConfigs []queueConfig `xml:"QueueConfiguration"`
|
||
|
TopicConfigs []topicConfig `xml:"TopicConfiguration"`
|
||
|
LambdaConfigs []lambdaConfig `xml:"CloudFunctionConfiguration"`
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
// Internal error used to signal notifications not set.
|
||
|
var errNoSuchNotifications = errors.New("The specified bucket does not have bucket notifications")
|
||
|
|
||
9 years ago
|
// 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
|
||
9 years ago
|
// ObjectCreatedPost is s3:ObjectCreated:Post
|
||
9 years ago
|
ObjectCreatedPost
|
||
9 years ago
|
// ObjectCreatedCopy is s3:ObjectCreated:Copy
|
||
9 years ago
|
ObjectCreatedCopy
|
||
|
// ObjectCreatedCompleteMultipartUpload is s3:ObjectCreated:CompleteMultipartUpload
|
||
|
ObjectCreatedCompleteMultipartUpload
|
||
|
// ObjectRemovedDelete is s3:ObjectRemoved:Delete
|
||
|
ObjectRemovedDelete
|
||
|
)
|
||
|
|
||
|
// 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"
|
||
|
default:
|
||
|
return "s3:Unknown"
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Indentity represents the user id, this is a compliance field.
|
||
|
type identity struct {
|
||
|
PrincipalID string `json:"principalId"`
|
||
|
}
|
||
|
|
||
|
func defaultIdentity() identity {
|
||
|
return identity{"minio"}
|
||
|
}
|
||
|
|
||
9 years ago
|
// Notification event bucket metadata.
|
||
|
type bucketMeta struct {
|
||
9 years ago
|
Name string `json:"name"`
|
||
|
OwnerIdentity identity `json:"ownerIdentity"`
|
||
|
ARN string `json:"arn"`
|
||
|
}
|
||
|
|
||
9 years ago
|
// Notification event object metadata.
|
||
|
type objectMeta struct {
|
||
9 years ago
|
Key string `json:"key"`
|
||
|
Size int64 `json:"size,omitempty"`
|
||
|
ETag string `json:"eTag,omitempty"`
|
||
|
VersionID string `json:"versionId,omitempty"`
|
||
|
Sequencer string `json:"sequencer"`
|
||
|
}
|
||
|
|
||
9 years ago
|
// Notification event server specific metadata.
|
||
|
type eventMeta struct {
|
||
|
SchemaVersion string `json:"s3SchemaVersion"`
|
||
|
ConfigurationID string `json:"configurationId"`
|
||
|
Bucket bucketMeta `json:"bucket"`
|
||
|
Object objectMeta `json:"object"`
|
||
9 years ago
|
}
|
||
|
|
||
|
// 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"`
|
||
9 years ago
|
S3 eventMeta `json:"s3"`
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
// Represents the minio topic type and account id's.
|
||
|
type arnTopic struct {
|
||
9 years ago
|
Type string
|
||
|
AccountID string
|
||
|
}
|
||
|
|
||
|
// Stringer for constructing AWS ARN compatible string.
|
||
8 years ago
|
func (m arnTopic) String() string {
|
||
|
return minioTopic + serverConfig.GetRegion() + ":" + m.AccountID + ":" + m.Type
|
||
9 years ago
|
}
|
||
|
|
||
|
// Represents the minio sqs type and account id's.
|
||
|
type arnSQS struct {
|
||
|
Type string
|
||
|
AccountID string
|
||
9 years ago
|
}
|
||
|
|
||
|
// Stringer for constructing AWS ARN compatible string.
|
||
9 years ago
|
func (m arnSQS) String() string {
|
||
|
return minioSqs + serverConfig.GetRegion() + ":" + m.AccountID + ":" + m.Type
|
||
9 years ago
|
}
|