Skip to content

Commit e001070

Browse files
committed
MK8S-197 - Pass access token to getAlerts in Shell-UI
1 parent 189d4e0 commit e001070

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

shell-ui/src/alerts/AlertProvider.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { useQuery } from 'react-query';
33
import { Loader } from '@scality/core-ui/dist/components/loader/Loader.component';
4+
import { useAuth } from '../auth/AuthProvider';
45
import { getAlerts } from './services/alertManager';
56
import { AlertContext } from './alertContext';
67
/**
@@ -18,13 +19,18 @@ export default function AlertProvider({
1819
alertManagerUrl: string;
1920
children: React.ReactNode;
2021
}) {
21-
const query = useQuery('activeAlerts', () => getAlerts(alertManagerUrl), {
22-
// refetch the alerts every 10 seconds
23-
refetchInterval: 30000,
24-
// TODO manage this refresh interval globally
25-
// avoid stucking at the hard loading state before alertmanager is ready
26-
initialData: [],
27-
});
22+
const { userData } = useAuth();
23+
const query = useQuery(
24+
'activeAlerts',
25+
() => getAlerts(alertManagerUrl, userData?.token),
26+
{
27+
// refetch the alerts every 30 seconds
28+
refetchInterval: 30000,
29+
// TODO manage this refresh interval globally
30+
// avoid stucking at the hard loading state before alertmanager is ready
31+
initialData: [],
32+
},
33+
);
2834
return (
2935
<AlertContext.Provider value={{ ...query }}>
3036
{query.status === 'loading' && (

shell-ui/src/alerts/services/alertManager.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ export type AlertLabels = {
2929
selectors?: string[];
3030
[labelName: string]: string;
3131
};
32-
export function getAlerts(alertManagerUrl: string) {
33-
return fetch(alertManagerUrl + '/api/v2/alerts')
32+
export function getAlerts(alertManagerUrl: string, token?: string) {
33+
return fetch(alertManagerUrl + '/api/v2/alerts', {
34+
headers: token ? { Authorization: `Bearer ${token}` } : {},
35+
})
3436
.then((r) => {
3537
if (r.ok) {
3638
return r.json();

0 commit comments

Comments
 (0)