Skip to content

Commit ea0da7a

Browse files
authored
Merge pull request #410 from hookdeck/chore/sqs-target-url
chore: destawssqs target_url
2 parents 9851135 + 95b1b80 commit ea0da7a

File tree

2 files changed

+101
-1
lines changed

2 files changed

+101
-1
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package destawssqs
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestMakeAWSSQSConsoleURL(t *testing.T) {
10+
tests := []struct {
11+
name string
12+
queueURL string
13+
want string
14+
}{
15+
{
16+
name: "basic us-east-1",
17+
queueURL: "https://sqs.us-east-1.amazonaws.com/123456789012/test-queue",
18+
want: "https://us-east-1.console.aws.amazon.com/sqs/v3/home?region=us-east-1#/queues/https%3A%2F%2Fsqs.us-east-1.amazonaws.com%2F123456789012%2Ftest-queue",
19+
},
20+
{
21+
name: "different region eu-west-1",
22+
queueURL: "https://sqs.eu-west-1.amazonaws.com/987654321098/production-queue",
23+
want: "https://eu-west-1.console.aws.amazon.com/sqs/v3/home?region=eu-west-1#/queues/https%3A%2F%2Fsqs.eu-west-1.amazonaws.com%2F987654321098%2Fproduction-queue",
24+
},
25+
{
26+
name: "queue name with special characters",
27+
queueURL: "https://sqs.ap-southeast-2.amazonaws.com/111222333444/my-queue-with-dashes",
28+
want: "https://ap-southeast-2.console.aws.amazon.com/sqs/v3/home?region=ap-southeast-2#/queues/https%3A%2F%2Fsqs.ap-southeast-2.amazonaws.com%2F111222333444%2Fmy-queue-with-dashes",
29+
},
30+
{
31+
name: "localstack URL should return empty",
32+
queueURL: "http://localhost:4566/000000000000/test-queue",
33+
want: "",
34+
},
35+
{
36+
name: "non-SQS AWS URL should return empty",
37+
queueURL: "https://s3.us-east-1.amazonaws.com/my-bucket/file.txt",
38+
want: "",
39+
},
40+
{
41+
name: "invalid URL should return empty",
42+
queueURL: "not-a-url",
43+
want: "",
44+
},
45+
{
46+
name: "empty string should return empty",
47+
queueURL: "",
48+
want: "",
49+
},
50+
{
51+
name: "SQS compatible service should return empty",
52+
queueURL: "https://sqs.custom-domain.com/123456789012/queue",
53+
want: "",
54+
},
55+
{
56+
name: "SQS URL with only account ID still generates console URL",
57+
queueURL: "https://sqs.us-east-1.amazonaws.com/123456789012",
58+
want: "https://us-east-1.console.aws.amazon.com/sqs/v3/home?region=us-east-1#/queues/https%3A%2F%2Fsqs.us-east-1.amazonaws.com%2F123456789012",
59+
},
60+
{
61+
name: "SQS URL with only queue name still generates console URL",
62+
queueURL: "https://sqs.us-east-1.amazonaws.com/test-queue",
63+
want: "https://us-east-1.console.aws.amazon.com/sqs/v3/home?region=us-east-1#/queues/https%3A%2F%2Fsqs.us-east-1.amazonaws.com%2Ftest-queue",
64+
},
65+
}
66+
67+
for _, test := range tests {
68+
t.Run(test.name, func(t *testing.T) {
69+
got := makeAWSSQSConsoleURL(test.queueURL)
70+
assert.Equal(t, test.want, got)
71+
})
72+
}
73+
}

internal/destregistry/providers/destawssqs/destawssqs.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,33 @@ func ParseQueueURL(queueURL string) (baseURL string, region string, err error) {
208208
func (d *AWSSQSDestination) ComputeTarget(destination *models.Destination) destregistry.DestinationTarget {
209209
return destregistry.DestinationTarget{
210210
Target: destination.Config["queue_url"],
211-
TargetURL: "",
211+
TargetURL: makeAWSSQSConsoleURL(destination.Config["queue_url"]),
212212
}
213213
}
214+
215+
func makeAWSSQSConsoleURL(queueURL string) string {
216+
// Check if it's a valid AWS SQS URL
217+
if !strings.Contains(queueURL, ".amazonaws.com/") || !strings.Contains(queueURL, "sqs.") {
218+
return ""
219+
}
220+
221+
// Parse the URL to extract region
222+
u, err := url.Parse(queueURL)
223+
if err != nil {
224+
return ""
225+
}
226+
227+
// Extract region from hostname (e.g., sqs.us-east-1.amazonaws.com)
228+
parts := strings.Split(u.Host, ".")
229+
if len(parts) < 3 || parts[0] != "sqs" {
230+
return ""
231+
}
232+
region := parts[1]
233+
234+
// URL encode the queue URL for the fragment
235+
encodedQueueURL := url.QueryEscape(queueURL)
236+
237+
// Construct console URL with region subdomain
238+
return fmt.Sprintf("https://%s.console.aws.amazon.com/sqs/v3/home?region=%s#/queues/%s",
239+
region, region, encodedQueueURL)
240+
}

0 commit comments

Comments
 (0)