Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit 7b2113a

Browse files
bradleybluebeanandresmgot
authored andcommitted
Add support for "dynamic" EKS token auth (#189)
1 parent c220233 commit 7b2113a

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/helpers.js

+25
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const fs = require('fs');
2121
const moment = require('moment');
2222
const path = require('path');
2323
const yaml = require('js-yaml');
24+
const proc = require('child_process');
2425

2526
function loadKubeConfig() {
2627
const kubeCfgPath = path.join(process.env.HOME, '.kube/config');
@@ -104,6 +105,7 @@ function getToken(userInfo) {
104105
const token = _.get(userInfo, 'user.token') ||
105106
_.get(userInfo, 'user.auth-provider.config.id-token');
106107
const accessToken = _.get(userInfo, 'user.auth-provider.config.access-token');
108+
let cmd = _.get(userInfo, 'user.exec.command');
107109
if (token) {
108110
return token;
109111
} else if (accessToken) {
@@ -117,6 +119,29 @@ function getToken(userInfo) {
117119
}
118120
}
119121
return accessToken;
122+
} else if (cmd && cmd === 'aws') {
123+
const args = _.get(userInfo, 'user.exec.args');
124+
if (args) {
125+
cmd = `${cmd} ${args.join(' ')}`;
126+
}
127+
const env = _.get(userInfo, 'user.exec.env', []);
128+
if (env) {
129+
const profile = _.find(env, e => e.name === 'AWS_PROFILE');
130+
if (profile) {
131+
cmd = `${cmd} --profile ${profile.value}`;
132+
}
133+
}
134+
let output = {};
135+
try {
136+
output = proc.execSync(cmd);
137+
} catch (err) {
138+
throw new Error(`Failed to refresh token: ${err.message}`);
139+
}
140+
const resultObj = JSON.parse(output);
141+
const execToken = _.get(resultObj, 'status.token');
142+
if (execToken) {
143+
return execToken;
144+
}
120145
}
121146
return null;
122147
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-kubeless",
3-
"version": "0.8.0",
3+
"version": "0.8.1",
44
"description": "This plugin enables support for Kubeless within the [Serverless Framework](https://github.com/serverless).",
55
"main": "index.js",
66
"directories": {

0 commit comments

Comments
 (0)