Skip to content
Snippets Groups Projects
Commit 90f4b176 authored by Mehrsary's avatar Mehrsary
Browse files

Check the health status of Vault

parent 2cec9eff
Branches 8-vault-health-status
No related tags found
No related merge requests found
......@@ -953,6 +953,9 @@ router.get('/container/commit', utility.asyncHandler(async (req, res, next) => {
try {
// check vault health status
let vaultHealthStatus = await vault.healthStatus();
// This includes a list of files that have been modified by previous stations - They are decrypted and must be encrypted again before the train leaves the station
let prevChanges = [];
const prevChangesFileName = getPrevChangesFileName();
......@@ -1216,6 +1219,9 @@ router.get('/image/decrypt', utility.asyncHandler(async (req, res, next) => {
try {
console.log("try1");
// check vault health status
let vaultHealthStatus = await vault.healthStatus();
// create a temp container
let createTempContainerOptions = {
uri: `https://${process.env.DOCKER_HOST}:${process.env.DOCKER_PORT}/containers/create`,
......
......@@ -172,6 +172,41 @@ module.exports = {
console.log(error);
return Promise.reject(error);
}
},
healthStatus: async() => {
try {
let vaultHealthStatus = await vault.health();
console.log(vaultHealthStatus);
if (vaultHealthStatus.isError) {
return Promise.reject("Error: Vault");
}
if (!vaultHealthStatus.initialized) {
return Promise.reject("Error: Vault is not initialized");
}
if (vaultHealthStatus.sealed) {
return Promise.reject("Error: Vault is sealed");
}
try {
let lookupResult = await vault.tokenLookupSelf();
console.log(lookupResult);
if (lookupResult.data) {
return Promise.resolve();
}
} catch (error) {
return Promise.reject("Error: Vault authentication failed");
}
} catch (error) {
console.log(error);
return Promise.reject("Error: Vault connection refused");
}
}
};
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment