Skip to content

Commit

Permalink
Merge pull request #17 from reapit/construct/entra-app
Browse files Browse the repository at this point in the history
construct: add EntraIDApplication
  • Loading branch information
joshbalfour committed Nov 1, 2023
2 parents 130b791 + 4fe0714 commit 3813f28
Show file tree
Hide file tree
Showing 37 changed files with 952 additions and 48 deletions.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,20 @@ var handler = async (event) => {
if (!mapping) {
throw new Error(`no domain mapping found for host ${host}`);
}
let domainName = typeof mapping === "string" ? mapping : mapping.destination;
if (domainName.includes("//")) {
domainName = domainName.split("//")[1].split("/")[0];
}
req.origin = {
custom: {
...req.origin.custom,
domainName: mapping.domain
domainName
}
};
req.headers["host"] = [
{
key: "host",
value: mapping.domain
value: domainName
}
];
middlewares.forEach((middleware) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var middlewares = [];
var rewriteLocationHeader = (location, host2) => {
try {
const url = new URL(location);
if (url.hostname !== host2 && domains.find((domain) => url.hostname.endsWith(domain))) {
if (url.hostname !== host2 && domains.find((domain) => url.hostname.endsWith(domain.includes("//") ? new URL(domain).hostname : domain))) {
url.hostname = host2;
}
return url.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,29 @@
}
}
},
"0f4c1084359ae06a7ede8c4134bc004f2f6bf7e40aa54a8ba73f846c88b98ee4": {
"e568ed14759e05024fa779a0a128447c7c6adf222da22882dd3fd471ba571039": {
"source": {
"path": "asset.0f4c1084359ae06a7ede8c4134bc004f2f6bf7e40aa54a8ba73f846c88b98ee4",
"path": "asset.e568ed14759e05024fa779a0a128447c7c6adf222da22882dd3fd471ba571039",
"packaging": "zip"
},
"destinations": {
"028446965111-eu-central-1": {
"bucketName": "cdk-hnb659fds-assets-028446965111-eu-central-1",
"objectKey": "0f4c1084359ae06a7ede8c4134bc004f2f6bf7e40aa54a8ba73f846c88b98ee4.zip",
"objectKey": "e568ed14759e05024fa779a0a128447c7c6adf222da22882dd3fd471ba571039.zip",
"region": "eu-central-1",
"assumeRoleArn": "arn:${AWS::Partition}:iam::028446965111:role/cdk-hnb659fds-file-publishing-role-028446965111-eu-central-1"
}
}
},
"98012992a7b8061681d5eca60cdf9ca75a3c205f296f40bf8e1a79fba1490fa4": {
"c7e4fd4b5953cf90cfa743ee60a5d3a3d2b043a5db3e19a203577ab7890f222b": {
"source": {
"path": "edge-api-test-stack-dev.template.json",
"packaging": "file"
},
"destinations": {
"028446965111-eu-central-1": {
"bucketName": "cdk-hnb659fds-assets-028446965111-eu-central-1",
"objectKey": "98012992a7b8061681d5eca60cdf9ca75a3c205f296f40bf8e1a79fba1490fa4.json",
"objectKey": "c7e4fd4b5953cf90cfa743ee60a5d3a3d2b043a5db3e19a203577ab7890f222b.json",
"region": "eu-central-1",
"assumeRoleArn": "arn:${AWS::Partition}:iam::028446965111:role/cdk-hnb659fds-file-publishing-role-028446965111-eu-central-1"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@
"Properties": {
"Code": {
"S3Bucket": "cdk-hnb659fds-assets-028446965111-eu-central-1",
"S3Key": "0f4c1084359ae06a7ede8c4134bc004f2f6bf7e40aa54a8ba73f846c88b98ee4.zip"
"S3Key": "e568ed14759e05024fa779a0a128447c7c6adf222da22882dd3fd471ba571039.zip"
},
"Handler": "redirector.handler",
"Role": {
Expand All @@ -577,7 +577,7 @@
],
"Metadata": {
"aws:cdk:path": "edge-api-test-stack-dev/api/api/redirect/Resource",
"aws:asset:path": "asset.0f4c1084359ae06a7ede8c4134bc004f2f6bf7e40aa54a8ba73f846c88b98ee4",
"aws:asset:path": "asset.e568ed14759e05024fa779a0a128447c7c6adf222da22882dd3fd471ba571039",
"aws:asset:is-bundled": false,
"aws:asset:property": "Code"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::028446965111:role/cdk-hnb659fds-deploy-role-028446965111-eu-central-1",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::028446965111:role/cdk-hnb659fds-cfn-exec-role-028446965111-eu-central-1",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-028446965111-eu-central-1/98012992a7b8061681d5eca60cdf9ca75a3c205f296f40bf8e1a79fba1490fa4.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-028446965111-eu-central-1/c7e4fd4b5953cf90cfa743ee60a5d3a3d2b043a5db3e19a203577ab7890f222b.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@
"aws:cdk:cloudformation:props": {
"code": {
"s3Bucket": "cdk-hnb659fds-assets-028446965111-eu-central-1",
"s3Key": "0f4c1084359ae06a7ede8c4134bc004f2f6bf7e40aa54a8ba73f846c88b98ee4.zip"
"s3Key": "e568ed14759e05024fa779a0a128447c7c6adf222da22882dd3fd471ba571039.zip"
},
"handler": "redirector.handler",
"role": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,20 @@ var handler = async (event) => {
if (!mapping) {
throw new Error(`no domain mapping found for host ${host}`);
}
let domainName = typeof mapping === "string" ? mapping : mapping.destination;
if (domainName.includes("//")) {
domainName = domainName.split("//")[1].split("/")[0];
}
req.origin = {
custom: {
...req.origin.custom,
domainName: mapping.domain
domainName
}
};
req.headers["host"] = [
{
key: "host",
value: mapping.domain
value: domainName
}
];
middlewares.forEach((middleware) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,35 @@ __export(rewriter_exports, {
handler: () => handler
});
module.exports = __toCommonJS(rewriter_exports);
var rewriteCookie = (header, host) => {
var rewriteCookie = (header, host2) => {
return header.split("; ").map((part) => {
if (part.startsWith("Domain=")) {
return `Domain=${host}`;
return `Domain=${host2}`;
}
return part;
}).join("; ");
};
var domains = ["example.org"];
var doCookieRewrite = true;
var doRedirectRewrite = true;
var rewriteLocationHeader = (location, host) => {
var middlewares = [];
var rewriteLocationHeader = (location, host2) => {
try {
const url = new URL(location);
if (url.hostname !== host && domains.find((domain) => url.hostname.endsWith(domain))) {
url.hostname = host;
if (url.hostname !== host2 && domains.find((domain) => url.hostname.endsWith(domain.includes("//") ? new URL(domain).hostname : domain))) {
url.hostname = host2;
}
return url.toString();
} catch (e) {
console.error(e);
}
return location;
};
var getEnv = (event2) => {
const header = event2.origin?.custom?.customHeaders["env"];
const str = header ? header[0].value : void 0;
return str ? JSON.parse(str) : {};
};
var handler = async (event) => {
const req = event.Records[0].cf.request;
const res = event.Records[0].cf.response;
Expand All @@ -59,6 +65,15 @@ var handler = async (event) => {
if (doRedirectRewrite && res.headers["location"]) {
res.headers["location"][0].value = rewriteLocationHeader(res.headers["location"][0].value, host);
}
const { domainMapping } = getEnv(req);
const mapping = domainMapping ? domainMapping[host] : {};
middlewares.forEach((middleware) => {
try {
eval(middleware)(req, res, mapping);
} catch (e) {
console.error(e);
}
});
return res;
};
// Annotate the CommonJS export names for ESM import in node:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,29 @@
}
}
},
"bac1bd7a64f3d6d01d6caa8387a57ec28f7630f9de4c2d333d11d3124e542868": {
"e568ed14759e05024fa779a0a128447c7c6adf222da22882dd3fd471ba571039": {
"source": {
"path": "asset.bac1bd7a64f3d6d01d6caa8387a57ec28f7630f9de4c2d333d11d3124e542868",
"path": "asset.e568ed14759e05024fa779a0a128447c7c6adf222da22882dd3fd471ba571039",
"packaging": "zip"
},
"destinations": {
"028446965111-us-east-1": {
"bucketName": "cdk-hnb659fds-assets-028446965111-us-east-1",
"objectKey": "bac1bd7a64f3d6d01d6caa8387a57ec28f7630f9de4c2d333d11d3124e542868.zip",
"objectKey": "e568ed14759e05024fa779a0a128447c7c6adf222da22882dd3fd471ba571039.zip",
"region": "us-east-1",
"assumeRoleArn": "arn:${AWS::Partition}:iam::028446965111:role/cdk-hnb659fds-file-publishing-role-028446965111-us-east-1"
}
}
},
"072b2ed0e5e9cb7a29399528ca25114e8054f5f84f4e0a8aa6746dc9602ae262": {
"00b81e185ce083dfa6618a62f98cfbf03ec9cad7cf0a0b6bc6f8abf2455381c9": {
"source": {
"path": "edge-api-test-stack.template.json",
"packaging": "file"
},
"destinations": {
"028446965111-us-east-1": {
"bucketName": "cdk-hnb659fds-assets-028446965111-us-east-1",
"objectKey": "072b2ed0e5e9cb7a29399528ca25114e8054f5f84f4e0a8aa6746dc9602ae262.json",
"objectKey": "00b81e185ce083dfa6618a62f98cfbf03ec9cad7cf0a0b6bc6f8abf2455381c9.json",
"region": "us-east-1",
"assumeRoleArn": "arn:${AWS::Partition}:iam::028446965111:role/cdk-hnb659fds-file-publishing-role-028446965111-us-east-1"
}
Expand Down
Loading

0 comments on commit 3813f28

Please sign in to comment.