Skip to content

Commit 8804c75

Browse files
author
cesnietor
committed
Disable KMS Endpoints and Metrics Tabs if using KMS Secret Key
1 parent f562347 commit 8804c75

File tree

1 file changed

+75
-86
lines changed

1 file changed

+75
-86
lines changed

web-app/src/screens/Console/KMS/Status.tsx

Lines changed: 75 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ import {
3737
XAxis,
3838
YAxis,
3939
} from "recharts";
40-
import api from "../../../common/api";
41-
import { ErrorResponseHandler } from "../../../common/types";
4240
import { hasPermission } from "../../../common/SecureComponent";
4341
import {
4442
CONSOLE_UI_RESOURCE,
@@ -49,12 +47,16 @@ import { useAppDispatch } from "../../../store";
4947
import LabelWithIcon from "../Buckets/BucketDetails/SummaryItems/LabelWithIcon";
5048
import PageHeaderWrapper from "../Common/PageHeaderWrapper/PageHeaderWrapper";
5149
import HelpMenu from "../HelpMenu";
50+
import { api } from "api";
51+
import { KmsStatusResponse } from "api/consoleApi";
52+
import { errorToHandler } from "api/errors";
5253

5354
const Status = () => {
5455
const dispatch = useAppDispatch();
5556
const [curTab, setCurTab] = useState<string>("simple-tab-0");
5657

57-
const [status, setStatus] = useState<any | null>(null);
58+
const [isKMSSecretKey, setIsKMSSecretKey] = useState<boolean>(true);
59+
const [status, setStatus] = useState<KmsStatusResponse | null>(null);
5860
const [loadingStatus, setLoadingStatus] = useState<boolean>(true);
5961
const [metrics, setMetrics] = useState<any | null>(null);
6062
const [loadingMetrics, setLoadingMetrics] = useState<boolean>(true);
@@ -66,105 +68,84 @@ const Status = () => {
6668
const displayStatus = hasPermission(CONSOLE_UI_RESOURCE, [
6769
IAM_SCOPES.KMS_STATUS,
6870
]);
69-
const displayMetrics = hasPermission(CONSOLE_UI_RESOURCE, [
70-
IAM_SCOPES.KMS_METRICS,
71-
]);
72-
const displayAPIs = hasPermission(CONSOLE_UI_RESOURCE, [IAM_SCOPES.KMS_APIS]);
73-
const displayVersion = hasPermission(CONSOLE_UI_RESOURCE, [
74-
IAM_SCOPES.KMS_Version,
75-
]);
71+
const displayMetrics =
72+
hasPermission(CONSOLE_UI_RESOURCE, [IAM_SCOPES.KMS_METRICS]) &&
73+
!isKMSSecretKey;
74+
const displayAPIs =
75+
hasPermission(CONSOLE_UI_RESOURCE, [IAM_SCOPES.KMS_APIS]) &&
76+
!isKMSSecretKey;
77+
const displayVersion =
78+
hasPermission(CONSOLE_UI_RESOURCE, [IAM_SCOPES.KMS_Version]) &&
79+
!isKMSSecretKey;
7680

7781
useEffect(() => {
78-
setLoadingStatus(true);
79-
}, []);
82+
const loadStatus = () => {
83+
api.kms
84+
.kmsStatus()
85+
.then((result) => {
86+
if (result.data) {
87+
setStatus(result.data);
88+
setIsKMSSecretKey(result.data.name === "SecretKey");
89+
}
90+
})
91+
.catch((err) => {
92+
dispatch(setErrorSnackMessage(errorToHandler(err.error)));
93+
})
94+
.finally(() => setLoadingStatus(false));
95+
};
8096

81-
useEffect(() => {
8297
const loadMetrics = () => {
83-
if (displayMetrics) {
84-
api
85-
.invoke("GET", `/api/v1/kms/metrics`)
86-
.then((result: any) => {
87-
if (result) {
88-
setMetrics(result);
89-
}
90-
setLoadingMetrics(false);
91-
})
92-
.catch((err: ErrorResponseHandler) => {
93-
dispatch(setErrorSnackMessage(err));
94-
setLoadingMetrics(false);
95-
});
96-
} else {
97-
setLoadingMetrics(false);
98-
}
98+
api.kms
99+
.kmsMetrics()
100+
.then((result) => {
101+
if (result.data) {
102+
setMetrics(result.data);
103+
}
104+
})
105+
.catch((err) => {
106+
dispatch(setErrorSnackMessage(errorToHandler(err.error)));
107+
})
108+
.finally(() => setLoadingMetrics(false));
99109
};
100110

101111
const loadAPIs = () => {
102-
if (displayAPIs) {
103-
api
104-
.invoke("GET", `/api/v1/kms/apis`)
105-
.then((result: any) => {
106-
if (result) {
107-
setAPIs(result);
108-
}
109-
setLoadingAPIs(false);
110-
})
111-
.catch((err: ErrorResponseHandler) => {
112-
dispatch(setErrorSnackMessage(err));
113-
setLoadingAPIs(false);
114-
});
115-
} else {
116-
setLoadingAPIs(false);
117-
}
112+
api.kms
113+
.kmsapIs()
114+
.then((result: any) => {
115+
if (result.data) {
116+
setAPIs(result.data);
117+
}
118+
})
119+
.catch((err) => {
120+
dispatch(setErrorSnackMessage(errorToHandler(err.error)));
121+
})
122+
.finally(() => setLoadingAPIs(false));
118123
};
119124

120125
const loadVersion = () => {
121-
if (displayVersion) {
122-
api
123-
.invoke("GET", `/api/v1/kms/version`)
124-
.then((result: any) => {
125-
if (result) {
126-
setVersion(result);
127-
}
128-
setLoadingVersion(false);
129-
})
130-
.catch((err: ErrorResponseHandler) => {
131-
dispatch(setErrorSnackMessage(err));
132-
setLoadingVersion(false);
133-
});
134-
} else {
135-
setLoadingVersion(false);
136-
}
137-
};
138-
139-
const loadStatus = () => {
140-
if (displayStatus) {
141-
api
142-
.invoke("GET", `/api/v1/kms/status`)
143-
.then((result: any) => {
144-
if (result) {
145-
setStatus(result);
146-
}
147-
setLoadingStatus(false);
148-
})
149-
.catch((err: ErrorResponseHandler) => {
150-
dispatch(setErrorSnackMessage(err));
151-
setLoadingStatus(false);
152-
});
153-
} else {
154-
setLoadingStatus(false);
155-
}
126+
api.kms
127+
.kmsVersion()
128+
.then((result: any) => {
129+
if (result.data) {
130+
setVersion(result.data);
131+
}
132+
})
133+
.catch((err) => {
134+
dispatch(setErrorSnackMessage(errorToHandler(err.error)));
135+
})
136+
.finally(() => setLoadingVersion(false));
156137
};
157138

158-
if (loadingStatus) {
139+
if (displayStatus && loadingStatus) {
159140
loadStatus();
160141
}
161-
if (loadingMetrics) {
142+
if (displayMetrics && loadingMetrics) {
162143
loadMetrics();
163144
}
164-
if (loadingAPIs) {
145+
if (displayAPIs && loadingAPIs) {
165146
loadAPIs();
166147
}
167-
if (loadingVersion) {
148+
if (displayVersion && loadingVersion) {
168149
loadVersion();
169150
}
170151
}, [
@@ -395,7 +376,11 @@ const Status = () => {
395376
),
396377
},
397378
{
398-
tabConfig: { label: "APIs", id: "simple-tab-1" },
379+
tabConfig: {
380+
label: "APIs",
381+
id: "simple-tab-1",
382+
disabled: !displayAPIs,
383+
},
399384
content: (
400385
<Box
401386
withBorders
@@ -410,7 +395,11 @@ const Status = () => {
410395
),
411396
},
412397
{
413-
tabConfig: { label: "Metrics", id: "simple-tab-2" },
398+
tabConfig: {
399+
label: "Metrics",
400+
id: "simple-tab-2",
401+
disabled: !displayMetrics,
402+
},
414403
content: (
415404
<Box
416405
withBorders

0 commit comments

Comments
 (0)