mirror of
https://github.com/hashicorp/vault-action.git
synced 2025-11-07 07:06:56 +00:00
fix: fix got not being use correctly and path prefix
This commit is contained in:
parent
0e719ef42a
commit
ed8303ca53
3 changed files with 12 additions and 13 deletions
|
|
@ -72,7 +72,7 @@ async function exportSecrets() {
|
||||||
requestOptions.headers["X-Vault-Namespace"] = vaultNamespace;
|
requestOptions.headers["X-Vault-Namespace"] = vaultNamespace;
|
||||||
}
|
}
|
||||||
|
|
||||||
let requestPath = `${vaultUrl}/v1`;
|
let requestPath = `v1`;
|
||||||
const kvRequest = !secretPath.startsWith('/')
|
const kvRequest = !secretPath.startsWith('/')
|
||||||
if (!kvRequest) {
|
if (!kvRequest) {
|
||||||
requestPath += secretPath;
|
requestPath += secretPath;
|
||||||
|
|
@ -87,7 +87,7 @@ async function exportSecrets() {
|
||||||
body = responseCache.get(requestPath);
|
body = responseCache.get(requestPath);
|
||||||
core.debug('ℹ using cached response');
|
core.debug('ℹ using cached response');
|
||||||
} else {
|
} else {
|
||||||
const result = await got(requestPath, requestOptions);
|
const result = await client.get(requestPath, requestOptions);
|
||||||
body = result.body;
|
body = result.body;
|
||||||
responseCache.set(requestPath, body);
|
responseCache.set(requestPath, body);
|
||||||
}
|
}
|
||||||
|
|
@ -192,7 +192,7 @@ async function retrieveToken(method, client) {
|
||||||
responseType: 'json'
|
responseType: 'json'
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = await client.post(`/v1/auth/approle/login`, options);
|
const result = await client.post(`v1/auth/approle/login`, options);
|
||||||
if (result && result.body && result.body.auth && result.body.auth.client_token) {
|
if (result && result.body && result.body.auth && result.body.auth.client_token) {
|
||||||
core.debug('✔ Vault Token has retrieved from approle');
|
core.debug('✔ Vault Token has retrieved from approle');
|
||||||
return result.body.auth.client_token;
|
return result.body.auth.client_token;
|
||||||
|
|
@ -210,7 +210,7 @@ async function retrieveToken(method, client) {
|
||||||
responseType: 'json'
|
responseType: 'json'
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = await client.post(`/v1/auth/github/login`, options);
|
const result = await client.post(`v1/auth/github/login`, options);
|
||||||
if (result && result.body && result.body.auth && result.body.auth.client_token) {
|
if (result && result.body && result.body.auth && result.body.auth.client_token) {
|
||||||
core.debug('✔ Vault Token has retrieved from approle');
|
core.debug('✔ Vault Token has retrieved from approle');
|
||||||
return result.body.auth.client_token;
|
return result.body.auth.client_token;
|
||||||
|
|
|
||||||
13
dist/index.js
vendored
13
dist/index.js
vendored
|
|
@ -4906,8 +4906,7 @@ async function exportSecrets() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultOptions = {
|
const defaultOptions = {
|
||||||
baseUrl: vaultUrl,
|
prefixUrl: vaultUrl,
|
||||||
throwHttpErrors: true,
|
|
||||||
headers: {}
|
headers: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -4920,7 +4919,7 @@ async function exportSecrets() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = got.extend(defaultOptions);
|
const client = got.extend(defaultOptions);
|
||||||
const vaultToken = await retrieveToken(vaultMethod, client);
|
const vaultToken = await retrieveToken(vaultMethod, /** @type {any} */ (client));
|
||||||
|
|
||||||
if (!enginePath) {
|
if (!enginePath) {
|
||||||
enginePath = 'secret';
|
enginePath = 'secret';
|
||||||
|
|
@ -4952,7 +4951,7 @@ async function exportSecrets() {
|
||||||
requestOptions.headers["X-Vault-Namespace"] = vaultNamespace;
|
requestOptions.headers["X-Vault-Namespace"] = vaultNamespace;
|
||||||
}
|
}
|
||||||
|
|
||||||
let requestPath = `${vaultUrl}/v1`;
|
let requestPath = `v1`;
|
||||||
const kvRequest = !secretPath.startsWith('/')
|
const kvRequest = !secretPath.startsWith('/')
|
||||||
if (!kvRequest) {
|
if (!kvRequest) {
|
||||||
requestPath += secretPath;
|
requestPath += secretPath;
|
||||||
|
|
@ -4967,7 +4966,7 @@ async function exportSecrets() {
|
||||||
body = responseCache.get(requestPath);
|
body = responseCache.get(requestPath);
|
||||||
core.debug('ℹ using cached response');
|
core.debug('ℹ using cached response');
|
||||||
} else {
|
} else {
|
||||||
const result = await got(requestPath, requestOptions);
|
const result = await client.get(requestPath, requestOptions);
|
||||||
body = result.body;
|
body = result.body;
|
||||||
responseCache.set(requestPath, body);
|
responseCache.set(requestPath, body);
|
||||||
}
|
}
|
||||||
|
|
@ -5072,7 +5071,7 @@ async function retrieveToken(method, client) {
|
||||||
responseType: 'json'
|
responseType: 'json'
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = await client.post(`/v1/auth/approle/login`, options);
|
const result = await client.post(`v1/auth/approle/login`, options);
|
||||||
if (result && result.body && result.body.auth && result.body.auth.client_token) {
|
if (result && result.body && result.body.auth && result.body.auth.client_token) {
|
||||||
core.debug('✔ Vault Token has retrieved from approle');
|
core.debug('✔ Vault Token has retrieved from approle');
|
||||||
return result.body.auth.client_token;
|
return result.body.auth.client_token;
|
||||||
|
|
@ -5090,7 +5089,7 @@ async function retrieveToken(method, client) {
|
||||||
responseType: 'json'
|
responseType: 'json'
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = await client.post(`/v1/auth/github/login`, options);
|
const result = await client.post(`v1/auth/github/login`, options);
|
||||||
if (result && result.body && result.body.auth && result.body.auth.client_token) {
|
if (result && result.body && result.body.auth && result.body.auth.client_token) {
|
||||||
core.debug('✔ Vault Token has retrieved from approle');
|
core.debug('✔ Vault Token has retrieved from approle');
|
||||||
return result.body.auth.client_token;
|
return result.body.auth.client_token;
|
||||||
|
|
|
||||||
|
|
@ -212,7 +212,7 @@ describe('authenticate with approle', () => {
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('method')
|
.calledWith('method', expect.anything())
|
||||||
.mockReturnValueOnce('approle');
|
.mockReturnValueOnce('approle');
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('roleId')
|
.calledWith('roleId')
|
||||||
|
|
@ -228,7 +228,7 @@ describe('authenticate with approle', () => {
|
||||||
.mockReturnValueOnce('ns2');
|
.mockReturnValueOnce('ns2');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('authenticate with approle', async()=> {
|
it.only('authenticate with approle', async() => {
|
||||||
mockInput('test secret');
|
mockInput('test secret');
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue