Now using endpoints returned from the gateway sec

This commit is contained in:
bourquecharles
2021-07-02 17:34:13 -04:00
parent 908a034433
commit c017fe0774
31 changed files with 110 additions and 80 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "ucentral-client",
"version": "0.9.9",
"version": "0.9.10",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "ucentral-client",
"version": "0.9.9",
"version": "0.9.10",
"dependencies": {
"@coreui/coreui": "^3.4.0",
"@coreui/icons": "^2.0.1",

View File

@@ -1,6 +1,6 @@
{
"name": "ucentral-client",
"version": "0.9.9",
"version": "0.9.10",
"private": true,
"dependencies": {
"@coreui/coreui": "^3.4.0",

View File

@@ -1,4 +1,4 @@
{
"DEFAULT_GATEWAY_URL": "https://ucentral.dpaas.arilia.com:16001",
"DEFAULT_UCENTRALSEC_URL": "https://ucentral.dpaas.arilia.com:16001",
"ALLOW_GATEWAY_CHANGE": false
}

View File

@@ -3,6 +3,7 @@ import { HashRouter, Switch } from 'react-router-dom';
import 'scss/style.scss';
import Router from 'router';
import { AuthProvider } from 'contexts/AuthProvider';
import { checkIfJson } from 'utils/helper';
const loading = (
<div className="pt-3 text-center">
@@ -12,9 +13,10 @@ const loading = (
const App = () => {
const storageToken = sessionStorage.getItem('access_token');
const apiEndpoints = checkIfJson(sessionStorage.getItem('gateway_endpoints')) ? JSON.parse(sessionStorage.getItem('gateway_endpoints')) : {};
return (
<AuthProvider token={storageToken ?? ''}>
<AuthProvider token={storageToken ?? ''} apiEndpoints={apiEndpoints}>
<HashRouter>
<React.Suspense fallback={loading}>
<Switch>

View File

@@ -29,7 +29,7 @@ import styles from './index.module.scss';
const BlinkModal = ({ show, toggleModal }) => {
const { t } = useTranslation();
const { currentToken } = useAuth();
const { currentToken, endpoints } = useAuth();
const { deviceSerialNumber } = useDevice();
const [isNow, setIsNow] = useState(false);
const [waiting, setWaiting] = useState(false);
@@ -73,7 +73,7 @@ const BlinkModal = ({ show, toggleModal }) => {
};
axiosInstance
.post(`/device/${encodeURIComponent(deviceSerialNumber)}/leds`, parameters, { headers })
.post(`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/leds`, parameters, { headers })
.then(() => {
setResult('success');
})

View File

@@ -27,7 +27,7 @@ import styles from './index.module.scss';
const DeviceCommands = () => {
const { t } = useTranslation();
const { currentToken } = useAuth();
const { currentToken, endpoints } = useAuth();
const { deviceSerialNumber } = useDevice();
// Wifiscan result related
const [chosenWifiScan, setChosenWifiScan] = useState(null);
@@ -110,7 +110,7 @@ const DeviceCommands = () => {
axiosInstance
.get(
`/commands?serialNumber=${encodeURIComponent(deviceSerialNumber)}${extraParams}`,
`${endpoints.ucentralgw}/api/v1/commands?serialNumber=${encodeURIComponent(deviceSerialNumber)}${extraParams}`,
options,
)
.then((response) => {
@@ -133,7 +133,7 @@ const DeviceCommands = () => {
};
axiosInstance
.get(`/file/${uuid}?serialNumber=${deviceSerialNumber}`, options)
.get(`${endpoints.ucentralgw}/api/v1/file/${uuid}?serialNumber=${deviceSerialNumber}`, options)
.then((response) => {
const blob = new Blob([response.data], { type: 'application/octet-stream' });
const link = document.createElement('a');
@@ -154,7 +154,7 @@ const DeviceCommands = () => {
},
};
return axiosInstance
.delete(`/command/${uuidDelete}`, options)
.delete(`${endpoints.ucentralgw}/api/v1/command/${uuidDelete}`, options)
.then(() => {
deleteCommandFromList(uuidDelete);
setUuidDelete('');

View File

@@ -27,7 +27,7 @@ import styles from './index.module.scss';
const ConfigureModal = ({ show, toggleModal }) => {
const { t } = useTranslation();
const { currentToken } = useAuth();
const { currentToken, endpoints } = useAuth();
const { deviceSerialNumber } = useDevice();
const [hadSuccess, setHadSuccess] = useState(false);
const [hadFailure, setHadFailure] = useState(false);
@@ -84,7 +84,7 @@ const ConfigureModal = ({ show, toggleModal }) => {
};
axiosInstance
.post(`/device/${encodeURIComponent(deviceSerialNumber)}/configure`, parameters, { headers })
.post(`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/configure`, parameters, { headers })
.then(() => {
setHadSuccess(true);
})

View File

@@ -13,7 +13,7 @@ import styles from './index.module.scss';
const DeleteLogModal = ({ show, toggle, object }) => {
const { t } = useTranslation();
const { currentToken } = useAuth();
const { currentToken, endpoints } = useAuth();
const { deviceSerialNumber } = useDevice();
const [loading, setLoading] = useState(false);
const [maxDate, setMaxDate] = useState(new Date().toString());
@@ -37,7 +37,7 @@ const DeleteLogModal = ({ show, toggle, object }) => {
},
};
return axiosInstance
.delete(`/device/${deviceSerialNumber}/${object}`, options)
.delete(`${endpoints.ucentralgw}/api/v1/device/${deviceSerialNumber}/${object}`, options)
.then(() => {})
.catch(() => {})
.finally(() => {

View File

@@ -17,7 +17,7 @@ import styles from './index.module.scss';
const DeviceActions = () => {
const { t } = useTranslation();
const { currentToken } = useAuth();
const { currentToken, endpoints } = useAuth();
const { deviceSerialNumber } = useDevice();
const [showRebootModal, setShowRebootModal] = useState(false);
const [showBlinkModal, setShowBlinkModal] = useState(false);
@@ -66,7 +66,7 @@ const DeviceActions = () => {
};
axiosInstance
.get(`/device/${encodeURIComponent(deviceSerialNumber)}/rtty`, options)
.get(`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/rtty`, options)
.then((response) => {
const url = `https://${response.data.server}:${response.data.viewport}/connect/${response.data.connectionId}`;
const newWindow = window.open(url, '_blank', 'noopener,noreferrer');

View File

@@ -25,7 +25,7 @@ import styles from './index.module.scss';
const DeviceConfiguration = () => {
const { t } = useTranslation();
const { currentToken } = useAuth();
const { currentToken, endpoints } = useAuth();
const { deviceSerialNumber } = useDevice();
const [collapse, setCollapse] = useState(false);
const [showModal, setShowModal] = useState(false);
@@ -49,7 +49,7 @@ const DeviceConfiguration = () => {
};
axiosInstance
.get(`/device/${encodeURIComponent(deviceSerialNumber)}`, options)
.get(`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}`, options)
.then((response) => {
setDevice(response.data);
})

View File

@@ -26,7 +26,7 @@ import styles from './index.module.scss';
const DeviceHealth = () => {
const { t } = useTranslation();
const { currentToken } = useAuth();
const { currentToken, endpoints } = useAuth();
const { deviceSerialNumber } = useDevice();
const [collapse, setCollapse] = useState(false);
const [details, setDetails] = useState([]);
@@ -87,7 +87,7 @@ const DeviceHealth = () => {
}
axiosInstance
.get(`/device/${encodeURIComponent(deviceSerialNumber)}/healthchecks${extraParams}`, options)
.get(`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/healthchecks${extraParams}`, options)
.then((response) => {
setHealthChecks(response.data.values);
})

View File

@@ -29,7 +29,7 @@ import styles from './index.module.scss';
const DeviceList = () => {
const { t } = useTranslation();
const { currentToken } = useAuth();
const { currentToken, endpoints } = useAuth();
const [loadedSerials, setLoadedSerials] = useState(false);
const [serialNumbers, setSerialNumbers] = useState([]);
const [page, setPage] = useState(0);
@@ -47,7 +47,7 @@ const DeviceList = () => {
};
axiosInstance
.get('/devices?serialOnly=true', {
.get(`${endpoints.ucentralgw}/api/v1/devices?serialOnly=true`, {
headers,
})
.then((response) => {
@@ -75,7 +75,7 @@ const DeviceList = () => {
.join(',');
axiosInstance
.get(`/devices?deviceWithStatus=true&select=${serialsToGet}`, {
.get(`${endpoints.ucentralgw}/api/v1/devices?deviceWithStatus=true&select=${serialsToGet}`, {
headers,
})
.then((response) => {
@@ -96,7 +96,7 @@ const DeviceList = () => {
};
axiosInstance
.get(`/devices?deviceWithStatus=true&select=${encodeURIComponent(serialNumber)}`, {
.get(`${endpoints.ucentralgw}/api/v1/devices?deviceWithStatus=true&select=${encodeURIComponent(serialNumber)}`, {
headers,
})
.then((response) => {

View File

@@ -25,7 +25,7 @@ import styles from './index.module.scss';
const DeviceLogs = () => {
const { t } = useTranslation();
const { currentToken } = useAuth();
const { currentToken, endpoints } = useAuth();
const { deviceSerialNumber } = useDevice();
const [collapse, setCollapse] = useState(false);
const [details, setDetails] = useState([]);
@@ -84,7 +84,7 @@ const DeviceLogs = () => {
}
axiosInstance
.get(`/device/${encodeURIComponent(deviceSerialNumber)}/logs${extraParams}`, options)
.get(`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/logs${extraParams}`, options)
.then((response) => {
setLogs(response.data.values);
})

View File

@@ -25,7 +25,7 @@ import styles from './index.module.scss';
const DeviceStatusCard = () => {
const { t } = useTranslation();
const { currentToken } = useAuth();
const { currentToken, endpoints } = useAuth();
const { deviceSerialNumber } = useDevice();
const [lastStats, setLastStats] = useState(null);
const [status, setStatus] = useState(null);
@@ -47,11 +47,11 @@ const DeviceStatusCard = () => {
};
const lastStatsRequest = axiosInstance.get(
`/device/${encodeURIComponent(deviceSerialNumber)}/statistics?lastOnly=true`,
`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/statistics?lastOnly=true`,
options,
);
const statusRequest = axiosInstance.get(
`/device/${encodeURIComponent(deviceSerialNumber)}/status`,
`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/status`,
options,
);

View File

@@ -23,7 +23,7 @@ import styles from './index.module.scss';
const ConfigureModal = ({ show, toggleModal }) => {
const { t } = useTranslation();
const { currentToken } = useAuth();
const { currentToken, endpoints } = useAuth();
const { deviceSerialNumber } = useDevice();
const [hadSuccess, setHadSuccess] = useState(false);
const [hadFailure, setHadFailure] = useState(false);
@@ -65,7 +65,7 @@ const ConfigureModal = ({ show, toggleModal }) => {
};
axiosInstance
.post(`/device/${encodeURIComponent(deviceSerialNumber)}/factory`, parameters, { headers })
.post(`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/factory`, parameters, { headers })
.then(() => {
setHadSuccess(true);
})

View File

@@ -8,7 +8,7 @@ import axiosInstance from 'utils/axiosInstance';
const UpgradeWaitingBody = ({ serialNumber }) => {
const { t } = useTranslation();
const { currentToken } = useAuth();
const { currentToken, endpoints } = useAuth();
const [currentStep, setCurrentStep] = useState(0);
const [secondsElapsed, setSecondsElapsed] = useState(0);
const [labelsToShow, setLabelsToShow] = useState(['upgrade.command_submitted']);
@@ -22,7 +22,7 @@ const UpgradeWaitingBody = ({ serialNumber }) => {
};
axiosInstance
.get(`/device/${encodeURIComponent(serialNumber)}/status`, options)
.get(`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(serialNumber)}/status`, options)
.then((response) => response.data.connected)
.catch(() => {});
};
@@ -36,7 +36,7 @@ const UpgradeWaitingBody = ({ serialNumber }) => {
};
axiosInstance
.get(`/device/${encodeURIComponent(serialNumber)}`, options)
.get(`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(serialNumber)}`, options)
.then((response) => response.data.firmware)
.catch(() => {});
};

View File

@@ -28,7 +28,7 @@ import UpgradeWaitingBody from './UpgradeWaitingBody';
const FirmwareUpgradeModal = ({ show, toggleModal }) => {
const { t } = useTranslation();
const { currentToken } = useAuth();
const { currentToken, endpoints } = useAuth();
const { deviceSerialNumber } = useDevice();
const [isNow, setIsNow] = useState(true);
const [waitForUpgrade, setWaitForUpgrade] = useState(false);
@@ -84,7 +84,7 @@ const FirmwareUpgradeModal = ({ show, toggleModal }) => {
useEffect(() => {
if (deviceSerialNumber !== null && show) {
const asyncGet = async () => {
const isConnected = await getDeviceConnection(deviceSerialNumber, currentToken);
const isConnected = await getDeviceConnection(deviceSerialNumber, currentToken, endpoints.ucentralgw);
setDisableWaiting(!isConnected);
setDeviceConnected(isConnected);
};
@@ -108,7 +108,7 @@ const FirmwareUpgradeModal = ({ show, toggleModal }) => {
uri: firmware,
};
axiosInstance
.post(`/device/${encodeURIComponent(deviceSerialNumber)}/upgrade`, parameters, { headers })
.post(`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/upgrade`, parameters, { headers })
.then(() => {
if (waitForUpgrade) {
setShowWaitingConsole(true);

View File

@@ -16,7 +16,7 @@ import styles from './index.module.scss';
const LatestStatisticsModal = ({ show, toggle }) => {
const { t } = useTranslation();
const { currentToken } = useAuth();
const { currentToken, endpoints } = useAuth();
const { deviceSerialNumber } = useDevice();
const [latestStats, setLatestStats] = useState('');
@@ -29,7 +29,7 @@ const LatestStatisticsModal = ({ show, toggle }) => {
};
axiosInstance
.get(`/device/${deviceSerialNumber}/statistics?lastOnly=true`, options)
.get(`${endpoints.ucentralgw}/api/v1/device/${deviceSerialNumber}/statistics?lastOnly=true`, options)
.then((response) => {
setLatestStats(response.data);
})

View File

@@ -10,7 +10,7 @@ import DeviceStatisticsChart from './DeviceStatisticsChart';
const StatisticsChartList = () => {
const { t } = useTranslation();
const { currentToken } = useAuth();
const { currentToken, endpoints } = useAuth();
const { deviceSerialNumber } = useDevice();
const [statOptions, setStatOptions] = useState({
interfaceList: [],
@@ -128,7 +128,7 @@ const StatisticsChartList = () => {
};
axiosInstance
.get(`/device/${deviceSerialNumber}/statistics?newest=true&limit=50`, options)
.get(`${endpoints.ucentralgw}/api/v1/device/${deviceSerialNumber}/statistics?newest=true&limit=50`, options)
.then((response) => {
transformIntoDataset(response.data.data);
})

View File

@@ -25,7 +25,7 @@ import styles from './index.module.scss';
const ActionModal = ({ show, toggleModal }) => {
const { t } = useTranslation();
const { currentToken } = useAuth();
const { currentToken, endpoints } = useAuth();
const { deviceSerialNumber } = useDevice();
const [waiting, setWaiting] = useState(false);
const [result, setResult] = useState(null);
@@ -66,7 +66,7 @@ const ActionModal = ({ show, toggleModal }) => {
};
axiosInstance
.post(`/device/${encodeURIComponent(deviceSerialNumber)}/reboot`, parameters, { headers })
.post(`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/reboot`, parameters, { headers })
.then(() => {
setResult('success');
})

View File

@@ -9,7 +9,7 @@ import styles from './index.module.scss';
const WaitingForTraceBody = ({ serialNumber, commandUuid, toggle }) => {
const { t } = useTranslation();
const { currentToken } = useAuth();
const { currentToken, endpoints } = useAuth();
const [secondsElapsed, setSecondsElapsed] = useState(0);
const [waitingForFile, setWaitingForFile] = useState(true);
@@ -22,7 +22,7 @@ const WaitingForTraceBody = ({ serialNumber, commandUuid, toggle }) => {
};
axiosInstance
.get(`/command/${encodeURIComponent(commandUuid)}`, options)
.get(`${endpoints.ucentralgw}/api/v1/command/${encodeURIComponent(commandUuid)}`, options)
.then((response) => {
if (response.data.waitingForFile === 0) {
setWaitingForFile(false);
@@ -41,7 +41,7 @@ const WaitingForTraceBody = ({ serialNumber, commandUuid, toggle }) => {
};
axiosInstance
.get(`/file/${commandUuid}?serialNumber=${serialNumber}`, options)
.get(`${endpoints.ucentralgw}/api/v1/file/${commandUuid}?serialNumber=${serialNumber}`, options)
.then((response) => {
const blob = new Blob([response.data], { type: 'application/octet-stream' });
const link = document.createElement('a');

View File

@@ -30,7 +30,7 @@ import styles from './index.module.scss';
const TraceModal = ({ show, toggleModal }) => {
const { t } = useTranslation();
const { currentToken } = useAuth();
const { currentToken, endpoints } = useAuth();
const { deviceSerialNumber } = useDevice();
const [hadSuccess, setHadSuccess] = useState(false);
const [hadFailure, setHadFailure] = useState(false);
@@ -83,7 +83,7 @@ const TraceModal = ({ show, toggleModal }) => {
};
axiosInstance
.post(`/device/${encodeURIComponent(deviceSerialNumber)}/trace`, parameters, { headers })
.post(`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/trace`, parameters, { headers })
.then((response) => {
setHadSuccess(true);
if (waitForTrace) {
@@ -105,7 +105,7 @@ const TraceModal = ({ show, toggleModal }) => {
useEffect(() => {
if (deviceSerialNumber !== null && show) {
const asyncGet = async () => {
const isConnected = await getDeviceConnection(deviceSerialNumber, currentToken);
const isConnected = await getDeviceConnection(deviceSerialNumber, currentToken, endpoints.ucentralgw);
setIsDeviceConnected(isConnected);
};
asyncGet();

View File

@@ -25,7 +25,7 @@ import styles from './index.module.scss';
const WifiScanModal = ({ show, toggleModal }) => {
const { t } = useTranslation();
const { currentToken } = useAuth();
const { currentToken, endpoints } = useAuth();
const { deviceSerialNumber } = useDevice();
const [hadSuccess, setHadSuccess] = useState(false);
const [hadFailure, setHadFailure] = useState(false);
@@ -100,7 +100,7 @@ const WifiScanModal = ({ show, toggleModal }) => {
};
axiosInstance
.post(`/device/${encodeURIComponent(deviceSerialNumber)}/wifiscan`, parameters, { headers })
.post(`${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}/wifiscan`, parameters, { headers })
.then((response) => {
const scanList = response?.data?.results?.status?.scan;

View File

@@ -3,11 +3,12 @@ import PropTypes from 'prop-types';
const AuthContext = React.createContext();
export const AuthProvider = ({ token, children }) => {
export const AuthProvider = ({ token, apiEndpoints, children }) => {
const [currentToken, setCurrentToken] = useState(token);
const [endpoints, setEndpoints] = useState(apiEndpoints);
return (
<AuthContext.Provider value={{ currentToken, setCurrentToken }}>
<AuthContext.Provider value={{ currentToken, setCurrentToken, endpoints, setEndpoints }}>
{children}
</AuthContext.Provider>
);
@@ -16,6 +17,11 @@ export const AuthProvider = ({ token, children }) => {
AuthProvider.propTypes = {
token: PropTypes.string.isRequired,
children: PropTypes.node.isRequired,
apiEndpoints: PropTypes.instanceOf(Object)
};
AuthProvider.defaultProps = {
apiEndpoints: {}
}
export const useAuth = () => React.useContext(AuthContext);

View File

@@ -6,7 +6,7 @@ const TheFooter = () => (
<Translation>
{(t) => (
<CFooter fixed={false}>
<div>{t('footer.version')} 0.9.9</div>
<div>{t('footer.version')} 0.9.10</div>
<div className="mfs-auto">
<span className="mr-1">{t('footer.powered_by')}</span>
<a href="https://coreui.io/react" target="_blank" rel="noopener noreferrer">

View File

@@ -16,9 +16,11 @@ import { cilAccountLogout } from '@coreui/icons';
import { logout } from 'utils/authHelper';
import routes from 'routes';
import LanguageSwitcher from 'components/LanguageSwitcher';
import { useAuth } from 'contexts/AuthProvider';
const TheHeader = ({ showSidebar, setShowSidebar }) => {
const { t, i18n } = useTranslation();
const { currentToken, endpoints} = useAuth();
const [translatedRoutes, setTranslatedRoutes] = useState(routes);
const toggleSidebar = () => {
@@ -52,7 +54,7 @@ const TheHeader = ({ showSidebar, setShowSidebar }) => {
<CHeaderNav className="px-3">
<CPopover content={t('common.logout')}>
<CLink className="c-subheader-nav-link">
<CIcon name="cilAccountLogout" content={cilAccountLogout} size="2xl" onClick={logout} />
<CIcon name="cilAccountLogout" content={cilAccountLogout} size="2xl" onClick={() => logout(currentToken, endpoints.ucentralsec)} />
</CLink>
</CPopover>
</CHeaderNav>

View File

@@ -17,6 +17,7 @@ import {
CAlert,
CInvalidFeedback,
} from '@coreui/react';
import CIcon from '@coreui/icons-react';
import { useAuth } from 'contexts/AuthProvider';
import { cilUser, cilLockLocked, cilLink } from '@coreui/icons';
@@ -27,7 +28,7 @@ import styles from './index.module.scss';
const Login = () => {
const { t } = useTranslation();
const { setCurrentToken } = useAuth();
const { setCurrentToken, setEndpoints } = useAuth();
const [userId, setUsername] = useState('');
const [password, setPassword] = useState('');
const [gatewayUrl, setGatewayUrl] = useState('');
@@ -36,7 +37,7 @@ const Login = () => {
const [emptyPassword, setEmptyPassword] = useState(false);
const [emptyGateway, setEmptyGateway] = useState(false);
const [defaultConfig, setDefaultConfig] = useState({
DEFAULT_GATEWAY_URL: '',
DEFAULT_UCENTRALSEC_URL: '',
ALLOW_GATEWAY_CHANGE: true,
});
const placeholderUrl = 'Gateway URL (ex: https://your-url:port)';
@@ -78,16 +79,31 @@ const Login = () => {
};
const SignIn = (credentials) => {
const gatewayUrlToUse = defaultConfig.ALLOW_GATEWAY_CHANGE
let token = '';
const uCentralSecUrl = defaultConfig.ALLOW_GATEWAY_CHANGE
? gatewayUrl
: defaultConfig.DEFAULT_GATEWAY_URL;
: defaultConfig.DEFAULT_UCENTRALSEC_URL;
axiosInstance
.post(`${gatewayUrlToUse}/api/v1/oauth2`, credentials)
.post(`${uCentralSecUrl}/api/v1/oauth2`, credentials)
.then((response) => {
sessionStorage.setItem('gw_url', `${gatewayUrlToUse}/api/v1`);
sessionStorage.setItem('access_token', response.data.access_token);
setCurrentToken(response.data.access_token);
token = response.data.access_token;
return axiosInstance.get(`${uCentralSecUrl}/api/v1/systemEndpoints`, { headers: {
Accept: 'application/json',
Authorization: `Bearer ${response.data.access_token}`,
}});
})
.then ((response) => {
const endpoints = {
ucentralsec: uCentralSecUrl
};
for (const endpoint of response.data.endpoints){
endpoints[endpoint.type] = endpoint.uri;
}
sessionStorage.setItem('gateway_endpoints', JSON.stringify(endpoints));
setEndpoints(endpoints);
setCurrentToken(token);
})
.catch(() => {
setHadError(true);
@@ -113,7 +129,7 @@ const Login = () => {
getDefaultConfig();
}, []);
useEffect(() => {
setGatewayUrl(defaultConfig.DEFAULT_GATEWAY_URL);
setGatewayUrl(defaultConfig.DEFAULT_UCENTRALSEC_URL);
}, [defaultConfig]);
return (

View File

@@ -6,13 +6,13 @@ const TheLayout = React.lazy(() => import('layout'));
const Login = React.lazy(() => import('pages/LoginPage'));
const Routes = () => {
const { currentToken } = useAuth();
const { currentToken, endpoints } = useAuth();
return (
<Route
path="/"
name="Devices"
render={(props) => (currentToken !== '' ? <TheLayout {...props} /> : <Login {...props} />)}
render={(props) => (currentToken !== '' && Object.keys(endpoints).length !== 0 ? <TheLayout {...props} /> : <Login {...props} />)}
/>
);
};

View File

@@ -1,6 +1,19 @@
export const logout = () => {
sessionStorage.clear();
window.location.replace('/');
import axiosInstance from "./axiosInstance";
export const logout = (token, endpoint) => {
axiosInstance
.delete(`${endpoint}/api/v1/oauth2/${token}`, {
headers: {
Accept: 'application/json',
Authorization: `Bearer ${token}`,
},
})
.then(() => {})
.catch(() => {})
.finally(() => {
sessionStorage.clear();
window.location.replace('/');
})
};
export const getToken = () => {

View File

@@ -16,15 +16,6 @@ axiosInstance.defaults.timeout = 30000;
axiosInstance.defaults.headers.get.Accept = 'application/json';
axiosInstance.defaults.headers.post.Accept = 'application/json';
axiosInstance.interceptors.request.use((config) => {
const newConfig = config;
const url = sessionStorage.getItem('gw_url');
if (url !== undefined && url !== null && !newConfig.url.includes(url)) {
newConfig.url = url + newConfig.url;
}
return newConfig;
});
axiosInstance.interceptors.response.use(
// Success actions
undefined,

View File

@@ -1,6 +1,6 @@
import axiosInstance from 'utils/axiosInstance';
export default async (deviceId, token) => {
export default async (deviceId, token, endpoint) => {
const options = {
headers: {
Accept: 'application/json',
@@ -9,7 +9,7 @@ export default async (deviceId, token) => {
};
return axiosInstance
.get(`/device/${encodeURIComponent(deviceId)}/status`, options)
.get(`${endpoint}/api/v1/device/${encodeURIComponent(deviceId)}/status`, options)
.then((response) => response.data.connected)
.catch(() => false);
};