open-vault/ui/mirage/handlers/hcp-link.js
Jordan Reimer efe5193a59
HCP Link Status Parsing and Modal Update (#17279)
* updates hcp link status parsing for new format and updates to modal view

* fixes missing wormhole in tests

* fixes transit backend tests

* reverts adding wormhole to LinkStatus for testing and instead adds it to impacted tests
2022-09-23 08:18:20 -06:00

39 lines
1.4 KiB
JavaScript

export const statuses = [
'connected',
'disconnected since 2022-09-21T11:25:02.196835-07:00; error: unable to establish a connection with HCP',
'connecting since 2022-09-21T11:25:02.196835-07:00; error: unable to establish a connection with HCP',
'connecting since 2022-09-21T11:25:02.196835-07:00; error: principal does not have the permission to register as a provider',
'connecting since 2022-09-21T11:25:02.196835-07:00; error: could not obtain a token with the supplied credentials',
];
let index = null;
export default function (server) {
const handleResponse = (req, props) => {
const xhr = req.passthrough();
xhr.onreadystatechange = () => {
if (xhr.readyState === 4 && xhr.status < 300) {
// XMLHttpRequest response prop only has a getter -- redefine as writable and set value
Object.defineProperty(xhr, 'response', {
writable: true,
value: JSON.stringify({
...JSON.parse(xhr.responseText),
...props,
}),
});
}
};
};
server.get('sys/seal-status', (schema, req) => {
// return next status from statuses array
if (index === null || index === statuses.length - 1) {
index = 0;
} else {
index++;
}
return handleResponse(req, { hcp_link_status: statuses[index] });
});
// enterprise only feature initially
server.get('sys/health', (schema, req) => handleResponse(req, { version: '1.12.0-dev1+ent' }));
}