File tree Expand file tree Collapse file tree 5 files changed +62
-14
lines changed Expand file tree Collapse file tree 5 files changed +62
-14
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,9 @@ interface Config {
19
19
}
20
20
export class CloudAuth implements Authenticator {
21
21
public isAuthProvider ( user : User ) : boolean {
22
+ if ( ! user || ! user . authProvider ) {
23
+ return false ;
24
+ }
22
25
return user . authProvider . name === 'azure' || user . authProvider . name === 'gcp' ;
23
26
}
24
27
Original file line number Diff line number Diff line change @@ -276,13 +276,11 @@ export class KubeConfig {
276
276
}
277
277
let token : string | null = null ;
278
278
279
- if ( user . authProvider && user . authProvider . config ) {
280
- KubeConfig . authenticators . forEach ( ( authenticator : Authenticator ) => {
281
- if ( authenticator . isAuthProvider ( user ) ) {
282
- token = authenticator . getToken ( user ) ;
283
- }
284
- } ) ;
285
- }
279
+ KubeConfig . authenticators . forEach ( ( authenticator : Authenticator ) => {
280
+ if ( authenticator . isAuthProvider ( user ) ) {
281
+ token = authenticator . getToken ( user ) ;
282
+ }
283
+ } ) ;
286
284
287
285
if ( user . token ) {
288
286
token = 'Bearer ' + user . token ;
Original file line number Diff line number Diff line change @@ -816,6 +816,33 @@ describe('KubeConfig', () => {
816
816
expect ( opts . headers . Authorization ) . to . equal ( `Bearer ${ token } ` ) ;
817
817
}
818
818
} ) ;
819
+ it ( 'should exec with exec auth (other location)' , ( ) => {
820
+ const config = new KubeConfig ( ) ;
821
+ const token = 'token' ;
822
+ const responseStr = `'{
823
+ "apiVersion": "client.authentication.k8s.io/v1beta1",
824
+ "kind": "ExecCredential",
825
+ "status": {
826
+ "token": "${ token } "
827
+ }
828
+ }'` ;
829
+ config . loadFromClusterAndUser (
830
+ { skipTLSVerify : false } as Cluster ,
831
+ {
832
+ exec : {
833
+ command : 'echo' ,
834
+ args : [ `${ responseStr } ` ] ,
835
+ } ,
836
+ } as User ,
837
+ ) ;
838
+ // TODO: inject the exec command here?
839
+ const opts = { } as requestlib . Options ;
840
+ config . applyToRequest ( opts ) ;
841
+ expect ( opts . headers ) . to . not . be . undefined ;
842
+ if ( opts . headers ) {
843
+ expect ( opts . headers . Authorization ) . to . equal ( `Bearer ${ token } ` ) ;
844
+ }
845
+ } ) ;
819
846
it ( 'should throw with no command.' , ( ) => {
820
847
const config = new KubeConfig ( ) ;
821
848
config . loadFromClusterAndUser (
Original file line number Diff line number Diff line change 1
1
import * as fs from 'fs' ;
2
2
import * as u from 'underscore' ;
3
+ import { ExtensionsV1beta1RollbackConfig } from './api' ;
3
4
4
5
export interface Cluster {
5
6
readonly name : string ;
@@ -38,6 +39,7 @@ export interface User {
38
39
readonly name : string ;
39
40
readonly certData ?: string ;
40
41
readonly certFile ?: string ;
42
+ readonly exec ?: any ;
41
43
readonly keyData ?: string ;
42
44
readonly keyFile ?: string ;
43
45
readonly authProvider ?: any ;
Original file line number Diff line number Diff line change @@ -7,6 +7,15 @@ export class ExecAuth implements Authenticator {
7
7
private readonly tokenCache : { [ key : string ] : any } = { } ;
8
8
9
9
public isAuthProvider ( user : User ) {
10
+ if ( ! user ) {
11
+ return false ;
12
+ }
13
+ if ( user . exec ) {
14
+ return true ;
15
+ }
16
+ if ( ! user . authProvider ) {
17
+ return false ;
18
+ }
10
19
return (
11
20
user . authProvider . name === 'exec' || ( user . authProvider . config && user . authProvider . config . exec )
12
21
) ;
@@ -25,18 +34,27 @@ export class ExecAuth implements Authenticator {
25
34
}
26
35
this . tokenCache [ user . name ] = null ;
27
36
}
28
- const config = user . authProvider . config ;
29
- if ( ! config . exec . command ) {
37
+ let exec : any = null ;
38
+ if ( user . authProvider && user . authProvider . config ) {
39
+ exec = user . authProvider . config . exec ;
40
+ }
41
+ if ( user . exec ) {
42
+ exec = user . exec ;
43
+ }
44
+ if ( ! exec ) {
45
+ return null ;
46
+ }
47
+ if ( ! exec . command ) {
30
48
throw new Error ( 'No command was specified for exec authProvider!' ) ;
31
49
}
32
- let cmd = config . exec . command ;
33
- if ( config . exec . args ) {
34
- cmd = `${ cmd } ${ config . exec . args . join ( ' ' ) } ` ;
50
+ let cmd = exec . command ;
51
+ if ( exec . args ) {
52
+ cmd = `${ cmd } ${ exec . args . join ( ' ' ) } ` ;
35
53
}
36
54
let opts : shell . ExecOpts ;
37
- if ( config . exec . env ) {
55
+ if ( exec . env ) {
38
56
const env = { } ;
39
- config . exec . env . forEach ( ( elt ) => ( env [ elt . name ] = elt . value ) ) ;
57
+ exec . env . forEach ( ( elt ) => ( env [ elt . name ] = elt . value ) ) ;
40
58
opts = { env } ;
41
59
}
42
60
const result = shell . exec ( cmd , opts ) ;
You can’t perform that action at this time.
0 commit comments