Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add back support for proxy #597

Merged
merged 1 commit into from
Nov 22, 2023
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
336 changes: 326 additions & 10 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@
"@aws-sdk/credential-providers": "^3.370.0",
"@aws-sdk/node-config-provider": "^3.370.0",
"@aws-sdk/smithy-client": "^3.370.0",
"@aws-sdk/util-retry": "^3.370.0"
"@aws-sdk/util-retry": "^3.370.0",
"proxy-agent": "^6.3.1"
},
"peerDependencies": {
"serverless": "^2.60 || ^3.0.0"
Expand Down
3 changes: 2 additions & 1 deletion src/aws/acm-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
this.acm = new ACMClient({
credentials,
region: isEdge ? Globals.defaultRegion : Globals.getRegion(),
retryStrategy: Globals.getRetryStrategy()
retryStrategy: Globals.getRetryStrategy(),
requestHandler: Globals.getRequestHandler(),
});
}

Expand All @@ -33,7 +34,7 @@
"CertificateSummaryList",
"NextToken",
"NextToken",
new ListCertificatesCommand({ CertificateStatuses: certStatuses })

Check failure on line 37 in src/aws/acm-wrapper.ts

View workflow job for this annotation

GitHub Actions / test (14.x)

Type 'string[]' is not assignable to type 'CertificateStatus[]'.
);
// enhancement idea: weight the choice of cert so longer expires
// and RenewalEligibility = ELIGIBLE is more preferable
Expand Down
3 changes: 2 additions & 1 deletion src/aws/api-gateway-v1-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
this.apiGateway = new APIGatewayClient({
credentials,
region: Globals.getRegion(),
retryStrategy: Globals.getRetryStrategy()
retryStrategy: Globals.getRetryStrategy(),
requestHandler: Globals.getRequestHandler(),
});
}

Expand Down Expand Up @@ -128,7 +129,7 @@
public async getBasePathMappings(domain: DomainConfig): Promise<ApiGatewayMap[]> {
try {
const items = await getAWSPagedResults<BasePathMapping, GetBasePathMappingsCommandInput, GetBasePathMappingsCommandOutput>(
this.apiGateway,

Check failure on line 132 in src/aws/api-gateway-v1-wrapper.ts

View workflow job for this annotation

GitHub Actions / test (14.x)

Argument of type 'import("/home/runner/work/serverless-domain-manager/serverless-domain-manager/node_modules/@aws-sdk/smithy-client/node_modules/@smithy/smithy-client/dist-types/client").Client<any, any, any, any>' is not assignable to parameter of type 'import("/home/runner/work/serverless-domain-manager/serverless-domain-manager/node_modules/@smithy/smithy-client/dist-types/client").Client<any, any, any, any>'.
"items",
"position",
"position",
Expand Down
3 changes: 2 additions & 1 deletion src/aws/api-gateway-v2-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
this.apiGateway = new ApiGatewayV2Client({
credentials,
region: Globals.getRegion(),
retryStrategy: Globals.getRetryStrategy()
retryStrategy: Globals.getRetryStrategy(),
requestHandler: Globals.getRequestHandler(),
});
}

Expand Down Expand Up @@ -156,7 +157,7 @@
public async getBasePathMappings(domain: DomainConfig): Promise<ApiGatewayMap[]> {
try {
const items = await getAWSPagedResults<ApiMapping, GetApiMappingsCommandInput, GetApiMappingsCommandOutput>(
this.apiGateway,

Check failure on line 160 in src/aws/api-gateway-v2-wrapper.ts

View workflow job for this annotation

GitHub Actions / test (14.x)

Argument of type 'import("/home/runner/work/serverless-domain-manager/serverless-domain-manager/node_modules/@aws-sdk/smithy-client/node_modules/@smithy/smithy-client/dist-types/client").Client<any, any, any, any>' is not assignable to parameter of type 'import("/home/runner/work/serverless-domain-manager/serverless-domain-manager/node_modules/@smithy/smithy-client/dist-types/client").Client<any, any, any, any>'.
"Items",
"NextToken",
"NextToken",
Expand Down
3 changes: 2 additions & 1 deletion src/aws/cloud-formation-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class CloudFormationWrapper {
this.cloudFormation = new CloudFormationClient({
credentials,
region: Globals.getRegion(),
retryStrategy: Globals.getRetryStrategy()
retryStrategy: Globals.getRetryStrategy(),
requestHandler: Globals.getRequestHandler(),
});
}

Expand Down
6 changes: 4 additions & 2 deletions src/aws/route53-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
this.route53 = new Route53Client({
credentials,
region: region || Globals.getRegion(),
retryStrategy: Globals.getRetryStrategy()
retryStrategy: Globals.getRetryStrategy(),
requestHandler: Globals.getRequestHandler(),
});
} else {
this.route53 = new Route53Client({
region: Globals.getRegion(),
retryStrategy: Globals.getRetryStrategy()
retryStrategy: Globals.getRetryStrategy(),
requestHandler: Globals.getRequestHandler(),
});
}
}
Expand Down Expand Up @@ -147,7 +149,7 @@
};
// Make API call
try {
await this.route53.send(new ChangeResourceRecordSetsCommand(params));

Check failure on line 152 in src/aws/route53-wrapper.ts

View workflow job for this annotation

GitHub Actions / test (14.x)

Argument of type '{ ChangeBatch: { Changes: { Action: string; ResourceRecordSet: { AliasTarget: { DNSName: string; EvaluateTargetHealth: boolean; HostedZoneId: string; }; Name: string; Type: string; }; }[]; Comment: string; }; HostedZoneId: string; }' is not assignable to parameter of type 'ChangeResourceRecordSetsCommandInput'.
} catch (err) {
throw new Error(
`Failed to ${action} ${recordsToCreate.join(",")} Alias for '${domain.givenDomainName}':\n
Expand Down
3 changes: 2 additions & 1 deletion src/aws/s3-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class S3Wrapper {
constructor(credentials?: any) {
this.s3 = new S3Client({
credentials,
region: Globals.getRegion()
region: Globals.getRegion(),
requestHandler: Globals.getRequestHandler(),
});
}

Expand Down
10 changes: 10 additions & 0 deletions src/globals.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {ServerlessInstance, ServerlessOptions, ServerlessUtils} from "./types";
import {fromIni} from "@aws-sdk/credential-providers";
import {ConfiguredRetryStrategy} from "@aws-sdk/util-retry";
import { NodeHttpHandler } from "@smithy/node-http-handler";
import { ProxyAgent } from "proxy-agent";

export default class Globals {

Expand Down Expand Up @@ -83,4 +85,12 @@ export default class Globals {
(attempt: number) => backoff + attempt * delay // backoff function.
)
}

public static getRequestHandler() {
const proxyAgent = new ProxyAgent();
return new NodeHttpHandler({
httpAgent: proxyAgent,
httpsAgent: proxyAgent
});
}
}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"moduleResolution": "node",
"rootDir": ".",
"target": "es6",
"esModuleInterop": true,
"sourceMap": false,
"outDir": "dist",
"declaration": true,
Expand Down
Loading