Skip to content

Commit b54ace6

Browse files
authored
Merge pull request #789 from davidgamero/metrics-migration
Metrics migration
2 parents eb25280 + 193667f commit b54ace6

File tree

6 files changed

+112
-93
lines changed

6 files changed

+112
-93
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"@types/node": "^10.12.0",
5959
"@types/request": "^2.47.1",
6060
"@types/stream-buffers": "^3.0.3",
61-
"@types/tar": "^4.0.3",
61+
"@types/tar": "^6.1.1",
6262
"@types/underscore": "^1.8.9",
6363
"@types/ws": "^6.0.1",
6464
"abort-controller": "^3.0.0",

src/config_test.ts

Lines changed: 56 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { readFileSync } from 'fs';
22
import * as https from 'https';
33
import { join } from 'path';
4+
import { RequestOptions } from 'https';
45

56
import { expect } from 'chai';
67
import mockfs = require('mock-fs');
78
import * as path from 'path';
8-
import * as requestlib from 'request';
99

10-
import { CoreV1Api } from './api';
10+
import { CoreV1Api, RequestContext } from './api';
1111
import { bufferFromFileOrString, findHomeDir, findObject, KubeConfig, makeAbsolutePath } from './config';
1212
import { Cluster, newClusters, newContexts, newUsers, User, ActionOnInvalid } from './config_types';
1313
import { ExecAuth } from './exec_auth';
14+
import { HttpMethod } from '.';
1415

1516
const kcFileName = 'testdata/kubeconfig.yaml';
1617
const kc2FileName = 'testdata/kubeconfig-2.yaml';
@@ -23,7 +24,7 @@ const kcInvalidContextFileName = 'testdata/empty-context-kubeconfig.yaml';
2324
const kcInvalidClusterFileName = 'testdata/empty-cluster-kubeconfig.yaml';
2425

2526
/* tslint:disable: no-empty */
26-
describe('Config', () => {});
27+
describe('Config', () => { });
2728

2829
function validateFileLoad(kc: KubeConfig) {
2930
// check clusters
@@ -252,11 +253,14 @@ describe('KubeConfig', () => {
252253
const kc = new KubeConfig();
253254
kc.loadFromFile(kcFileName);
254255
kc.setCurrentContext('passwd');
256+
const testServerName1 = 'https://company.com';
255257

256-
const opts: requestlib.Options = {
257-
url: 'https://company.com',
258+
const opts: RequestOptions = {
259+
servername: 'https://company.com',
258260
};
259-
await kc.applyToRequest(opts);
261+
const rc = new RequestContext(testServerName1, HttpMethod.GET);
262+
await kc.applySecurityAuthentication(rc);
263+
await kc.applytoHTTPSOptions(opts);
260264
expect(opts).to.deep.equal({
261265
headers: {},
262266
ca: new Buffer('CADATA2', 'utf-8'),
@@ -672,27 +676,26 @@ describe('KubeConfig', () => {
672676
password: passwd,
673677
} as User,
674678
);
675-
const opts = {} as requestlib.Options;
679+
const opts = {} as RequestOptions;
676680

677-
await config.applyToRequest(opts);
681+
await config.applytoHTTPSOptions(opts);
678682

679683
/* tslint:disable no-unused-expression*/
680684
expect(opts.auth).to.not.be.undefined;
681685
if (opts.auth) {
682-
expect(opts.auth.username).to.equal(user);
683-
expect(opts.auth.password).to.equal(passwd);
686+
expect(opts.auth).to.equal(`${user}:${passwd}`);
684687
}
685-
expect(opts.strictSSL).to.equal(false);
688+
expect(opts.rejectUnauthorized).to.equal(false);
686689
});
687690
it('should not populate strict ssl', async () => {
688691
const config = new KubeConfig();
689692

690693
config.loadFromClusterAndUser({ skipTLSVerify: false } as Cluster, {} as User);
691-
const opts = {} as requestlib.Options;
694+
const opts = {} as RequestOptions;
692695

693-
await config.applyToRequest(opts);
696+
await config.applytoHTTPSOptions(opts);
694697

695-
expect(opts.strictSSL).to.equal(undefined);
698+
expect(opts.rejectUnauthorized).to.equal(undefined);
696699
});
697700
it('should populate from token', async () => {
698701
const config = new KubeConfig();
@@ -703,9 +706,9 @@ describe('KubeConfig', () => {
703706
token,
704707
} as User,
705708
);
706-
const opts = {} as requestlib.Options;
709+
const opts = {} as RequestOptions;
707710

708-
await config.applyToRequest(opts);
711+
await config.applytoHTTPSOptions(opts);
709712
expect(opts.headers).to.not.be.undefined;
710713
if (opts.headers) {
711714
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
@@ -726,16 +729,16 @@ describe('KubeConfig', () => {
726729
},
727730
} as User,
728731
);
729-
const opts = {} as requestlib.Options;
732+
const opts = {} as RequestOptions;
730733

731-
await config.applyToRequest(opts);
734+
await config.applytoHTTPSOptions(opts);
732735
expect(opts.headers).to.not.be.undefined;
733736
if (opts.headers) {
734737
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
735738
}
736-
opts.headers = [];
739+
opts.headers = {}
737740
opts.headers.Host = 'foo.com';
738-
await config.applyToRequest(opts);
741+
await config.applytoHTTPSOptions(opts);
739742
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
740743
});
741744

@@ -753,9 +756,9 @@ describe('KubeConfig', () => {
753756
},
754757
} as User,
755758
);
756-
const opts = {} as requestlib.Options;
759+
const opts = {} as RequestOptions;
757760

758-
await config.applyToRequest(opts);
761+
await config.applytoHTTPSOptions(opts);
759762
expect(opts.headers).to.not.be.undefined;
760763
if (opts.headers) {
761764
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
@@ -776,9 +779,9 @@ describe('KubeConfig', () => {
776779
},
777780
} as User,
778781
);
779-
const opts = {} as requestlib.Options;
782+
const opts = {} as RequestOptions;
780783

781-
await config.applyToRequest(opts);
784+
await config.applytoHTTPSOptions(opts);
782785
expect(opts.rejectUnauthorized).to.equal(false);
783786
});
784787

@@ -798,9 +801,9 @@ describe('KubeConfig', () => {
798801
},
799802
} as User,
800803
);
801-
const opts = {} as requestlib.Options;
804+
const opts = {} as RequestOptions;
802805

