-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
127 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package kms | ||
package itest | ||
|
||
import ( | ||
"context" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package sqs | ||
|
||
import "aws-in-a-box/awserrors" | ||
|
||
func XXXTodoException(message string) *awserrors.Error { | ||
return &awserrors.Error{ | ||
Code: 400, | ||
Body: awserrors.ErrorBody{ | ||
Type: "XXXTodoException", | ||
Message: message, | ||
}, | ||
} | ||
} | ||
|
||
func QueueNameExists(message string) *awserrors.Error { | ||
return awserrors.Generate400Exception("QueueNameExists", message) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package sqs | ||
|
||
import ( | ||
"golang.org/x/exp/slog" | ||
|
||
"aws-in-a-box/http" | ||
) | ||
|
||
const service = "TODO" | ||
|
||
func (s *SQS) RegisterHTTPHandlers(logger *slog.Logger, methodRegistry http.Registry) { | ||
http.Register(logger, methodRegistry, service, "CreateQueue", s.CreateQueue) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package sqs | ||
|
||
import ( | ||
"sync" | ||
|
||
"golang.org/x/exp/maps" | ||
"golang.org/x/exp/slog" | ||
|
||
"aws-in-a-box/arn" | ||
"aws-in-a-box/awserrors" | ||
) | ||
|
||
type Queue struct { | ||
// Immutable | ||
CreationTimestamp int64 | ||
Attributes map[string]string | ||
URL string | ||
|
||
// Mutable | ||
Messages []byte | ||
Tags map[string]string | ||
} | ||
|
||
type SQS struct { | ||
logger *slog.Logger | ||
arnGenerator arn.Generator | ||
|
||
mu sync.Mutex | ||
queues map[string]Queue | ||
tags map[string]string | ||
} | ||
|
||
type Options struct { | ||
Logger *slog.Logger | ||
ArnGenerator arn.Generator | ||
} | ||
|
||
func New(options Options) *SQS { | ||
if options.Logger == nil { | ||
options.Logger = slog.Default() | ||
} | ||
|
||
s := &SQS{ | ||
logger: options.Logger, | ||
arnGenerator: options.ArnGenerator, | ||
} | ||
|
||
return s | ||
} | ||
|
||
// https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_CreateQueue.html | ||
func (s *SQS) CreateQueue(input CreateQueueInput) (*CreateQueueOutput, *awserrors.Error) { | ||
s.mu.Lock() | ||
defer s.mu.Unlock() | ||
|
||
if queue, ok := s.queues[input.QueueName]; ok { | ||
if maps.Equal(queue.Attributes, input.Attributes) { | ||
return &CreateQueueOutput{ | ||
QueueUrl: queue.URL, | ||
}, nil | ||
} | ||
return nil, QueueNameExists("") | ||
} | ||
|
||
s.queues[input.QueueName] = Queue{ | ||
Attributes: input.Attributes, | ||
Tags: input.Tags, | ||
URL: "TODO", | ||
} | ||
|
||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package sqs | ||
|
||
type CreateQueueInput struct { | ||
Attributes map[string]string | ||
QueueName string | ||
Tags map[string]string `json:"tags"` | ||
} | ||
|
||
type CreateQueueOutput struct { | ||
QueueUrl string | ||
} |