mirror of
https://github.com/pgsty/minio.git
synced 2026-07-24 06:26:17 +03:00
api: Change listen bucket notification to be TopicConfiguration. (#2447)
This commit is contained in:
committed by
Anand Babu (AB) Periasamy
parent
3b9dbd748b
commit
e86dfcf41e
@@ -111,17 +111,33 @@ func checkQueueARN(queueARN string) APIErrorCode {
|
||||
return ErrNone
|
||||
}
|
||||
|
||||
// checkLambdaARN - check if the lambda arn is valid.
|
||||
func checkLambdaARN(lambdaARN string) APIErrorCode {
|
||||
if !strings.HasPrefix(lambdaARN, minioLambda) {
|
||||
// checkTopicARN - check if the topic arn is valid.
|
||||
func checkTopicARN(topicARN string) APIErrorCode {
|
||||
if !strings.HasPrefix(topicARN, minioTopic) {
|
||||
return ErrARNNotification
|
||||
}
|
||||
if !strings.HasPrefix(lambdaARN, minioLambda+serverConfig.GetRegion()+":") {
|
||||
if !strings.HasPrefix(topicARN, minioTopic+serverConfig.GetRegion()+":") {
|
||||
return ErrRegionNotification
|
||||
}
|
||||
return ErrNone
|
||||
}
|
||||
|
||||
// Returns true if the topicARN is for an Minio sns listen type.
|
||||
func isMinioSNS(topicARN arnTopic) bool {
|
||||
return strings.HasSuffix(topicARN.Type, snsTypeMinio)
|
||||
}
|
||||
|
||||
// isMinioSNSConfigured - verifies if one topic ARN is valid and is enabled.
|
||||
func isMinioSNSConfigured(topicARN string, topicConfigs []topicConfig) bool {
|
||||
for _, topicConfig := range topicConfigs {
|
||||
// Validate if topic ARN is already enabled.
|
||||
if topicARN == topicConfig.TopicARN {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Validate if we recognize the queue type.
|
||||
func isValidQueue(sqsARN arnSQS) bool {
|
||||
amqpQ := isAMQPQueue(sqsARN) // Is amqp queue?.
|
||||
@@ -130,9 +146,9 @@ func isValidQueue(sqsARN arnSQS) bool {
|
||||
return amqpQ || elasticQ || redisQ
|
||||
}
|
||||
|
||||
// Validate if we recognize the lambda type.
|
||||
func isValidLambda(lambdaARN arnLambda) bool {
|
||||
return isMinL(lambdaARN) // Is minio lambda?.
|
||||
// Validate if we recognize the topic type.
|
||||
func isValidTopic(topicARN arnTopic) bool {
|
||||
return isMinioSNS(topicARN) // Is minio topic?.
|
||||
}
|
||||
|
||||
// Validates account id for input queue ARN.
|
||||
@@ -188,26 +204,26 @@ func checkQueueConfig(qConfig queueConfig) APIErrorCode {
|
||||
}
|
||||
|
||||
// Check - validates queue configuration and returns error if any.
|
||||
func checkLambdaConfig(lConfig lambdaConfig) APIErrorCode {
|
||||
func checkTopicConfig(tConfig topicConfig) APIErrorCode {
|
||||
// Check queue arn is valid.
|
||||
if s3Error := checkLambdaARN(lConfig.LambdaARN); s3Error != ErrNone {
|
||||
if s3Error := checkTopicARN(tConfig.TopicARN); s3Error != ErrNone {
|
||||
return s3Error
|
||||
}
|
||||
|
||||
// Unmarshals QueueARN into structured object.
|
||||
lambdaARN := unmarshalLambdaARN(lConfig.LambdaARN)
|
||||
// Validate if lambdaARN requested any of the known supported queues.
|
||||
if !isValidLambda(lambdaARN) {
|
||||
topicARN := unmarshalTopicARN(tConfig.TopicARN)
|
||||
// Validate if topicARN requested any of the known supported queues.
|
||||
if !isValidTopic(topicARN) {
|
||||
return ErrARNNotification
|
||||
}
|
||||
|
||||
// Check if valid events are set in queue config.
|
||||
if s3Error := checkEvents(lConfig.Events); s3Error != ErrNone {
|
||||
if s3Error := checkEvents(tConfig.Events); s3Error != ErrNone {
|
||||
return s3Error
|
||||
}
|
||||
|
||||
// Check if valid filters are set in queue config.
|
||||
if s3Error := checkFilterRules(lConfig.Filter.Key.FilterRules); s3Error != ErrNone {
|
||||
if s3Error := checkFilterRules(tConfig.Filter.Key.FilterRules); s3Error != ErrNone {
|
||||
return s3Error
|
||||
}
|
||||
|
||||
@@ -228,12 +244,12 @@ func validateQueueConfigs(queueConfigs []queueConfig) APIErrorCode {
|
||||
return ErrNone
|
||||
}
|
||||
|
||||
// Validates all incoming lambda configs, checkLambdaConfig validates if the
|
||||
// Validates all incoming topic configs, checkTopicConfig validates if the
|
||||
// input fields for each queues is not malformed and has valid configuration
|
||||
// information. If validation fails bucket notifications are not enabled.
|
||||
func validateLambdaConfigs(lambdaConfigs []lambdaConfig) APIErrorCode {
|
||||
for _, lConfig := range lambdaConfigs {
|
||||
if s3Error := checkLambdaConfig(lConfig); s3Error != ErrNone {
|
||||
func validateTopicConfigs(topicConfigs []topicConfig) APIErrorCode {
|
||||
for _, tConfig := range topicConfigs {
|
||||
if s3Error := checkTopicConfig(tConfig); s3Error != ErrNone {
|
||||
return s3Error
|
||||
}
|
||||
}
|
||||
@@ -248,7 +264,7 @@ func validateNotificationConfig(nConfig notificationConfig) APIErrorCode {
|
||||
if s3Error := validateQueueConfigs(nConfig.QueueConfigs); s3Error != ErrNone {
|
||||
return s3Error
|
||||
}
|
||||
if s3Error := validateLambdaConfigs(nConfig.LambdaConfigs); s3Error != ErrNone {
|
||||
if s3Error := validateTopicConfigs(nConfig.TopicConfigs); s3Error != ErrNone {
|
||||
return s3Error
|
||||
}
|
||||
|
||||
@@ -256,21 +272,21 @@ func validateNotificationConfig(nConfig notificationConfig) APIErrorCode {
|
||||
return ErrNone
|
||||
}
|
||||
|
||||
// Unmarshals input value of AWS ARN format into minioLambda object.
|
||||
// Returned value represents minio lambda type, currently supported are
|
||||
// - minio
|
||||
func unmarshalLambdaARN(lambdaARN string) arnLambda {
|
||||
lambda := arnLambda{}
|
||||
if !strings.HasPrefix(lambdaARN, minioLambda+serverConfig.GetRegion()+":") {
|
||||
return lambda
|
||||
// Unmarshals input value of AWS ARN format into minioTopic object.
|
||||
// Returned value represents minio topic type, currently supported are
|
||||
// - listen
|
||||
func unmarshalTopicARN(topicARN string) arnTopic {
|
||||
topic := arnTopic{}
|
||||
if !strings.HasPrefix(topicARN, minioTopic+serverConfig.GetRegion()+":") {
|
||||
return topic
|
||||
}
|
||||
lambdaType := strings.TrimPrefix(lambdaARN, minioLambda+serverConfig.GetRegion()+":")
|
||||
topicType := strings.TrimPrefix(topicARN, minioTopic+serverConfig.GetRegion()+":")
|
||||
switch {
|
||||
case strings.HasSuffix(lambdaType, lambdaTypeMinio):
|
||||
lambda.Type = lambdaTypeMinio
|
||||
} // Add more lambda here.
|
||||
lambda.AccountID = strings.TrimSuffix(lambdaType, ":"+lambda.Type)
|
||||
return lambda
|
||||
case strings.HasSuffix(topicType, snsTypeMinio):
|
||||
topic.Type = snsTypeMinio
|
||||
} // Add more topic here.
|
||||
topic.AccountID = strings.TrimSuffix(topicType, ":"+topic.Type)
|
||||
return topic
|
||||
}
|
||||
|
||||
// Unmarshals input value of AWS ARN format into minioSqs object.
|
||||
|
||||
Reference in New Issue
Block a user