803-
await config.applyToRequest(opts);
806+
await config.applytoHTTPSOptions(opts);
804807
expect(opts.rejectUnauthorized).to.equal(undefined);
805808
});
806809

@@ -817,9 +820,9 @@ describe('KubeConfig', () => {
817820
},
818821
} as User,
819822
);
820-
const opts = {} as requestlib.Options;
823+
const opts = {} as RequestOptions;
821824

822-
return expect(config.applyToRequest(opts)).to.eventually.be.rejectedWith('Token is expired!');
825+
return expect(config.applytoHTTPSOptions(opts)).to.eventually.be.rejectedWith('Token is expired!');
823826
});
824827

825828
it('should throw with bad command', () => {
@@ -837,8 +840,8 @@ describe('KubeConfig', () => {
837840
},
838841
} as User,
839842
);
840-
const opts = {} as requestlib.Options;
841-
return expect(config.applyToRequest(opts)).to.eventually.be.rejectedWith(
843+
const opts = {} as RequestOptions;
844+
return expect(config.applytoHTTPSOptions(opts)).to.eventually.be.rejectedWith(
842845
/Failed to refresh token/,
843846
);
844847
});
@@ -866,8 +869,8 @@ describe('KubeConfig', () => {
866869
},
867870
} as User,
868871
);
869-
const opts = {} as requestlib.Options;
870-
await config.applyToRequest(opts);
872+
const opts = {} as RequestOptions;
873+
await config.applytoHTTPSOptions(opts);
871874
expect(opts.headers).to.not.be.undefined;
872875
if (opts.headers) {
873876
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
@@ -897,8 +900,8 @@ describe('KubeConfig', () => {
897900
},
898901
} as User,
899902
);
900-
const opts = {} as requestlib.Options;
901-
await config.applyToRequest(opts);
903+
const opts = {} as RequestOptions;
904+
await config.applytoHTTPSOptions(opts);
902905
expect(opts.headers).to.not.be.undefined;
903906
if (opts.headers) {
904907
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
@@ -927,8 +930,8 @@ describe('KubeConfig', () => {
927930
},
928931
} as User,
929932
);
930-
const opts = {} as requestlib.Options;
931-
await config.applyToRequest(opts);
933+
const opts = {} as RequestOptions;
934+
await config.applytoHTTPSOptions(opts);
932935
expect(opts.headers).to.not.be.undefined;
933936
if (opts.headers) {
934937
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
@@ -956,8 +959,8 @@ describe('KubeConfig', () => {
956959
},
957960
} as User,
958961
);
959-
const opts = {} as requestlib.Options;
960-
await config.applyToRequest(opts);
962+
const opts = {} as RequestOptions;
963+
await config.applytoHTTPSOptions(opts);
961964
expect(opts.headers).to.not.be.undefined;
962965
if (opts.headers) {
963966
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
@@ -985,8 +988,8 @@ describe('KubeConfig', () => {
985988
},
986989
} as User,
987990
);
988-
const opts = {} as requestlib.Options;
989-
await config.applyToRequest(opts);
991+
const opts = {} as RequestOptions;
992+
await config.applytoHTTPSOptions(opts);
990993
expect(opts.headers).to.not.be.undefined;
991994
if (opts.headers) {
992995
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
@@ -1021,8 +1024,8 @@ describe('KubeConfig', () => {
10211024
} as User,
10221025
);
10231026
// TODO: inject the exec command here and validate env vars?
1024-
const opts = {} as requestlib.Options;
1025-
await config.applyToRequest(opts);
1027+
const opts = {} as RequestOptions;
1028+
await config.applytoHTTPSOptions(opts);
10261029
expect(opts.headers).to.not.be.undefined;
10271030
if (opts.headers) {
10281031
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
@@ -1057,8 +1060,8 @@ describe('KubeConfig', () => {
10571060
} as User,
10581061
);
10591062
// TODO: inject the exec command here?
1060-
const opts = {} as requestlib.Options;
1061-
await config.applyToRequest(opts);
1063+
const opts = {} as RequestOptions;
1064+
await config.applytoHTTPSOptions(opts);
10621065
expect(opts.headers).to.not.be.undefined;
10631066
if (opts.headers) {
10641067
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
@@ -1088,8 +1091,8 @@ describe('KubeConfig', () => {
10881091
} as User,
10891092
);
10901093
// TODO: inject the exec command here?
1091-
const opts = {} as requestlib.Options;
1092-
await config.applyToRequest(opts);
1094+
const opts = {} as RequestOptions;
1095+
await config.applytoHTTPSOptions(opts);
10931096
expect(opts.headers).to.not.be.undefined;
10941097
if (opts.headers) {
10951098
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
@@ -1120,8 +1123,8 @@ describe('KubeConfig', () => {
11201123
} as User,
11211124
);
11221125
// TODO: inject the exec command here?
1123-
const opts = {} as requestlib.Options;
1124-
await config.applyToRequest(opts);
1126+
const opts = {} as RequestOptions;
1127+
await config.applytoHTTPSOptions(opts);
11251128
let execAuthenticator = (KubeConfig as any).authenticators.find(
11261129
(authenticator) => authenticator instanceof ExecAuth,
11271130
);
@@ -1141,8 +1144,8 @@ describe('KubeConfig', () => {
11411144
},
11421145
} as User,
11431146
);
1144-
const opts = {} as requestlib.Options;
1145-
return expect(config.applyToRequest(opts)).to.eventually.be.rejectedWith(
1147+
const opts = {} as RequestOptions;
1148+
return expect(config.applytoHTTPSOptions(opts)).to.eventually.be.rejectedWith(
11461149
'No command was specified for exec authProvider!',
11471150
);
11481151
});
@@ -1440,8 +1443,8 @@ describe('KubeConfig', () => {
14401443
});
14411444

14421445
it('should apply to request', async () => {
1443-
const opts = {} as requestlib.Options;
1444-
await emptyConfig.applyToRequest(opts);
1446+
const opts = {} as RequestOptions;
1447+
await emptyConfig.applytoHTTPSOptions(opts);
14451448
});
14461449
});
14471450

@@ -1503,4 +1506,4 @@ describe('KubeConfig', () => {
15031506
mockfs.restore();
15041507
});
15051508
});
1506-
});
1509+
});

src/gen/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@
2828
"devDependencies": {
2929
"typescript": "^4.1.3"
3030
}
31-
}
31+
}

0 commit comments

Comments
 (0)