- Standalone SQS-service repository - Multi-tenant message queue service, AWS SQS compatible - Based on GoAws, with mutable tenants, auth, WebUI, Redis persistence - Ready for independent development and deployment - See doc/ and README.md for architecture and usage
119 lines
4.4 KiB
Go
119 lines
4.4 KiB
Go
// Изменено: 2026-04-09
|
|
// GetQueueAttributesV1 — возвращает атрибуты очереди тенанта.
|
|
package gosqs
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"shared-sqs/app/interfaces"
|
|
"shared-sqs/app/models"
|
|
"shared-sqs/app/utils"
|
|
"github.com/mitchellh/copystructure"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func GetQueueAttributesV1(req *http.Request) (int, interfaces.AbstractResponseBody) {
|
|
requestBody := models.NewGetQueueAttributesRequest()
|
|
ok := utils.REQUEST_TRANSFORMER(requestBody, req, false)
|
|
if !ok {
|
|
log.Error("Invalid Request - GetQueueAttributesV1")
|
|
return utils.CreateErrorResponseV1("InvalidParameterValue", true)
|
|
}
|
|
if requestBody.QueueUrl == "" {
|
|
log.Error("Missing QueueUrl - GetQueueAttributesV1")
|
|
return utils.CreateErrorResponseV1("InvalidParameterValue", true)
|
|
}
|
|
|
|
t := getTenantFromContext(req)
|
|
if t == nil {
|
|
return utils.CreateErrorResponseV1("InvalidClientTokenId", true)
|
|
}
|
|
|
|
requestedAttributes := func() map[string]bool {
|
|
attrs := map[string]bool{}
|
|
if len(requestBody.AttributeNames) == 0 {
|
|
return map[string]bool{"All": true}
|
|
}
|
|
for _, attr := range requestBody.AttributeNames {
|
|
if "All" == attr {
|
|
return map[string]bool{"All": true}
|
|
}
|
|
attrs[attr] = true
|
|
}
|
|
return attrs
|
|
}()
|
|
|
|
dupe, _ := copystructure.Copy(models.AvailableQueueAttributes)
|
|
includedAttributes, _ := dupe.(map[string]bool)
|
|
_, ok = requestedAttributes["All"]
|
|
if !ok {
|
|
for attr := range includedAttributes {
|
|
if _, ok := requestedAttributes[attr]; !ok {
|
|
delete(includedAttributes, attr)
|
|
}
|
|
}
|
|
}
|
|
|
|
uriSegments := strings.Split(requestBody.QueueUrl, "/")
|
|
queueName := uriSegments[len(uriSegments)-1]
|
|
key := tenantQueueKey(t.AccessKey, queueName)
|
|
|
|
log.Infof("Get Queue Attributes: %s (tenant: %s)", queueName, t.ID)
|
|
queueAttributes := make([]models.Attribute, 0)
|
|
|
|
models.SyncQueues.RLock()
|
|
defer models.SyncQueues.RUnlock()
|
|
queue, ok := models.SyncQueues.Queues[key]
|
|
if !ok {
|
|
log.Errorf("Get Queue Attributes: %s queue does not exist for tenant %s", queueName, t.ID)
|
|
return utils.CreateErrorResponseV1("QueueNotFound", true)
|
|
}
|
|
|
|
if _, ok := includedAttributes["DelaySeconds"]; ok {
|
|
queueAttributes = append(queueAttributes, models.Attribute{Name: "DelaySeconds", Value: strconv.Itoa(queue.DelaySeconds)})
|
|
}
|
|
if _, ok := includedAttributes["MaximumMessageSize"]; ok {
|
|
queueAttributes = append(queueAttributes, models.Attribute{Name: "MaximumMessageSize", Value: strconv.Itoa(queue.MaximumMessageSize)})
|
|
}
|
|
if _, ok := includedAttributes["MessageRetentionPeriod"]; ok {
|
|
queueAttributes = append(queueAttributes, models.Attribute{Name: "MessageRetentionPeriod", Value: strconv.Itoa(queue.MessageRetentionPeriod)})
|
|
}
|
|
if _, ok := includedAttributes["ReceiveMessageWaitTimeSeconds"]; ok {
|
|
queueAttributes = append(queueAttributes, models.Attribute{Name: "ReceiveMessageWaitTimeSeconds", Value: strconv.Itoa(queue.ReceiveMessageWaitTimeSeconds)})
|
|
}
|
|
if _, ok := includedAttributes["VisibilityTimeout"]; ok {
|
|
queueAttributes = append(queueAttributes, models.Attribute{Name: "VisibilityTimeout", Value: strconv.Itoa(queue.VisibilityTimeout)})
|
|
}
|
|
if _, ok := includedAttributes["ApproximateNumberOfMessages"]; ok {
|
|
queueAttributes = append(queueAttributes, models.Attribute{Name: "ApproximateNumberOfMessages", Value: strconv.Itoa(len(queue.Messages))})
|
|
}
|
|
if _, ok := includedAttributes["ApproximateNumberOfMessagesNotVisible"]; ok {
|
|
queueAttributes = append(queueAttributes, models.Attribute{Name: "ApproximateNumberOfMessagesNotVisible", Value: strconv.Itoa(numberOfHiddenMessagesInQueue(*queue))})
|
|
}
|
|
if _, ok := includedAttributes["CreatedTimestamp"]; ok {
|
|
queueAttributes = append(queueAttributes, models.Attribute{Name: "CreatedTimestamp", Value: "0000000000"})
|
|
}
|
|
if _, ok := includedAttributes["LastModifiedTimestamp"]; ok {
|
|
queueAttributes = append(queueAttributes, models.Attribute{Name: "LastModifiedTimestamp", Value: "0000000000"})
|
|
}
|
|
if _, ok := includedAttributes["QueueArn"]; ok {
|
|
queueAttributes = append(queueAttributes, models.Attribute{Name: "QueueArn", Value: queue.Arn})
|
|
}
|
|
if _, ok := includedAttributes["RedrivePolicy"]; ok && queue.DeadLetterQueue != nil {
|
|
queueAttributes = append(queueAttributes, models.Attribute{
|
|
Name: "RedrivePolicy",
|
|
Value: fmt.Sprintf(`{"maxReceiveCount":"%d", "deadLetterTargetArn":"%s"}`, queue.MaxReceiveCount, queue.DeadLetterQueue.Arn),
|
|
})
|
|
}
|
|
|
|
respStruct := models.GetQueueAttributesResponse{
|
|
Xmlns: models.BaseXmlns,
|
|
Result: models.GetQueueAttributesResult{Attrs: queueAttributes},
|
|
Metadata: models.BaseResponseMetadata,
|
|
}
|
|
return http.StatusOK, respStruct
|
|
}
|