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

Commit

Permalink
Add support for "dynamic" EKS token auth (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradleybluebean authored and andresmgot committed Oct 23, 2019
1 parent c220233 commit 7b2113a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const fs = require('fs');
const moment = require('moment');
const path = require('path');
const yaml = require('js-yaml');
const proc = require('child_process');

function loadKubeConfig() {
const kubeCfgPath = path.join(process.env.HOME, '.kube/config');
Expand Down Expand Up @@ -104,6 +105,7 @@ function getToken(userInfo) {
const token = _.get(userInfo, 'user.token') ||
_.get(userInfo, 'user.auth-provider.config.id-token');
const accessToken = _.get(userInfo, 'user.auth-provider.config.access-token');
let cmd = _.get(userInfo, 'user.exec.command');
if (token) {
return token;
} else if (accessToken) {
Expand All @@ -117,6 +119,29 @@ function getToken(userInfo) {
}
}
return accessToken;
} else if (cmd && cmd === 'aws') {
const args = _.get(userInfo, 'user.exec.args');
if (args) {
cmd = `${cmd} ${args.join(' ')}`;
}
const env = _.get(userInfo, 'user.exec.env', []);
if (env) {
const profile = _.find(env, e => e.name === 'AWS_PROFILE');
if (profile) {
cmd = `${cmd} --profile ${profile.value}`;
}
}
let output = {};
try {
output = proc.execSync(cmd);
} catch (err) {
throw new Error(`Failed to refresh token: ${err.message}`);
}
const resultObj = JSON.parse(output);
const execToken = _.get(resultObj, 'status.token');
if (execToken) {
return execToken;
}
}
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-kubeless",
"version": "0.8.0",
"version": "0.8.1",
"description": "This plugin enables support for Kubeless within the [Serverless Framework](https://github.com/serverless).",
"main": "index.js",
"directories": {
Expand Down

0 comments on commit 7b2113a

Please sign in to comment.