@ -111,17 +111,33 @@ func checkQueueARN(queueARN string) APIErrorCode {
return ErrNone
return ErrNone
}
}
// checkLambdaARN - check if the lambda arn is valid.
// checkTopicARN - check if the topic arn is valid.
func checkLambdaARN ( lambda ARN string ) APIErrorCode {
func checkTopicARN ( topic ARN string ) APIErrorCode {
if ! strings . HasPrefix ( lambdaARN , minioLambda ) {
if ! strings . HasPrefix ( topicARN , minioTopic ) {
return ErrARNNotification
return ErrARNNotification
}
}
if ! strings . HasPrefix ( lambdaARN , minioLambda + serverConfig . GetRegion ( ) + ":" ) {
if ! strings . HasPrefix ( topicARN , minioTopic + serverConfig . GetRegion ( ) + ":" ) {
return ErrRegionNotification
return ErrRegionNotification
}
}
return ErrNone
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.
// Validate if we recognize the queue type.
func isValidQueue ( sqsARN arnSQS ) bool {
func isValidQueue ( sqsARN arnSQS ) bool {
amqpQ := isAMQPQueue ( sqsARN ) // Is amqp queue?.
amqpQ := isAMQPQueue ( sqsARN ) // Is amqp queue?.
@ -130,9 +146,9 @@ func isValidQueue(sqsARN arnSQS) bool {
return amqpQ || elasticQ || redisQ
return amqpQ || elasticQ || redisQ
}
}
// Validate if we recognize the lambda type.
// Validate if we recognize the topic type.
func isValidLambda ( lambdaARN arnLambda ) bool {
func isValidTopic ( topicARN arnTopic ) bool {
return isMinL ( lambdaARN ) // Is minio lambda ?.
return isMinioSNS ( topicARN ) // Is minio topic ?.
}
}
// Validates account id for input queue ARN.
// 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.
// Check - validates queue configuration and returns error if any.
func checkLambdaConfig ( lConfig lambda Config ) APIErrorCode {
func checkTopicConfig ( tConfig topic Config ) APIErrorCode {
// Check queue arn is valid.
// Check queue arn is valid.
if s3Error := checkLambdaARN ( lConfig . Lambda ARN ) ; s3Error != ErrNone {
if s3Error := checkTopicARN ( tConfig . Topic ARN ) ; s3Error != ErrNone {
return s3Error
return s3Error
}
}
// Unmarshals QueueARN into structured object.
// Unmarshals QueueARN into structured object.
lambdaARN := unmarshalLambdaARN ( lConfig . Lambda ARN)
topicARN := unmarshalTopicARN ( tConfig . Topic ARN)
// Validate if lambda ARN requested any of the known supported queues.
// Validate if topic ARN requested any of the known supported queues.
if ! isValidLambda ( lambda ARN ) {
if ! isValidTopic ( topic ARN ) {
return ErrARNNotification
return ErrARNNotification
}
}
// Check if valid events are set in queue config.
// Check if valid events are set in queue config.
if s3Error := checkEvents ( l Config. Events ) ; s3Error != ErrNone {
if s3Error := checkEvents ( t Config. Events ) ; s3Error != ErrNone {
return s3Error
return s3Error
}
}
// Check if valid filters are set in queue config.
// Check if valid filters are set in queue config.
if s3Error := checkFilterRules ( l Config. Filter . Key . FilterRules ) ; s3Error != ErrNone {
if s3Error := checkFilterRules ( t Config. Filter . Key . FilterRules ) ; s3Error != ErrNone {
return s3Error
return s3Error
}
}
@ -228,12 +244,12 @@ func validateQueueConfigs(queueConfigs []queueConfig) APIErrorCode {
return ErrNone
return ErrNone
}
}
// Validates all incoming lambda configs, checkLambda Config validates if the
// Validates all incoming topic configs, checkTopic Config validates if the
// input fields for each queues is not malformed and has valid configuration
// input fields for each queues is not malformed and has valid configuration
// information. If validation fails bucket notifications are not enabled.
// information. If validation fails bucket notifications are not enabled.
func validateLambdaConfigs ( lambdaConfigs [ ] lambda Config ) APIErrorCode {
func validateTopicConfigs ( topicConfigs [ ] topic Config ) APIErrorCode {
for _ , lConfig := range lambda Configs {
for _ , tConfig := range topic Configs {
if s3Error := checkLambdaConfig ( l Config ) ; s3Error != ErrNone {
if s3Error := checkTopicConfig ( t Config ) ; s3Error != ErrNone {
return s3Error
return s3Error
}
}
}
}
@ -248,7 +264,7 @@ func validateNotificationConfig(nConfig notificationConfig) APIErrorCode {
if s3Error := validateQueueConfigs ( nConfig . QueueConfigs ) ; s3Error != ErrNone {
if s3Error := validateQueueConfigs ( nConfig . QueueConfigs ) ; s3Error != ErrNone {
return s3Error
return s3Error
}
}
if s3Error := validateLambda Configs ( nConfig . Lambda Configs) ; s3Error != ErrNone {
if s3Error := validateTopic Configs ( nConfig . Topic Configs) ; s3Error != ErrNone {
return s3Error
return s3Error
}
}
@ -256,21 +272,21 @@ func validateNotificationConfig(nConfig notificationConfig) APIErrorCode {
return ErrNone
return ErrNone
}
}
// Unmarshals input value of AWS ARN format into minioLambda object.
// Unmarshals input value of AWS ARN format into minioTopic object.
// Returned value represents minio lambda type, currently supported are
// Returned value represents minio topic type, currently supported are
// - minio
// - listen
func unmarshalLambdaARN ( lambdaARN string ) arnLambda {
func unmarshalTopicARN ( topicARN string ) arnTopic {
lambda := arnLambda { }
topic := arnTopic { }
if ! strings . HasPrefix ( lambdaARN , minioLambda + serverConfig . GetRegion ( ) + ":" ) {
if ! strings . HasPrefix ( topicARN , minioTopic + serverConfig . GetRegion ( ) + ":" ) {
return lambda
return topic
}
}
lambda Type := strings . TrimPrefix ( lambdaARN , minioLambda + serverConfig . GetRegion ( ) + ":" )
topic Type := strings . TrimPrefix ( topicARN , minioTopic + serverConfig . GetRegion ( ) + ":" )
switch {
switch {
case strings . HasSuffix ( lambdaType , lambda TypeMinio) :
case strings . HasSuffix ( topicType , sns TypeMinio) :
lambda . Type = lambda TypeMinio
topic . Type = sns TypeMinio
} // Add more lambda here.
} // Add more topic here.
lambda . AccountID = strings . TrimSuffix ( lambda Type, ":" + lambda . Type )
topic . AccountID = strings . TrimSuffix ( topic Type, ":" + topic . Type )
return lambda
return topic
}
}
// Unmarshals input value of AWS ARN format into minioSqs object.
// Unmarshals input value of AWS ARN format into minioSqs object.