Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

display current region #890

Merged
merged 5 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions frontend/types/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 21 additions & 3 deletions frontend/views/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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();
Expand All @@ -51,6 +52,10 @@ const Overview = () => {
// eslint-disable-next-line
}, [queues, listItemIndex]);

useEffect(() => {
receiveRegion();
}, []);

useEffect(() => {
callApi({
method: "GET",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -143,7 +158,7 @@ const Overview = () => {
action: "SendMessage",
queue: queues[listItemIndex],
message: message,
onSuccess: () => {},
onSuccess: () => { },
onError: setError,
});
} else {
Expand Down Expand Up @@ -174,6 +189,9 @@ const Overview = () => {
<Typography variant="subtitle2" margin={"auto"}>
{process.env.REACT_APP_VERSION}
</Typography>
<Typography variant="subtitle2" margin={"auto"}>
{region.region}
</Typography>
</ListItem>
<ListItem>
<Toolbar
Expand Down Expand Up @@ -254,7 +272,7 @@ const Overview = () => {
<Container maxWidth="md">
<MuiAlert severity="info">
<AlertTitle>No Queue</AlertTitle>
No Queues exist in region (default was "eu-central-1")
{`No Queues exist in region: ${region.region ? region.region + " " : ""}(default is "eu-central-1")`}
</MuiAlert>
</Container>
) : null}
Expand Down
10 changes: 8 additions & 2 deletions frontend/views/__snapshots__/Overview.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Object {
<h6
class="MuiTypography-root MuiTypography-subtitle2 css-787bb5-MuiTypography-root"
/>
<h6
class="MuiTypography-root MuiTypography-subtitle2 css-787bb5-MuiTypography-root"
/>
</li>
<li
class="MuiListItem-root MuiListItem-gutters MuiListItem-padding css-1p823my-MuiListItem-root"
Expand Down Expand Up @@ -136,7 +139,7 @@ Object {
>
No Queue
</div>
No Queues exist in region (default was "eu-central-1")
No Queues exist in region: (default is "eu-central-1")
</div>
</div>
</div>
Expand Down Expand Up @@ -175,6 +178,9 @@ Object {
<h6
class="MuiTypography-root MuiTypography-subtitle2 css-787bb5-MuiTypography-root"
/>
<h6
class="MuiTypography-root MuiTypography-subtitle2 css-787bb5-MuiTypography-root"
/>
</li>
<li
class="MuiListItem-root MuiListItem-gutters MuiListItem-padding css-1p823my-MuiListItem-root"
Expand Down Expand Up @@ -280,7 +286,7 @@ Object {
>
No Queue
</div>
No Queues exist in region (default was "eu-central-1")
No Queues exist in region: (default is "eu-central-1")
</div>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions server/aws/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ type Request struct {
SqsQueue SqsQueue `json:"queue"`
SqsMessage SqsMessage `json:"message"`
}

type AwsRegion struct {
Region string `json:"region"`
}
14 changes: 12 additions & 2 deletions server/handler/sqsHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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{
Expand Down
21 changes: 17 additions & 4 deletions server/handler/sqsHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down