Skip to content

Commit

Permalink
feat(config): read exec arguments from kubeconfig (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
cfellin1 authored and silasbw committed Sep 26, 2018
1 parent ed47d43 commit 58541c7
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,25 @@ function fromKubeconfig(kubeconfig, current) {
};
}

if (user.exec) {
const env = {};
user.exec.env.forEach(variable => {
env[variable.name] = variable.value;
});
const args = user.exec.args.join(' ');
auth = {
provider: {
type: 'cmd',
config: {
'cmd-args': args,
'cmd-path': user.exec.command,
'token-key': 'status.token',
'cmd-env': env
}
}
};
}

if (user.username) auth.user = user.username;
if (user.password) auth.pass = user.password;
}
Expand Down
50 changes: 50 additions & 0 deletions test/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,56 @@ describe('Config', () => {
expect(args.auth.provider.type).equals('cmd');
});

it('handles user.exec', () => {
const command = 'foo-command';
const cmdArgs = ['arg1', 'arg2'];
const envKey = 'foo-env-key';
const envValue = 'foo-env-value';
const kubeconfig = {
'apiVersion': 'v1',
'kind': 'Config',
'preferences': {},
'current-context': 'foo-context',
'contexts': [
{
name: 'foo-context',
context: {
cluster: 'foo-cluster',
user: 'foo-user'
}
}
],
'clusters': [
{
name: 'foo-cluster',
cluster: {
server: 'https://192.168.42.121:8443'
}
}
],
'users': [
{
name: 'foo-user',
user: {
exec: {
command,
args: cmdArgs,
env: [{
name: envKey,
value: envValue
}]
}
}
}
]
};
const args = config.fromKubeconfig(kubeconfig);
expect(args.auth.provider.type).equals('cmd');
expect(args.auth.provider.config['cmd-args']).equals(cmdArgs.join(' '));
expect(args.auth.provider.config['cmd-path']).equals(command);
expect(args.auth.provider.config['cmd-env']).deep.equals({ [envKey]: envValue });
});

it('handles manually specified current-context', () => {
const kubeconfig = {
'apiVersion': 'v1',
Expand Down

0 comments on commit 58541c7

Please sign in to comment.