Skip to content

Commit e548962

Browse files
committed
multiple changes:
fix: expiry is not set properly in config fix: add type for Config
1 parent 35df1ad commit e548962

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/cloud_auth.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ import * as shelljs from 'shelljs';
55
import { Authenticator } from './auth';
66
import { User } from './config_types';
77

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+
}
820
export class CloudAuth implements Authenticator {
921
public isAuthProvider(user: User): boolean {
1022
return (
@@ -21,7 +33,7 @@ export class CloudAuth implements Authenticator {
2133
return 'Bearer ' + config['access-token'];
2234
}
2335

24-
private isExpired(config) {
36+
private isExpired(config: Config) {
2537
const token = config['access-token'];
2638
const expiry = config.expiry;
2739
if (!token) {
@@ -38,7 +50,7 @@ export class CloudAuth implements Authenticator {
3850
return false;
3951
}
4052

41-
private updateAccessToken(config) {
53+
private updateAccessToken(config: Config) {
4254
if (!config['cmd-path']) {
4355
throw new Error('Token is expired!');
4456
}
@@ -51,7 +63,7 @@ export class CloudAuth implements Authenticator {
5163
if (args) {
5264
cmd = `${cmd} ${args}`;
5365
}
54-
result = shelljs.exec(cmd, {silent: true});
66+
result = shelljs.exec(cmd, { silent: true });
5567
if (result.code !== 0) {
5668
throw new Error(result.stderr);
5769
}
@@ -64,7 +76,7 @@ export class CloudAuth implements Authenticator {
6476

6577
let tokenPathKey = config['token-key'];
6678

67-
let expiryPathKey = config['token-key'];
79+
let expiryPathKey = config['expiry-key'];
6880
// Format in file is {<query>}, so slice it out and add '$'
6981
tokenPathKey = '$' + tokenPathKey.slice(1, -1);
7082
expiryPathKey = '$' + expiryPathKey.slice(1, -1);

0 commit comments

Comments
 (0)