| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-12 06:44:27 +08:00
										 |  |  | import ( | 
					
						
							| 
									
										
										
										
											2017-05-16 09:17:02 +08:00
										 |  |  | 	"errors" | 
					
						
							| 
									
										
										
										
											2017-04-12 06:44:27 +08:00
										 |  |  | 	"strings" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/minio/minio-go/pkg/set" | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | // List of valid event types.
 | 
					
						
							|  |  |  | var suppportedEventTypes = map[string]struct{}{ | 
					
						
							|  |  |  | 	// Object created event types.
 | 
					
						
							|  |  |  | 	"s3:ObjectCreated:*":                       {}, | 
					
						
							|  |  |  | 	"s3:ObjectCreated:Put":                     {}, | 
					
						
							|  |  |  | 	"s3:ObjectCreated:Post":                    {}, | 
					
						
							|  |  |  | 	"s3:ObjectCreated:Copy":                    {}, | 
					
						
							|  |  |  | 	"s3:ObjectCreated:CompleteMultipartUpload": {}, | 
					
						
							|  |  |  | 	// Object removed event types.
 | 
					
						
							|  |  |  | 	"s3:ObjectRemoved:*":      {}, | 
					
						
							|  |  |  | 	"s3:ObjectRemoved:Delete": {}, | 
					
						
							| 
									
										
										
										
											2017-03-22 01:32:17 +08:00
										 |  |  | 	"s3:ObjectAccessed:Get":   {}, | 
					
						
							|  |  |  | 	"s3:ObjectAccessed:Head":  {}, | 
					
						
							|  |  |  | 	"s3:ObjectAccessed:*":     {}, | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // checkEvent - checks if an event is supported.
 | 
					
						
							|  |  |  | func checkEvent(event string) APIErrorCode { | 
					
						
							|  |  |  | 	_, ok := suppportedEventTypes[event] | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return ErrEventNotification | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return ErrNone | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // checkEvents - checks given list of events if all of them are valid.
 | 
					
						
							|  |  |  | // given if one of them is invalid, this function returns an error.
 | 
					
						
							|  |  |  | func checkEvents(events []string) APIErrorCode { | 
					
						
							|  |  |  | 	for _, event := range events { | 
					
						
							|  |  |  | 		if s3Error := checkEvent(event); s3Error != ErrNone { | 
					
						
							|  |  |  | 			return s3Error | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return ErrNone | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-26 08:53:55 +08:00
										 |  |  | // Valid if filterName is 'prefix'.
 | 
					
						
							|  |  |  | func isValidFilterNamePrefix(filterName string) bool { | 
					
						
							|  |  |  | 	return "prefix" == filterName | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Valid if filterName is 'suffix'.
 | 
					
						
							|  |  |  | func isValidFilterNameSuffix(filterName string) bool { | 
					
						
							|  |  |  | 	return "suffix" == filterName | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Is this a valid filterName? - returns true if valid.
 | 
					
						
							|  |  |  | func isValidFilterName(filterName string) bool { | 
					
						
							|  |  |  | 	return isValidFilterNamePrefix(filterName) || isValidFilterNameSuffix(filterName) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // checkFilterRules - checks given list of filter rules if all of them are valid.
 | 
					
						
							|  |  |  | func checkFilterRules(filterRules []filterRule) APIErrorCode { | 
					
						
							|  |  |  | 	ruleSetMap := make(map[string]string) | 
					
						
							|  |  |  | 	// Validate all filter rules.
 | 
					
						
							|  |  |  | 	for _, filterRule := range filterRules { | 
					
						
							|  |  |  | 		// Unknown filter rule name found, returns an appropriate error.
 | 
					
						
							|  |  |  | 		if !isValidFilterName(filterRule.Name) { | 
					
						
							|  |  |  | 			return ErrFilterNameInvalid | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Filter names should not be set twice per notification service
 | 
					
						
							|  |  |  | 		// configuration, if found return an appropriate error.
 | 
					
						
							|  |  |  | 		if _, ok := ruleSetMap[filterRule.Name]; ok { | 
					
						
							|  |  |  | 			if isValidFilterNamePrefix(filterRule.Name) { | 
					
						
							|  |  |  | 				return ErrFilterNamePrefix | 
					
						
							|  |  |  | 			} else if isValidFilterNameSuffix(filterRule.Name) { | 
					
						
							|  |  |  | 				return ErrFilterNameSuffix | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				return ErrFilterNameInvalid | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if !IsValidObjectPrefix(filterRule.Value) { | 
					
						
							| 
									
										
										
										
											2016-08-19 03:00:01 +08:00
										 |  |  | 			return ErrFilterValueInvalid | 
					
						
							| 
									
										
										
										
											2016-07-26 08:53:55 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Set the new rule name to keep track of duplicates.
 | 
					
						
							|  |  |  | 		ruleSetMap[filterRule.Name] = filterRule.Value | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	// Success all prefixes validated.
 | 
					
						
							|  |  |  | 	return ErrNone | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 07:34:03 +08:00
										 |  |  | // Checks validity of input ARN for a given arnType.
 | 
					
						
							|  |  |  | func checkARN(arn, arnType string) APIErrorCode { | 
					
						
							|  |  |  | 	if !strings.HasPrefix(arn, arnType) { | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | 		return ErrARNNotification | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-05-16 09:17:02 +08:00
										 |  |  | 	strs := strings.SplitN(arn, ":", -1) | 
					
						
							|  |  |  | 	if len(strs) != 6 { | 
					
						
							| 
									
										
										
										
											2016-08-18 07:34:03 +08:00
										 |  |  | 		return ErrARNNotification | 
					
						
							| 
									
										
										
										
											2017-05-16 09:17:02 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-10-28 06:09:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Server region is allowed to be empty by default,
 | 
					
						
							|  |  |  | 	// in such a scenario ARN region is not validating
 | 
					
						
							|  |  |  | 	// allowing all regions.
 | 
					
						
							| 
									
										
										
										
											2017-11-30 05:12:47 +08:00
										 |  |  | 	if sregion := globalServerConfig.GetRegion(); sregion != "" { | 
					
						
							| 
									
										
										
										
											2017-05-16 09:17:02 +08:00
										 |  |  | 		region := strs[3] | 
					
						
							| 
									
										
										
										
											2017-10-28 06:09:55 +08:00
										 |  |  | 		if region != sregion { | 
					
						
							| 
									
										
										
										
											2017-05-16 09:17:02 +08:00
										 |  |  | 			return ErrRegionNotification | 
					
						
							| 
									
										
										
										
											2016-08-18 07:34:03 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-05-16 09:17:02 +08:00
										 |  |  | 	accountID := strs[4] | 
					
						
							|  |  |  | 	resource := strs[5] | 
					
						
							|  |  |  | 	if accountID == "" || resource == "" { | 
					
						
							|  |  |  | 		return ErrARNNotification | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-08-05 13:01:58 +08:00
										 |  |  | 	return ErrNone | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 07:34:03 +08:00
										 |  |  | // checkQueueARN - check if the queue arn is valid.
 | 
					
						
							|  |  |  | func checkQueueARN(queueARN string) APIErrorCode { | 
					
						
							|  |  |  | 	return checkARN(queueARN, minioSqs) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-05 13:01:58 +08:00
										 |  |  | // Validates account id for input queue ARN.
 | 
					
						
							|  |  |  | func isValidQueueID(queueARN string) bool { | 
					
						
							|  |  |  | 	// Unmarshals QueueARN into structured object.
 | 
					
						
							|  |  |  | 	sqsARN := unmarshalSqsARN(queueARN) | 
					
						
							| 
									
										
										
										
											2016-09-17 08:26:27 +08:00
										 |  |  | 	// Is Queue identifier valid?.
 | 
					
						
							| 
									
										
										
										
											2017-01-10 06:22:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-17 08:26:27 +08:00
										 |  |  | 	if isAMQPQueue(sqsARN) { // AMQP eueue.
 | 
					
						
							| 
									
										
										
										
											2017-11-30 05:12:47 +08:00
										 |  |  | 		amqpN := globalServerConfig.Notify.GetAMQPByID(sqsARN.AccountID) | 
					
						
							| 
									
										
										
										
											2016-08-05 13:01:58 +08:00
										 |  |  | 		return amqpN.Enable && amqpN.URL != "" | 
					
						
							| 
									
										
										
										
											2017-06-15 08:27:03 +08:00
										 |  |  | 	} else if isMQTTQueue(sqsARN) { | 
					
						
							| 
									
										
										
										
											2017-11-30 05:12:47 +08:00
										 |  |  | 		mqttN := globalServerConfig.Notify.GetMQTTByID(sqsARN.AccountID) | 
					
						
							| 
									
										
										
										
											2017-06-15 08:27:03 +08:00
										 |  |  | 		return mqttN.Enable && mqttN.Broker != "" | 
					
						
							| 
									
										
										
										
											2016-09-30 14:42:10 +08:00
										 |  |  | 	} else if isNATSQueue(sqsARN) { | 
					
						
							| 
									
										
										
										
											2017-11-30 05:12:47 +08:00
										 |  |  | 		natsN := globalServerConfig.Notify.GetNATSByID(sqsARN.AccountID) | 
					
						
							| 
									
										
										
										
											2016-09-30 14:42:10 +08:00
										 |  |  | 		return natsN.Enable && natsN.Address != "" | 
					
						
							| 
									
										
										
										
											2016-08-05 13:01:58 +08:00
										 |  |  | 	} else if isElasticQueue(sqsARN) { // Elastic queue.
 | 
					
						
							| 
									
										
										
										
											2017-11-30 05:12:47 +08:00
										 |  |  | 		elasticN := globalServerConfig.Notify.GetElasticSearchByID(sqsARN.AccountID) | 
					
						
							| 
									
										
										
										
											2016-08-05 13:01:58 +08:00
										 |  |  | 		return elasticN.Enable && elasticN.URL != "" | 
					
						
							|  |  |  | 	} else if isRedisQueue(sqsARN) { // Redis queue.
 | 
					
						
							| 
									
										
										
										
											2017-11-30 05:12:47 +08:00
										 |  |  | 		redisN := globalServerConfig.Notify.GetRedisByID(sqsARN.AccountID) | 
					
						
							| 
									
										
										
										
											2016-08-05 13:01:58 +08:00
										 |  |  | 		return redisN.Enable && redisN.Addr != "" | 
					
						
							| 
									
										
										
										
											2016-10-04 08:29:55 +08:00
										 |  |  | 	} else if isPostgreSQLQueue(sqsARN) { | 
					
						
							| 
									
										
										
										
											2017-11-30 05:12:47 +08:00
										 |  |  | 		pgN := globalServerConfig.Notify.GetPostgreSQLByID(sqsARN.AccountID) | 
					
						
							| 
									
										
										
										
											2016-10-04 08:29:55 +08:00
										 |  |  | 		// Postgres can work with only default conn. info.
 | 
					
						
							|  |  |  | 		return pgN.Enable | 
					
						
							| 
									
										
										
										
											2017-03-18 00:29:17 +08:00
										 |  |  | 	} else if isMySQLQueue(sqsARN) { | 
					
						
							| 
									
										
										
										
											2017-11-30 05:12:47 +08:00
										 |  |  | 		msqlN := globalServerConfig.Notify.GetMySQLByID(sqsARN.AccountID) | 
					
						
							| 
									
										
										
										
											2017-03-18 00:29:17 +08:00
										 |  |  | 		// Mysql can work with only default conn. info.
 | 
					
						
							|  |  |  | 		return msqlN.Enable | 
					
						
							| 
									
										
										
										
											2016-12-16 00:23:48 +08:00
										 |  |  | 	} else if isKafkaQueue(sqsARN) { | 
					
						
							| 
									
										
										
										
											2017-11-30 05:12:47 +08:00
										 |  |  | 		kafkaN := globalServerConfig.Notify.GetKafkaByID(sqsARN.AccountID) | 
					
						
							| 
									
										
										
										
											2016-12-16 00:23:48 +08:00
										 |  |  | 		return (kafkaN.Enable && len(kafkaN.Brokers) > 0 && | 
					
						
							|  |  |  | 			kafkaN.Topic != "") | 
					
						
							| 
									
										
										
										
											2017-01-10 06:22:10 +08:00
										 |  |  | 	} else if isWebhookQueue(sqsARN) { | 
					
						
							| 
									
										
										
										
											2017-11-30 05:12:47 +08:00
										 |  |  | 		webhookN := globalServerConfig.Notify.GetWebhookByID(sqsARN.AccountID) | 
					
						
							| 
									
										
										
										
											2017-01-10 06:22:10 +08:00
										 |  |  | 		return webhookN.Enable && webhookN.Endpoint != "" | 
					
						
							| 
									
										
										
										
											2016-08-05 13:01:58 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return false | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | // Check - validates queue configuration and returns error if any.
 | 
					
						
							|  |  |  | func checkQueueConfig(qConfig queueConfig) APIErrorCode { | 
					
						
							|  |  |  | 	// Check queue arn is valid.
 | 
					
						
							| 
									
										
										
										
											2016-08-05 13:01:58 +08:00
										 |  |  | 	if s3Error := checkQueueARN(qConfig.QueueARN); s3Error != ErrNone { | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | 		return s3Error | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-05 13:01:58 +08:00
										 |  |  | 	// Validate if the account ID is correct.
 | 
					
						
							|  |  |  | 	if !isValidQueueID(qConfig.QueueARN) { | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | 		return ErrARNNotification | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Check if valid events are set in queue config.
 | 
					
						
							|  |  |  | 	if s3Error := checkEvents(qConfig.Events); s3Error != ErrNone { | 
					
						
							|  |  |  | 		return s3Error | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-26 08:53:55 +08:00
										 |  |  | 	// Check if valid filters are set in queue config.
 | 
					
						
							|  |  |  | 	if s3Error := checkFilterRules(qConfig.Filter.Key.FilterRules); s3Error != ErrNone { | 
					
						
							|  |  |  | 		return s3Error | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | 	// Success.
 | 
					
						
							|  |  |  | 	return ErrNone | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Validates all incoming queue configs, checkQueueConfig 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 validateQueueConfigs(queueConfigs []queueConfig) APIErrorCode { | 
					
						
							|  |  |  | 	for _, qConfig := range queueConfigs { | 
					
						
							|  |  |  | 		if s3Error := checkQueueConfig(qConfig); s3Error != ErrNone { | 
					
						
							|  |  |  | 			return s3Error | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	// Success.
 | 
					
						
							|  |  |  | 	return ErrNone | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-24 09:42:30 +08:00
										 |  |  | // Check all the queue configs for any duplicates.
 | 
					
						
							|  |  |  | func checkDuplicateQueueConfigs(configs []queueConfig) APIErrorCode { | 
					
						
							| 
									
										
										
										
											2017-04-12 06:44:27 +08:00
										 |  |  | 	queueConfigARNS := set.NewStringSet() | 
					
						
							| 
									
										
										
										
											2016-08-24 09:42:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Navigate through each configs and count the entries.
 | 
					
						
							|  |  |  | 	for _, config := range configs { | 
					
						
							| 
									
										
										
										
											2017-04-12 06:44:27 +08:00
										 |  |  | 		queueConfigARNS.Add(config.QueueARN) | 
					
						
							| 
									
										
										
										
											2016-08-24 09:42:30 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-12 06:44:27 +08:00
										 |  |  | 	if len(queueConfigARNS) != len(configs) { | 
					
						
							| 
									
										
										
										
											2016-08-26 15:11:53 +08:00
										 |  |  | 		return ErrOverlappingConfigs | 
					
						
							| 
									
										
										
										
											2016-08-24 09:42:30 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Success.
 | 
					
						
							|  |  |  | 	return ErrNone | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | // Validates all the bucket notification configuration for their validity,
 | 
					
						
							|  |  |  | // if one of the config is malformed or has invalid data it is rejected.
 | 
					
						
							|  |  |  | // Configuration is never applied partially.
 | 
					
						
							|  |  |  | func validateNotificationConfig(nConfig notificationConfig) APIErrorCode { | 
					
						
							| 
									
										
										
										
											2017-08-24 06:58:02 +08:00
										 |  |  | 	// Minio server does not support lambda/topic configurations
 | 
					
						
							|  |  |  | 	// currently. Such configuration is rejected.
 | 
					
						
							|  |  |  | 	if len(nConfig.LambdaConfigs) > 0 || len(nConfig.TopicConfigs) > 0 { | 
					
						
							|  |  |  | 		return ErrUnsupportedNotification | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-24 09:42:30 +08:00
										 |  |  | 	// Validate all queue configs.
 | 
					
						
							| 
									
										
										
										
											2016-08-05 13:01:58 +08:00
										 |  |  | 	if s3Error := validateQueueConfigs(nConfig.QueueConfigs); s3Error != ErrNone { | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | 		return s3Error | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-08-05 13:01:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-24 09:42:30 +08:00
										 |  |  | 	// Check for duplicate queue configs.
 | 
					
						
							| 
									
										
										
										
											2016-08-26 15:11:53 +08:00
										 |  |  | 	if len(nConfig.QueueConfigs) > 1 { | 
					
						
							|  |  |  | 		if s3Error := checkDuplicateQueueConfigs(nConfig.QueueConfigs); s3Error != ErrNone { | 
					
						
							|  |  |  | 			return s3Error | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-08-24 09:42:30 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-08-26 15:11:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | 	// Add validation for other configurations.
 | 
					
						
							|  |  |  | 	return ErrNone | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Unmarshals input value of AWS ARN format into minioSqs object.
 | 
					
						
							|  |  |  | // Returned value represents minio sqs types, currently supported are
 | 
					
						
							|  |  |  | // - amqp
 | 
					
						
							| 
									
										
										
										
											2017-06-15 08:27:03 +08:00
										 |  |  | // - mqtt
 | 
					
						
							| 
									
										
										
										
											2016-09-30 14:42:10 +08:00
										 |  |  | // - nats
 | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | // - elasticsearch
 | 
					
						
							| 
									
										
										
										
											2016-07-26 08:53:55 +08:00
										 |  |  | // - redis
 | 
					
						
							| 
									
										
										
										
											2016-10-04 08:29:55 +08:00
										 |  |  | // - postgresql
 | 
					
						
							| 
									
										
										
										
											2017-03-18 00:29:17 +08:00
										 |  |  | // - mysql
 | 
					
						
							| 
									
										
										
										
											2016-12-16 00:23:48 +08:00
										 |  |  | // - kafka
 | 
					
						
							| 
									
										
										
										
											2017-01-10 06:22:10 +08:00
										 |  |  | // - webhook
 | 
					
						
							| 
									
										
										
										
											2016-08-05 13:01:58 +08:00
										 |  |  | func unmarshalSqsARN(queueARN string) (mSqs arnSQS) { | 
					
						
							| 
									
										
										
										
											2017-05-16 09:17:02 +08:00
										 |  |  | 	strs := strings.SplitN(queueARN, ":", -1) | 
					
						
							|  |  |  | 	if len(strs) != 6 { | 
					
						
							| 
									
										
										
										
											2017-06-08 08:24:46 +08:00
										 |  |  | 		return | 
					
						
							| 
									
										
										
										
											2016-08-05 13:01:58 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-10-28 06:09:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Server region is allowed to be empty by default,
 | 
					
						
							|  |  |  | 	// in such a scenario ARN region is not validating
 | 
					
						
							|  |  |  | 	// allowing all regions.
 | 
					
						
							| 
									
										
										
										
											2017-11-30 05:12:47 +08:00
										 |  |  | 	if sregion := globalServerConfig.GetRegion(); sregion != "" { | 
					
						
							| 
									
										
										
										
											2017-05-16 09:17:02 +08:00
										 |  |  | 		region := strs[3] | 
					
						
							| 
									
										
										
										
											2017-10-28 06:09:55 +08:00
										 |  |  | 		if region != sregion { | 
					
						
							| 
									
										
										
										
											2017-06-08 08:24:46 +08:00
										 |  |  | 			return | 
					
						
							| 
									
										
										
										
											2017-05-16 09:17:02 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	sqsType := strs[5] | 
					
						
							|  |  |  | 	switch sqsType { | 
					
						
							|  |  |  | 	case queueTypeAMQP: | 
					
						
							| 
									
										
										
										
											2016-08-05 13:01:58 +08:00
										 |  |  | 		mSqs.Type = queueTypeAMQP | 
					
						
							| 
									
										
										
										
											2017-06-15 08:27:03 +08:00
										 |  |  | 	case queueTypeMQTT: | 
					
						
							|  |  |  | 		mSqs.Type = queueTypeMQTT | 
					
						
							| 
									
										
										
										
											2017-05-16 09:17:02 +08:00
										 |  |  | 	case queueTypeNATS: | 
					
						
							| 
									
										
										
										
											2016-09-30 14:42:10 +08:00
										 |  |  | 		mSqs.Type = queueTypeNATS | 
					
						
							| 
									
										
										
										
											2017-05-16 09:17:02 +08:00
										 |  |  | 	case queueTypeElastic: | 
					
						
							| 
									
										
										
										
											2016-08-05 13:01:58 +08:00
										 |  |  | 		mSqs.Type = queueTypeElastic | 
					
						
							| 
									
										
										
										
											2017-05-16 09:17:02 +08:00
										 |  |  | 	case queueTypeRedis: | 
					
						
							| 
									
										
										
										
											2016-08-05 13:01:58 +08:00
										 |  |  | 		mSqs.Type = queueTypeRedis | 
					
						
							| 
									
										
										
										
											2017-05-16 09:17:02 +08:00
										 |  |  | 	case queueTypePostgreSQL: | 
					
						
							| 
									
										
										
										
											2016-10-04 08:29:55 +08:00
										 |  |  | 		mSqs.Type = queueTypePostgreSQL | 
					
						
							| 
									
										
										
										
											2017-05-16 09:17:02 +08:00
										 |  |  | 	case queueTypeMySQL: | 
					
						
							| 
									
										
										
										
											2017-03-18 00:29:17 +08:00
										 |  |  | 		mSqs.Type = queueTypeMySQL | 
					
						
							| 
									
										
										
										
											2017-05-16 09:17:02 +08:00
										 |  |  | 	case queueTypeKafka: | 
					
						
							| 
									
										
										
										
											2016-12-16 00:23:48 +08:00
										 |  |  | 		mSqs.Type = queueTypeKafka | 
					
						
							| 
									
										
										
										
											2017-05-16 09:17:02 +08:00
										 |  |  | 	case queueTypeWebhook: | 
					
						
							| 
									
										
										
										
											2017-01-10 06:22:10 +08:00
										 |  |  | 		mSqs.Type = queueTypeWebhook | 
					
						
							| 
									
										
										
										
											2017-05-16 09:17:02 +08:00
										 |  |  | 	default: | 
					
						
							|  |  |  | 		errorIf(errors.New("invalid SQS type"), "SQS type: %s", sqsType) | 
					
						
							| 
									
										
										
										
											2016-08-05 13:01:58 +08:00
										 |  |  | 	} // Add more queues here.
 | 
					
						
							| 
									
										
										
										
											2017-05-16 09:17:02 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	mSqs.AccountID = strs[4] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-08 08:24:46 +08:00
										 |  |  | 	return | 
					
						
							| 
									
										
										
										
											2016-07-24 13:51:12 +08:00
										 |  |  | } |