* chore: use stricter typescript config * fix: properly expose getProxyForUrl (in #1482)
This commit is contained in:
parent
6b19f7ffe6
commit
cea42985ac
6 changed files with 36 additions and 48 deletions
|
|
@ -1,31 +0,0 @@
|
||||||
/** @type {import('jest').Config} */
|
|
||||||
const config = {
|
|
||||||
verbose: true,
|
|
||||||
transform: {
|
|
||||||
'^.+\\.m?[tj]sx?$': ['ts-jest'],
|
|
||||||
},
|
|
||||||
testMatch: [
|
|
||||||
'<rootDir>/src/**/__tests__/**/*.ts?(x)',
|
|
||||||
'<rootDir>/(test|src)/**/*(*.)@(spec|test).ts?(x)',
|
|
||||||
'<rootDir>/test/**/*.(test|spec).(js|jsx|ts|tsx)',
|
|
||||||
],
|
|
||||||
clearMocks: true,
|
|
||||||
collectCoverage: true,
|
|
||||||
coverageReporters: ['json', 'lcov', 'clover', 'cobertura', 'text'],
|
|
||||||
coverageDirectory: 'coverage',
|
|
||||||
coveragePathIgnorePatterns: ['/node_modules/'],
|
|
||||||
testPathIgnorePatterns: ['/node_modules/'],
|
|
||||||
watchPathIgnorePatterns: ['/node_modules/'],
|
|
||||||
reporters: [
|
|
||||||
'default',
|
|
||||||
[
|
|
||||||
'jest-junit',
|
|
||||||
{
|
|
||||||
outputDirectory: 'test-reports',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
],
|
|
||||||
preset: 'ts-jest/presets/default-legacy',
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = config;
|
|
||||||
|
|
@ -20,14 +20,19 @@ export class CredentialsClient {
|
||||||
private readonly requestHandler?: NodeHttpHandler;
|
private readonly requestHandler?: NodeHttpHandler;
|
||||||
|
|
||||||
constructor(props: CredentialsClientProps) {
|
constructor(props: CredentialsClientProps) {
|
||||||
this.region = props.region;
|
if (props.region !== undefined) {
|
||||||
|
this.region = props.region;
|
||||||
|
}
|
||||||
if (props.proxyServer) {
|
if (props.proxyServer) {
|
||||||
info('Configuring proxy handler for STS client');
|
info('Configuring proxy handler for STS client');
|
||||||
const getProxyForUrl = new ProxyResolver({
|
const proxyOptions: { httpProxy: string; httpsProxy: string; noProxy?: string } = {
|
||||||
httpProxy: props.proxyServer,
|
httpProxy: props.proxyServer,
|
||||||
httpsProxy: props.proxyServer,
|
httpsProxy: props.proxyServer,
|
||||||
noProxy: props.noProxy,
|
};
|
||||||
}).getProxyForUrl;
|
if (props.noProxy !== undefined) {
|
||||||
|
proxyOptions.noProxy = props.noProxy;
|
||||||
|
}
|
||||||
|
const getProxyForUrl = new ProxyResolver(proxyOptions).getProxyForUrl;
|
||||||
const handler = new ProxyAgent({ getProxyForUrl });
|
const handler = new ProxyAgent({ getProxyForUrl });
|
||||||
this.requestHandler = new NodeHttpHandler({
|
this.requestHandler = new NodeHttpHandler({
|
||||||
httpsAgent: handler,
|
httpsAgent: handler,
|
||||||
|
|
@ -38,11 +43,14 @@ export class CredentialsClient {
|
||||||
|
|
||||||
public get stsClient(): STSClient {
|
public get stsClient(): STSClient {
|
||||||
if (!this._stsClient) {
|
if (!this._stsClient) {
|
||||||
this._stsClient = new STSClient({
|
const config = { customUserAgent: USER_AGENT } as {
|
||||||
region: this.region,
|
customUserAgent: string;
|
||||||
customUserAgent: USER_AGENT,
|
region?: string;
|
||||||
requestHandler: this.requestHandler ? this.requestHandler : undefined,
|
requestHandler?: NodeHttpHandler;
|
||||||
});
|
};
|
||||||
|
if (this.region !== undefined) config.region = this.region;
|
||||||
|
if (this.requestHandler !== undefined) config.requestHandler = this.requestHandler;
|
||||||
|
this._stsClient = new STSClient(config);
|
||||||
}
|
}
|
||||||
return this._stsClient;
|
return this._stsClient;
|
||||||
}
|
}
|
||||||
|
|
@ -88,9 +96,9 @@ export class CredentialsClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async loadCredentials() {
|
private async loadCredentials() {
|
||||||
const client = new STSClient({
|
const config = {} as { requestHandler?: NodeHttpHandler };
|
||||||
requestHandler: this.requestHandler ? this.requestHandler : undefined,
|
if (this.requestHandler !== undefined) config.requestHandler = this.requestHandler;
|
||||||
});
|
const client = new STSClient(config);
|
||||||
return client.config.credentials();
|
return client.config.credentials();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,10 @@ export class ProxyResolver {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
getProxyForUrl(url: string, _req: http.ClientRequest): string {
|
// This method matches the interface expected by 'proxy-agent'. It is an arrow function to bind 'this'.
|
||||||
|
public readonly getProxyForUrl = (url: string, _req: http.ClientRequest): string => {
|
||||||
return this.getProxyForUrlOptions(url, this.options);
|
return this.getProxyForUrlOptions(url, this.options);
|
||||||
}
|
};
|
||||||
|
|
||||||
private getProxyForUrlOptions(url: string | URL, options?: ProxyOptions): string {
|
private getProxyForUrlOptions(url: string | URL, options?: ProxyOptions): string {
|
||||||
let parsedUrl: URL;
|
let parsedUrl: URL;
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,14 @@ export async function getCallerIdentity(client: STSClient): Promise<{ Account: s
|
||||||
if (!identity.Account || !identity.Arn) {
|
if (!identity.Account || !identity.Arn) {
|
||||||
throw new Error('Could not get Account ID or ARN from STS. Did you set credentials?');
|
throw new Error('Could not get Account ID or ARN from STS. Did you set credentials?');
|
||||||
}
|
}
|
||||||
return { Account: identity.Account, Arn: identity.Arn, UserId: identity.UserId };
|
const result: { Account: string; Arn: string; UserId?: string } = {
|
||||||
|
Account: identity.Account,
|
||||||
|
Arn: identity.Arn,
|
||||||
|
};
|
||||||
|
if (identity.UserId !== undefined) {
|
||||||
|
result.UserId = identity.UserId;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtains account ID from STS Client and sets it as output
|
// Obtains account ID from STS Client and sets it as output
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,10 @@ export async function run() {
|
||||||
exportRegion(region, outputEnvCredentials);
|
exportRegion(region, outputEnvCredentials);
|
||||||
|
|
||||||
// Instantiate credentials client
|
// Instantiate credentials client
|
||||||
const credentialsClient = new CredentialsClient({ region, proxyServer, noProxy });
|
const clientProps: { region: string; proxyServer?: string; noProxy?: string } = { region };
|
||||||
|
if (proxyServer) clientProps.proxyServer = proxyServer;
|
||||||
|
if (noProxy) clientProps.noProxy = noProxy;
|
||||||
|
const credentialsClient = new CredentialsClient(clientProps);
|
||||||
let sourceAccountId: string;
|
let sourceAccountId: string;
|
||||||
let webIdentityToken: string;
|
let webIdentityToken: string;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
"allowUnreachableCode": false,
|
"allowUnreachableCode": false,
|
||||||
"allowUnusedLabels": false,
|
"allowUnusedLabels": false,
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"exactOptionalPropertyTypes": false,
|
"exactOptionalPropertyTypes": true,
|
||||||
"noFallthroughCasesInSwitch": true,
|
"noFallthroughCasesInSwitch": true,
|
||||||
"noImplicitOverride": true,
|
"noImplicitOverride": true,
|
||||||
"noImplicitReturns": true,
|
"noImplicitReturns": true,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue