UNPKG

8.78 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.makeHostedZoneArn = exports.determineFullyQualifiedDomainName = exports.validateZoneName = void 0;
4const core_1 = require("@aws-cdk/core");
5/**
6 * Validates a zone name is valid by Route53 specifc naming rules,
7 * and that there is no trailing dot in the name.
8 *
9 * @param zoneName the zone name to be validated.
10 * @returns +zoneName+
11 * @throws ValidationError if the name is not valid.
12 */
13function validateZoneName(zoneName) {
14 if (zoneName.endsWith('.')) {
15 throw new ValidationError('zone name must not end with a trailing dot');
16 }
17 if (zoneName.length > 255) {
18 throw new ValidationError('zone name cannot be more than 255 bytes long');
19 }
20 if (zoneName.split('.').find(label => label.length > 63)) {
21 throw new ValidationError('zone name labels cannot be more than 63 bytes long');
22 }
23 if (!zoneName.match(/^[a-z0-9!"#$%&'()*+,/:;<=>?@[\\\]^_`{|}~.-]+$/i)) {
24 throw new ValidationError('zone names can only contain a-z, 0-9, -, ! " # $ % & \' ( ) * + , - / : ; < = > ? @ [ \ ] ^ _ ` { | } ~ .');
25 }
26}
27exports.validateZoneName = validateZoneName;
28class ValidationError extends Error {
29 constructor(message) {
30 super(message);
31 }
32}
33/**
34 * Route53 requires the record names are specified as fully qualified names, but this
35 * forces lots of redundant work on the user (repeating the zone name over and over).
36 * This function allows the user to be lazier and offers a nicer experience, by
37 * qualifying relative names appropriately:
38 *
39 * @param providedName the user-specified name of the record.
40 * @param zoneName the fully-qualified name of the zone the record will be created in.
41 *
42 * @returns <ul>
43 * <li>If +providedName+ ends with a +.+, use it as-is</li>
44 * <li>If +providedName+ ends with or equals +zoneName+, append a trailing +.+</li>
45 * <li>Otherwise, append +.+, +zoneName+ and a trailing +.+</li>
46 * </ul>
47 */
48function determineFullyQualifiedDomainName(providedName, hostedZone) {
49 if (providedName.endsWith('.')) {
50 return providedName;
51 }
52 const hostedZoneName = hostedZone.zoneName.endsWith('.')
53 ? hostedZone.zoneName.substring(0, hostedZone.zoneName.length - 1)
54 : hostedZone.zoneName;
55 const suffix = `.${hostedZoneName}`;
56 if (providedName.endsWith(suffix) || providedName === hostedZoneName) {
57 return `${providedName}.`;
58 }
59 return `${providedName}${suffix}.`;
60}
61exports.determineFullyQualifiedDomainName = determineFullyQualifiedDomainName;
62function makeHostedZoneArn(construct, hostedZoneId) {
63 return core_1.Stack.of(construct).formatArn({
64 account: '',
65 region: '',
66 service: 'route53',
67 resource: 'hostedzone',
68 resourceName: hostedZoneId,
69 });
70}
71exports.makeHostedZoneArn = makeHostedZoneArn;
72//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInV0aWwudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEsd0NBQXNDO0FBT3RDOzs7Ozs7O0dBT0c7QUFDSCxTQUFnQixnQkFBZ0IsQ0FBQyxRQUFnQjtJQUMvQyxJQUFJLFFBQVEsQ0FBQyxRQUFRLENBQUMsR0FBRyxDQUFDLEVBQUU7UUFDMUIsTUFBTSxJQUFJLGVBQWUsQ0FBQyw0Q0FBNEMsQ0FBQyxDQUFDO0tBQ3pFO0lBQ0QsSUFBSSxRQUFRLENBQUMsTUFBTSxHQUFHLEdBQUcsRUFBRTtRQUN6QixNQUFNLElBQUksZUFBZSxDQUFDLDhDQUE4QyxDQUFDLENBQUM7S0FDM0U7SUFDRCxJQUFJLFFBQVEsQ0FBQyxLQUFLLENBQUMsR0FBRyxDQUFDLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBQyxFQUFFLENBQUMsS0FBSyxDQUFDLE1BQU0sR0FBRyxFQUFFLENBQUMsRUFBRTtRQUN4RCxNQUFNLElBQUksZUFBZSxDQUFDLG9EQUFvRCxDQUFDLENBQUM7S0FDakY7SUFDRCxJQUFJLENBQUMsUUFBUSxDQUFDLEtBQUssQ0FBQyxnREFBZ0QsQ0FBQyxFQUFFO1FBQ3J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