Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions jest.config.cjs

This file was deleted.

32 changes: 20 additions & 12 deletions src/CredentialsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@ export class CredentialsClient {
private readonly requestHandler?: NodeHttpHandler;

constructor(props: CredentialsClientProps) {
this.region = props.region;
if (props.region !== undefined) {
this.region = props.region;
}
if (props.proxyServer) {
info('Configuring proxy handler for STS client');
const getProxyForUrl = new ProxyResolver({
const proxyOptions: { httpProxy: string; httpsProxy: string; noProxy?: string } = {
httpProxy: 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 });
this.requestHandler = new NodeHttpHandler({
httpsAgent: handler,
Expand All @@ -38,11 +43,14 @@ export class CredentialsClient {

public get stsClient(): STSClient {
if (!this._stsClient) {
this._stsClient = new STSClient({
region: this.region,
customUserAgent: USER_AGENT,
requestHandler: this.requestHandler ? this.requestHandler : undefined,
});
const config = { customUserAgent: USER_AGENT } as {
customUserAgent: string;
region?: string;
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;
}
Expand Down Expand Up @@ -88,9 +96,9 @@ export class CredentialsClient {
}

private async loadCredentials() {
const client = new STSClient({
requestHandler: this.requestHandler ? this.requestHandler : undefined,
});
const config = {} as { requestHandler?: NodeHttpHandler };
if (this.requestHandler !== undefined) config.requestHandler = this.requestHandler;
const client = new STSClient(config);
return client.config.credentials();
}
}
5 changes: 3 additions & 2 deletions src/ProxyResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ export class ProxyResolver {
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 => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual proxy fix is here. The other changes in this PR are related to setting "exactOptionalPropertyTypes": true in the tsconfig.json

return this.getProxyForUrlOptions(url, this.options);
}
};

private getProxyForUrlOptions(url: string | URL, options?: ProxyOptions): string {
let parsedUrl: URL;
Expand Down
9 changes: 8 additions & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,14 @@ export async function getCallerIdentity(client: STSClient): Promise<{ Account: s
if (!identity.Account || !identity.Arn) {
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
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ export async function run() {
exportRegion(region, outputEnvCredentials);

// 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 webIdentityToken: string;

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"strict": true,
"exactOptionalPropertyTypes": false,
"exactOptionalPropertyTypes": true,
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
Expand Down
Loading