@ -111,17 +111,33 @@ func checkQueueARN(queueARN string) APIErrorCode {
return ErrNone
}
// checkLambdaARN - check if the lambda arn is valid.
func checkLambdaARN ( lambda ARN string ) APIErrorCode {
if ! strings . HasPrefix ( lambdaARN , minioLambda ) {
// checkTopicARN - check if the topic arn is valid.
func checkTopicARN ( topic ARN 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 lambda Config ) APIErrorCode {
func checkTopicConfig ( tConfig topic Config ) APIErrorCode {
// Check queue arn is valid.
if s3Error := checkLambdaARN ( lConfig . Lambda ARN ) ; s3Error != ErrNone {
if s3Error := checkTopicARN ( tConfig . Topic ARN ) ; s3Error != ErrNone {
return s3Error
}
// Unmarshals QueueARN into structured object.
lambdaARN := unmarshalLambdaARN ( lConfig . Lambda ARN)
// Validate if lambda ARN requested any of the known supported queues.
if ! isValidLambda ( lambda ARN ) {
topicARN := unmarshalTopicARN ( tConfig . Topic ARN)
// Validate if topic ARN requested any of the known supported queues.
if ! isValidTopic ( topic ARN ) {
return ErrARNNotification
}
// 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
}
// 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
}
@ -228,12 +244,12 @@ func validateQueueConfigs(queueConfigs []queueConfig) APIErrorCode {
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
// information. If validation fails bucket notifications are not enabled.
func validateLambdaConfigs ( lambdaConfigs [ ] lambda Config ) APIErrorCode {
for _ , lConfig := range lambda Configs {
if s3Error := checkLambdaConfig ( l Config ) ; s3Error != ErrNone {
func validateTopicConfigs ( topicConfigs [ ] topic Config ) APIErrorCode {
for _ , tConfig := range topic Configs {
if s3Error := checkTopicConfig ( t Config ) ; s3Error != ErrNone {
return s3Error
}
}
@ -248,7 +264,7 @@ func validateNotificationConfig(nConfig notificationConfig) APIErrorCode {
if s3Error := validateQueueConfigs ( nConfig . QueueConfigs ) ; s3Error != ErrNone {
return s3Error
}
if s3Error := validateLambda Configs ( nConfig . Lambda Configs) ; s3Error != ErrNone {
if s3Error := validateTopic Configs ( nConfig . Topic Configs) ; 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
}
lambda Type := strings . TrimPrefix ( lambdaARN , minioLambda + serverConfig . GetRegion ( ) + ":" )
topic Type := strings . TrimPrefix ( topicARN , minioTopic + serverConfig . GetRegion ( ) + ":" )
switch {
case strings . HasSuffix ( lambdaType , lambda TypeMinio) :
lambda . Type = lambda TypeMinio
} // Add more lambda here.
lambda . AccountID = strings . TrimSuffix ( lambda Type, ":" + lambda . Type )
return lambda
case strings . HasSuffix ( topicType , sns TypeMinio) :
topic . Type = sns TypeMinio
} // Add more topic here.
topic . AccountID = strings . TrimSuffix ( topic Type, ":" + topic . Type )
return topic
}
// Unmarshals input value of AWS ARN format into minioSqs object.