Esempio n. 1
0
// This is the approximate behavior of AWS SQS API. It seems a little weird in many cases, however, it works.
func ParseCreateQueueAttributes(sqsQuery *urlutils.SQSQuery) (*QueueAttributes, *sqserr.SQSError) {
	var err *sqserr.SQSError
	out := NewQueueAttributes()
	attrs, err := urlutils.ParseNNotationAttr("Attribute.", sqsQuery.ParamsList, nil, NewReqQueueAttr)
	if err != nil {
		return nil, err
	}

	attrsSize := len(attrs)

	for i := 1; i <= attrsSize; i++ {
		v, ok := attrs[i]
		if !ok {
			return nil, sqserr.MalformedInputError("End of list found where not expected")
		}
		reqAttr, _ := v.(*ReqQueueAttr)
		if reqAttr.Name == "" {
			return nil, sqserr.MalformedInputError("End of list found where not expected")
		}
		if reqAttr.Value == "" {
			return nil, sqserr.EmptyValueError("No Value Found for " + reqAttr.Name)
		}
		err = out.HandleAttribute(reqAttr.Name, reqAttr.Value)
		if err != nil {
			return nil, err
		}
	}
	return out, nil
}
func ChangeMessageVisibility(pq *pqueue.PQueue, sqsQuery *urlutils.SQSQuery) sqs_response.SQSResponse {
	var receipt string
	var visibilityTimeout int64 = -1
	paramsLen := len(sqsQuery.ParamsList) - 1

	for i := 0; i < paramsLen; i += 2 {
		switch sqsQuery.ParamsList[i] {
		case "ReceiptHandle":
			receipt = sqsQuery.ParamsList[i+1]
		case "VisibilityTimeout":
			v, err := strconv.ParseInt(sqsQuery.ParamsList[i+1], 10, 0)
			if err != nil || v < 0 {
				return sqserr.MalformedInputError("VisibilityTimeout must be a positive integer value")
			}
			visibilityTimeout = v * 1000
		}
	}

	if receipt == "" {
		return sqserr.MissingParameterError("The request must contain the parameter ReceiptHandle.")
	}

	if visibilityTimeout < 0 {
		return sqserr.MissingParameterError("The request must contain the parameter VisibilityTimeout.")
	}

	resp := pq.UpdateLockByRcpt(receipt, visibilityTimeout)
	if resp == mpqerr.ERR_INVALID_RECEIPT {
		return sqserr.InvalidReceiptHandleError("The input receipt handle is not a valid receipt handle.")
	}

	return &ChangeMessageVisibilityResponse{
		RequestId: "cvtreq",
	}
}
Esempio n. 3
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
}
Esempio n. 4
0
func ParseNNotationAttr(prefix string, paramList []string, mainHandler ParamFunc, sc NewSubContainer) (map[int]ISubContainer, *sqserr.SQSError) {
	res := make(map[int]ISubContainer, len(paramList))
	pos := 0
	paramLen := len(paramList) - 1
	for ; pos < paramLen; pos += 2 {
		attrName := paramList[pos]
		if strings.HasPrefix(attrName, prefix) {
			blocks := strings.SplitN(attrName, ".", 3)
			if len(blocks) != 3 {
				return nil, sqserr.MalformedInputError("key: " + attrName + " is malformed")
			}
			v, err := strconv.Atoi(blocks[1])
			if err == nil {
				c, ok := res[v]
				if !ok {
					c = sc()
					res[v] = c
				}
				if err := c.Parse(blocks[2], paramList[pos+1]); err != nil {
					return nil, err
				}
			}
		} else if mainHandler != nil {
			mainHandler(attrName, paramList[pos+1])
		}
	}
	return res, nil
}
Esempio n. 5
0
func (self *ReceiveMessageOptions) Parse(paramName, value string) *sqserr.SQSError {
	var err error
	switch paramName {
	case "VisibilityTimeout":
		self.VisibilityTimeout, err = strconv.ParseInt(value, 10, 0)
		if err != nil {
			return sqserr.MalformedInputError("VisibilityTimeout must be a positive integer value")
		}
		self.VisibilityTimeout *= 1000
		return nil
	case "WaitTimeSeconds":
		self.WaitTimeSeconds, err = strconv.ParseInt(value, 10, 0)
		if err != nil {
			return sqserr.MalformedInputError("WaitTimeSeconds must be a positive integer value")
		}
		self.WaitTimeSeconds *= 1000
		return nil
	case "MaxNumberOfMessages":
		self.MaxNumberOfMessages, err = strconv.ParseInt(value, 10, 0)
		if err != nil {
			return sqserr.MalformedInputError("MaxNumberOfMessages must be a positive integer value")
		}
		return nil
	}

	if strings.HasPrefix(paramName, "AttributeName") {
		if value == AttrAll {
			self.AllSysAttributes = true
		} else {
			self.Attributes = append(self.Attributes, value)
		}
	} else if strings.HasPrefix(paramName, "MessageAttributeName") {
		if value == AttrAll {
			self.AllMessageAttributes = true
		} else {
			self.MessageAttributes = append(self.MessageAttributes, value)
		}
	}

	return nil
}
func (self *VisibilityBatchParams) Parse(paramName, value string) *sqserr.SQSError {
	switch paramName {
	case "Id":
		self.Id = value
	case "ReceiptHandle":
		self.ReceiptHandle = value
	case "VisibilityTimeout":
		v, err := strconv.ParseInt(value, 10, 0)
		if err != nil || v < 0 {
			return sqserr.MalformedInputError("VisibilityTimeout must be a positive integer value")
		}
		self.VisibilityTimeout = v * 1000
	}
	return nil
}
Esempio n. 7
0
func (mp *MessageParams) Parse(paramName, value string) *sqserr.SQSError {
	var err error
	switch paramName {
	case "DelaySeconds":
		mp.DelaySeconds, err = strconv.ParseInt(value, 10, 0)
		mp.DelaySeconds *= 1000
	case "MessageBody":
		mp.MessageBody = value
	}

	if err != nil {
		return sqserr.MalformedInputError("Invalid value for the parameter " + paramName)
	}

	return nil
}