Skip to content

Commit

Permalink
Fix Route53
Browse files Browse the repository at this point in the history
  • Loading branch information
rddimon committed Dec 7, 2023
1 parent b832502 commit 1999f1d
Show file tree
Hide file tree
Showing 16 changed files with 2,880 additions and 2,882 deletions.
9 changes: 6 additions & 3 deletions src/aws/route53-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@ import { getAWSPagedResults } from "../utils";

class Route53Wrapper {
public route53: Route53Client;
private readonly region: string;

constructor (credentials?: any, region?: string) {
// not null and not undefined
if (credentials) {
this.region = region || Globals.getRegion();
this.route53 = new Route53Client([{
credentials,
region: region || Globals.getRegion(),
region: this.region,
retryStrategy: Globals.getRetryStrategy(),
requestHandler: Globals.getRequestHandler()
}]);
} else {
this.region = Globals.getRegion();
this.route53 = new Route53Client([{
region: Globals.getRegion(),
region: this.region,
retryStrategy: Globals.getRetryStrategy(),
requestHandler: Globals.getRequestHandler()
}]);
Expand Down Expand Up @@ -103,7 +106,7 @@ class Route53Wrapper {
let routingOptions = {};
if (route53Params.routingPolicy === Globals.routingPolicies.latency) {
routingOptions = {
Region: await this.route53.config[0].region,
Region: this.region,
SetIdentifier: route53Params.setIdentifier ?? domainInfo.domainName,
...route53healthCheck
};
Expand Down
84 changes: 42 additions & 42 deletions test/integration-tests/apigateway.ts
Original file line number Diff line number Diff line change
@@ -1,91 +1,91 @@
import {
APIGatewayClient,
CreateRestApiCommand,
CreateRestApiCommandOutput,
DeleteRestApiCommand,
GetBasePathMappingsCommand,
GetBasePathMappingsCommandOutput, GetDomainNameCommand, GetDomainNameCommandOutput,
GetResourcesCommand,
GetResourcesCommandOutput
APIGatewayClient,
CreateRestApiCommand,
CreateRestApiCommandOutput,
DeleteRestApiCommand,
GetBasePathMappingsCommand,
GetBasePathMappingsCommandOutput, GetDomainNameCommand, GetDomainNameCommandOutput,
GetResourcesCommand,
GetResourcesCommandOutput
} from "@aws-sdk/client-api-gateway";
import Globals from "../../src/globals";

export default class APIGatewayWrap {
private client: APIGatewayClient;

constructor(region: string) {
this.client = new APIGatewayClient({
region,
retryStrategy: Globals.getRetryStrategy()
});
constructor (region: string) {
this.client = new APIGatewayClient({
region,
retryStrategy: Globals.getRetryStrategy()
});
}

/**
* Make API Gateway calls to create an API Gateway
* @param {string} restApiName
* @return {Object} Contains restApiId and resourceId
*/
public async setupApiGatewayResources(restApiName) {
const restAPI: CreateRestApiCommandOutput = await this.client.send(
new CreateRestApiCommand({name: restApiName})
)
public async setupApiGatewayResources (restApiName) {
const restAPI: CreateRestApiCommandOutput = await this.client.send(
new CreateRestApiCommand({ name: restApiName })
);

const restApiId = restAPI.id;
const resources: GetResourcesCommandOutput = await this.client.send(
new GetResourcesCommand({restApiId})
)
const restApiId = restAPI.id;
const resources: GetResourcesCommandOutput = await this.client.send(
new GetResourcesCommand({ restApiId })
);

const resourceId = resources.items[0].id;
return {restApiId, resourceId};
const resourceId = resources.items[0].id;
return { restApiId, resourceId };
}

/**
* Make API Gateway calls to delete an API Gateway
* @param {string} restApiId
* @return {boolean} Returns true if deleted
*/
public async deleteApiGatewayResources(restApiId) {
return await this.client.send(
new DeleteRestApiCommand({restApiId})
);
public async deleteApiGatewayResources (restApiId) {
return await this.client.send(
new DeleteRestApiCommand({ restApiId })
);
}

/**
* Gets stage of given URL from AWS
* @param domainName
* @returns {Promise<String>}
*/
public async getStage(domainName) {
const result: GetBasePathMappingsCommandOutput = await this.client.send(
new GetBasePathMappingsCommand({domainName})
)
public async getStage (domainName) {
const result: GetBasePathMappingsCommandOutput = await this.client.send(
new GetBasePathMappingsCommand({ domainName })
);

return result.items[0].stage;
return result.items[0].stage;
}

/**
* Gets basePath of given URL from AWS
* @param domainName
* @returns {Promise<String>}
*/
public async getBasePath(domainName) {
const result: GetBasePathMappingsCommandOutput = await this.client.send(
new GetBasePathMappingsCommand({domainName})
)
public async getBasePath (domainName) {
const result: GetBasePathMappingsCommandOutput = await this.client.send(
new GetBasePathMappingsCommand({ domainName })
);

return result.items[0].basePath;
return result.items[0].basePath;
}

/**
* Gets endpoint type of given URL from AWS
* @param domainName
* @returns {Promise<String>}
*/
public async getEndpointType(domainName) {
const result: GetDomainNameCommandOutput = await this.client.send(
new GetDomainNameCommand({domainName})
)
public async getEndpointType (domainName) {
const result: GetDomainNameCommandOutput = await this.client.send(
new GetDomainNameCommand({ domainName })
);

return result.endpointConfiguration.types[0];
return result.endpointConfiguration.types[0];
}
}
20 changes: 10 additions & 10 deletions test/integration-tests/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ import randomstring = require("randomstring");
// this is set in the each sls configs for the cleanup purpose in case of tests failure
const PLUGIN_IDENTIFIER = "sdm";
const RANDOM_STRING = randomstring.generate({
capitalization: "lowercase",
charset: "alphanumeric",
length: 5,
capitalization: "lowercase",
charset: "alphanumeric",
length: 5
});
const TEMP_DIR = `~/tmp/domain-manager-integration-tests/${RANDOM_STRING}`;
const TEST_DOMAIN = process.env.TEST_DOMAIN;

// setting a `RANDOM_STRING` variable to use in each integration test
// by this we are going to run unique test each time
// and handling case for running tests for the same AWS account at the same time by different runs
process.env.PLUGIN_IDENTIFIER = PLUGIN_IDENTIFIER
process.env.RANDOM_STRING = RANDOM_STRING
process.env.PLUGIN_IDENTIFIER = PLUGIN_IDENTIFIER;
process.env.RANDOM_STRING = RANDOM_STRING;

if (!TEST_DOMAIN) {
throw new Error("TEST_DOMAIN environment variable not set");
throw new Error("TEST_DOMAIN environment variable not set");
}

export {
PLUGIN_IDENTIFIER,
RANDOM_STRING,
TEMP_DIR,
TEST_DOMAIN,
PLUGIN_IDENTIFIER,
RANDOM_STRING,
TEMP_DIR,
TEST_DOMAIN
};
Loading

0 comments on commit 1999f1d

Please sign in to comment.