Repository URL to install this package:
|
Version:
1.0.3-rc.0 ▾
|
@doodle/vault
/
kubernetesLogin.js
|
|---|
const fetch = require('node-fetch');
/**
* Exchanges a Kubernetes service account token for a authenticated Vault token
*
* @see https://www.vaultproject.io/api/auth/kubernetes/index.html#login
*
* @param {Object} options
* @param {String} options.jwt A valid Kubernetes ServiceAccount secret token
* @param {String} options.role With which vault role to log in using the service account token
* @param {String} [options.endpoint=http://127.0.0.1:8200] Vault host
* @param {String} [options.apiVersion=v1] Vault API version
*/
module.exports = async ({
jwt,
role,
endpoint = 'http://127.0.0.1:8200',
apiVersion = 'v1'
}) => fetch(`${endpoint}/${apiVersion}/auth/kubernetes/login`, {
method: 'POST',
body: JSON.stringify({
jwt,
role
}),
headers: {
'Content-Type': 'application/json'
}
}).then(response => response.json()).then(({
auth
}) => auth.client_token).catch(error => {
throw error;
});