5
0
Fork 0
mirror of https://github.com/hashicorp/vault-action.git synced 2025-11-14 18:13:45 +00:00

Write a better error message when key not found

This commit is contained in:
Simon Johansson 2021-01-27 16:22:26 +01:00
parent 5e5c06a3c8
commit 7dc1ddf98c
No known key found for this signature in database
GPG key ID: 63F236A41D9A79AC
2 changed files with 19 additions and 3 deletions

View file

@ -123,6 +123,14 @@ describe('integration', () => {
.mockReturnValueOnce(secrets); .mockReturnValueOnce(secrets);
} }
it('prints a nice error message when secret not found', async () => {
mockInput(`secret/data/test secret ;
secret/data/test secret | NAMED_SECRET ;
secret/data/notFound kehe | NO_SIR ;`);
expect(exportSecrets()).rejects.toEqual(Error(`Unable to retrieve result for "secret/data/notFound". Double check your Key.`));
})
it('get simple secret', async () => { it('get simple secret', async () => {
mockInput('secret/data/test secret'); mockInput('secret/data/test secret');

View file

@ -34,9 +34,17 @@ async function getSecrets(secretRequests, client) {
body = responseCache.get(requestPath); body = responseCache.get(requestPath);
cachedResponse = true; cachedResponse = true;
} else { } else {
const result = await client.get(requestPath); try {
body = result.body; const result = await client.get(requestPath);
responseCache.set(requestPath, body); body = result.body;
responseCache.set(requestPath, body);
} catch (error) {
const {response} = error;
if (response.statusCode === 404) {
throw Error(`Unable to retrieve result for "${path}". Double check your Key.`)
}
throw error
}
} }
if (!selector.match(/.*[\.].*/)) { if (!selector.match(/.*[\.].*/)) {
selector = '"' + selector + '"' selector = '"' + selector + '"'