@@ -5,6 +5,18 @@ import * as shelljs from 'shelljs';
5
5
import { Authenticator } from './auth' ;
6
6
import { User } from './config_types' ;
7
7
8
+ /* FIXME: maybe we can extend the User and User.authProvider type to have a proper type.
9
+ Currently user.authProvider has `any` type and so we don't have a type for user.authProvider.config.
10
+ We therefore define its type here
11
+ */
12
+ interface Config {
13
+ expiry : string ;
14
+ [ 'cmd-args' ] ?: string ;
15
+ [ 'cmd-path' ] ?: string ;
16
+ [ 'token-key' ] : string ;
17
+ [ 'expiry-key' ] : string ;
18
+ [ 'access-token' ] ?: string ;
19
+ }
8
20
export class CloudAuth implements Authenticator {
9
21
public isAuthProvider ( user : User ) : boolean {
10
22
return (
@@ -21,7 +33,7 @@ export class CloudAuth implements Authenticator {
21
33
return 'Bearer ' + config [ 'access-token' ] ;
22
34
}
23
35
24
- private isExpired ( config ) {
36
+ private isExpired ( config : Config ) {
25
37
const token = config [ 'access-token' ] ;
26
38
const expiry = config . expiry ;
27
39
if ( ! token ) {
@@ -38,7 +50,7 @@ export class CloudAuth implements Authenticator {
38
50
return false ;
39
51
}
40
52
41
- private updateAccessToken ( config ) {
53
+ private updateAccessToken ( config : Config ) {
42
54
if ( ! config [ 'cmd-path' ] ) {
43
55
throw new Error ( 'Token is expired!' ) ;
44
56
}
@@ -51,7 +63,7 @@ export class CloudAuth implements Authenticator {
51
63
if ( args ) {
52
64
cmd = `${ cmd } ${ args } ` ;
53
65
}
54
- result = shelljs . exec ( cmd , { silent : true } ) ;
66
+ result = shelljs . exec ( cmd , { silent : true } ) ;
55
67
if ( result . code !== 0 ) {
56
68
throw new Error ( result . stderr ) ;
57
69
}
@@ -64,7 +76,7 @@ export class CloudAuth implements Authenticator {
64
76
65
77
let tokenPathKey = config [ 'token-key' ] ;
66
78
67
- let expiryPathKey = config [ 'token -key' ] ;
79
+ let expiryPathKey = config [ 'expiry -key' ] ;
68
80
// Format in file is {<query>}, so slice it out and add '$'
69
81
tokenPathKey = '$' + tokenPathKey . slice ( 1 , - 1 ) ;
70
82
expiryPathKey = '$' + expiryPathKey . slice ( 1 , - 1 ) ;
0 commit comments