예제 #1
0
func (r *QueueAttributes) HandleAttribute(paramName, value string) *sqserr.SQSError {
	var err error
	switch paramName {
	case AttrVisibilityTimeout:
		r.VisibilityTimeout, err = strconv.ParseInt(value, 10, 0)
		r.VisibilityTimeout *= 1000
	case AttrDelaySeconds:
		r.DelaySeconds, err = strconv.ParseInt(value, 10, 0)
		r.DelaySeconds *= 1000
	case AttrMaximumMessageSize:
		r.MaximumMessageSize, err = strconv.ParseInt(value, 10, 0)
	case AttrMessageRetentionPeriod:
		r.MessageRetentionPeriod, err = strconv.ParseInt(value, 10, 0)
		r.MessageRetentionPeriod *= 1000
	case AttrReceiveMessageWaitTimeSeconds:
		r.ReceiveMessageWaitTimeSeconds, err = strconv.ParseInt(value, 10, 0)
		r.ReceiveMessageWaitTimeSeconds *= 1000
	default:
		return sqserr.InvalidAttributeNameError("Unknown Attribute " + paramName + ".")
	}
	if err != nil {
		return sqserr.MalformedInputError("Invalid value for the parameter " + paramName)
	}
	return nil
}
예제 #2
0
func (r *ReqQueueAttr) Parse(paramName string, value string) *sqserr.SQSError {
	switch paramName {
	case "Name":
		r.Name = value
	case "Value":
		r.Value = value
	default:
		return sqserr.InvalidAttributeNameError("Invalid attribute: " + paramName)
	}
	return nil
}
예제 #3
0
func SetQueueAttributes(pq *pqueue.PQueue, sqsQuery *urlutils.SQSQuery) sqs_response.SQSResponse {
	attrs, err := urlutils.ParseNNotationAttr("MessageAttribute.", sqsQuery.ParamsList, nil, NewAttribute)
	if err != nil {
		return err
	}

	attrsLen := len(attrs)

	params := &pqueue.PQueueParams{}

	for i := 1; i < attrsLen; i++ {
		a, ok := attrs[i]
		if !ok {
			return sqserr.InvalidParameterValueError("The request must contain non-empty message attribute name.")
		}
		attr, _ := a.(*Attribute)
		err = nil
		switch attr.Name {
		case "DelaySeconds":
			if v, e := strconv.ParseInt(attr.Value, 10, 0); e == nil {
				v := v * 1000
				if v >= 0 && v <= conf.CFG_PQ.MaxDeliveryDelay {
					params.DeliveryDelay = &v
					continue
				}
			}
			return sqserr.InvalidAttributeValueError(AttrErrText, attr.Name)
		case "MaximumMessageSize":
			if v, e := strconv.ParseInt(attr.Value, 10, 0); e == nil {
				if v >= 1024 && v <= conf.CFG_PQ.MaxMessageSize {
					params.MaxMsgSize = &v
					continue
				}
			}
			return sqserr.InvalidAttributeValueError(AttrErrText, attr.Name)
		case "MessageRetentionPeriod":
			if v, e := strconv.ParseInt(attr.Value, 10, 0); e == nil {
				if v >= 60 && v <= 1209600 {
					v := v * 1000
					params.MsgTTL = &v
					continue
				}
			}
			return sqserr.InvalidAttributeValueError(AttrErrText, attr.Name)
		case "ReceiveMessageWaitTimeSeconds":
			if v, e := strconv.ParseInt(attr.Value, 10, 0); e == nil {
				v := v * 1000
				if v >= 60000 && v <= conf.CFG_PQ.MaxPopWaitTimeout {
					params.PopWaitTimeout = &v
					continue
				}
			}
			return sqserr.InvalidAttributeValueError(AttrErrText, attr.Name)
		case "VisibilityTimeout":
			if v, e := strconv.ParseInt(attr.Value, 10, 0); e == nil {
				v := v * 1000
				if v > 0 && v <= conf.CFG_PQ.MaxLockTimeout {
					params.PopLockTimeout = &v
					continue
				}
			}
			return sqserr.InvalidAttributeValueError(AttrErrText, attr.Name)
		// These parameters are just ignored.
		case "Policy":
		case "ApproximateNumberOfMessages":
		case "ApproximateNumberOfMessagesDelayed":
		case "ApproximateNumberOfMessagesNotVisible":
		case "CreatedTimestamp":
		case "LastModifiedTimestamp":
		case "QueueArn":
		// Any unexpected attribute will produce unexpected attribute error.
		default:
			return sqserr.InvalidAttributeNameError("Unknown Attribute: %s", attr.Name)
		}
	}

	pq.SetParams(params)
	return &SetQueueAttributesResponse{
		RequestId: "req",
	}
}