Skip to content

Commit

Permalink
feat(auth-provider): support for auth-provider access-token in fromKu…
Browse files Browse the repository at this point in the history
…beconfig() (#112)
  • Loading branch information
theothermike authored and silasbw committed Jun 15, 2017
1 parent 520554a commit 9b02bc2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ function fromKubeconfig(kubeconfig, current) {
auth.bearer = user.token;
}

if (user['auth-provider'] && user['auth-provider'].config && user['auth-provider'].config['access-token']) {
auth.bearer = user['auth-provider'].config['access-token'];
}

if (user.username) auth.user = user.username;
if (user.password) auth.pass = user.password;
}
Expand Down
40 changes: 40 additions & 0 deletions test/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,46 @@ describe('Config', () => {
assume(args.auth.bearer).equals('foo-token');
});

it('handles auth-provider.config.access-token', () => {
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: {
'auth-provider': {
config: {
'access-token': 'foo-token'
}
}
}
}
]
};
const args = config.fromKubeconfig(kubeconfig);
assume(args.auth.bearer).equals('foo-token');
});

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

0 comments on commit 9b02bc2

Please sign in to comment.