diff --git a/frontend/types/index.tsx b/frontend/types/index.tsx
index 3897a3cb..5c3099c5 100644
--- a/frontend/types/index.tsx
+++ b/frontend/types/index.tsx
@@ -28,31 +28,36 @@ export interface Queue {
QueueAttributes?: { [key: string]: string } | undefined;
}
+export interface AwsRegion {
+ region: string;
+}
+
export interface SqsMessage {
messageBody: string;
messageId?: string;
messageAttributes?:
- | {
- ApproximateFirstReceiveTimestamp?: string;
- ApproximateReceiveCount?: string;
- MessageDeduplicationId?: string;
- MessageGroupId?: string;
- SenderId?: string;
- SentTimestamp?: string;
- SequenceNumber?: string;
- CustomAttributes?: string | { [key: string]: string };
- }
- | undefined;
+ | {
+ ApproximateFirstReceiveTimestamp?: string;
+ ApproximateReceiveCount?: string;
+ MessageDeduplicationId?: string;
+ MessageGroupId?: string;
+ SenderId?: string;
+ SentTimestamp?: string;
+ SequenceNumber?: string;
+ CustomAttributes?: string | { [key: string]: string };
+ }
+ | undefined;
}
export interface ApiCall {
method: string;
action?:
- | "CreateQueue"
- | "DeleteQueue"
- | "PurgeQueue"
- | "GetMessages"
- | "SendMessage";
+ | "CreateQueue"
+ | "DeleteQueue"
+ | "PurgeQueue"
+ | "GetMessages"
+ | "SendMessage"
+ | "GetRegion";
queue?: Queue;
message?: any;
onSuccess: any;
diff --git a/frontend/views/Overview.tsx b/frontend/views/Overview.tsx
index 3b309d0d..931b30af 100644
--- a/frontend/views/Overview.tsx
+++ b/frontend/views/Overview.tsx
@@ -16,7 +16,7 @@ import {
Toolbar,
Typography,
} from "@mui/material";
-import { Queue, SqsMessage } from "../types";
+import { AwsRegion, Queue, SqsMessage } from "../types";
import CreateQueueDialog from "../components/CreateQueueDialog";
import Alert from "../components/Alert";
import useInterval from "../hooks/useInterval";
@@ -41,6 +41,7 @@ const Overview = () => {
const [reload, triggerReload] = useState(true);
const [error, setError] = useState("");
const [disabledStatus, setDisabledStatus] = useState(true);
+ const [region, setRegion] = useState({ region: "" } as AwsRegion);
useInterval(async () => {
await receiveMessageFromCurrentQueue();
@@ -51,6 +52,10 @@ const Overview = () => {
// eslint-disable-next-line
}, [queues, listItemIndex]);
+ useEffect(() => {
+ receiveRegion();
+ }, []);
+
useEffect(() => {
callApi({
method: "GET",
@@ -85,6 +90,16 @@ const Overview = () => {
}
};
+ const receiveRegion = async () => {
+ await callApi({
+ method: "POST",
+ action: "GetRegion",
+ onSuccess: setRegion,
+ queue: { QueueName: "" } as Queue,
+ onError: setError,
+ });
+ };
+
const createNewQueue = async (queue: Queue) => {
await callApi({
method: "POST",
@@ -143,7 +158,7 @@ const Overview = () => {
action: "SendMessage",
queue: queues[listItemIndex],
message: message,
- onSuccess: () => {},
+ onSuccess: () => { },
onError: setError,
});
} else {
@@ -174,6 +189,9 @@ const Overview = () => {
{process.env.REACT_APP_VERSION}
+
+ {region.region}
+
{
No Queue
- No Queues exist in region (default was "eu-central-1")
+ {`No Queues exist in region: ${region.region ? region.region + " " : ""}(default is "eu-central-1")`}
) : null}
diff --git a/frontend/views/__snapshots__/Overview.test.tsx.snap b/frontend/views/__snapshots__/Overview.test.tsx.snap
index 30b2cab4..fcebcbb3 100644
--- a/frontend/views/__snapshots__/Overview.test.tsx.snap
+++ b/frontend/views/__snapshots__/Overview.test.tsx.snap
@@ -31,6 +31,9 @@ Object {
+
No Queue
- No Queues exist in region (default was "eu-central-1")
+ No Queues exist in region: (default is "eu-central-1")
@@ -175,6 +178,9 @@ Object {
+
No Queue
- No Queues exist in region (default was "eu-central-1")
+ No Queues exist in region: (default is "eu-central-1")
diff --git a/server/aws/types/types.go b/server/aws/types/types.go
index 52be5985..ae72a729 100644
--- a/server/aws/types/types.go
+++ b/server/aws/types/types.go
@@ -17,3 +17,7 @@ type Request struct {
SqsQueue SqsQueue `json:"queue"`
SqsMessage SqsMessage `json:"message"`
}
+
+type AwsRegion struct {
+ Region string `json:"region"`
+}
diff --git a/server/handler/sqsHandler.go b/server/handler/sqsHandler.go
index 18344161..d3e53b33 100644
--- a/server/handler/sqsHandler.go
+++ b/server/handler/sqsHandler.go
@@ -2,10 +2,13 @@ package handler
import (
"fmt"
- "github.com/gorilla/mux"
- "github.com/pacoVK/aws"
"log"
"net/http"
+
+ "github.com/gorilla/mux"
+ "github.com/pacoVK/aws"
+ "github.com/pacoVK/aws/types"
+ "github.com/pacoVK/utils"
)
func WebsiteHandler() http.Handler {
@@ -60,6 +63,13 @@ func SQSHandler() Handler {
Payload: messages,
Error: err,
})
+ case "GetRegion":
+ region := utils.GetEnv("SQS_AWS_REGION", "eu-central-1")
+ response := types.AwsRegion{Region: region}
+ respondJSON(writer, Response{
+ Payload: response,
+ StatusCode: http.StatusOK,
+ })
default:
log.Printf("Unsupported action provided [%v]", payload.Action)
respondJSON(writer, Response{
diff --git a/server/handler/sqsHandler_test.go b/server/handler/sqsHandler_test.go
index e058c3dc..54b7327f 100644
--- a/server/handler/sqsHandler_test.go
+++ b/server/handler/sqsHandler_test.go
@@ -4,16 +4,17 @@ import (
"bytes"
"encoding/json"
"fmt"
- "github.com/gorilla/mux"
- "github.com/pacoVK/aws"
- "github.com/pacoVK/aws/types"
- "github.com/pacoVK/utils"
"io"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
+
+ "github.com/gorilla/mux"
+ "github.com/pacoVK/aws"
+ "github.com/pacoVK/aws/types"
+ "github.com/pacoVK/utils"
)
var router = mux.NewRouter()
@@ -153,6 +154,18 @@ func TestDeleteSqsQueues(t *testing.T) {
}
}
+func TestGetRegion(t *testing.T) {
+ var s, _ = json.Marshal(types.Request{
+ Action: "GetRegion",
+ })
+ req, _ := http.NewRequest("POST", "/sqs", bytes.NewBuffer(s))
+ response := executeRequest(req, router)
+ checkResponseCode(t, http.StatusOK, response.Code)
+ if !strings.Contains(response.Body.String(), "eu-central-1") {
+ t.Error("Did not get expected response body, got", response.Body.String())
+ }
+}
+
func TestListEmptySqsQueues(t *testing.T) {
req, _ := http.NewRequest("GET", "/sqs", nil)
response := executeRequest(req, router)