Skip to content

Commit b17dbcb

Browse files
joaopeDanielMSchmidt
authored andcommitted
replace is-valid-domain by validator.isFQDN
1 parent 54d5252 commit b17dbcb

File tree

4 files changed

+40
-11
lines changed

4 files changed

+40
-11
lines changed

packages/@cdktf/commons/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,16 @@
4444
"cross-spawn": "7.0.6",
4545
"follow-redirects": "1.15.9",
4646
"fs-extra": "11.2.0",
47-
"is-valid-domain": "0.1.6",
4847
"log4js": "6.9.1",
4948
"strip-ansi": "6.0.1",
50-
"uuid": "9.0.1"
49+
"uuid": "9.0.1",
50+
"validator": "13.12.0"
5151
},
5252
"devDependencies": {
5353
"@types/follow-redirects": "1.14.4",
5454
"@types/fs-extra": "11.0.4",
5555
"@types/uuid": "9.0.8",
56+
"@types/validator": "13.12.2",
5657
"@typescript-eslint/eslint-plugin": "4.33.0",
5758
"@typescript-eslint/parser": "4.33.0",
5859
"eslint-config-prettier": "8.10.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { isRegistryModule } from "./terraform-module";
2+
3+
describe("terraform-module", () => {
4+
describe.each`
5+
source | expected
6+
${"hashicorp/consul/aws"} | ${true}
7+
${"hashicorp/consul/aws//foo"} | ${false}
8+
${"./consul"} | ${false}
9+
${"[email protected]:hashicorp/example.git"} | ${false}
10+
${"github.com/hashicorp/example"} | ${false}
11+
${"github.com/hashicorp/terraform-cidr-subnets"} | ${false}
12+
${"bitbucket.org/hashicorp/terraform-consul-aws"} | ${false}
13+
${"foo/var/baz/qux"} | ${false}
14+
${"foo.com/var/baz"} | ${true}
15+
${".foo.com/var/baz"} | ${false}
16+
${"f-o-o.com/var/baz"} | ${true}
17+
${"foo.com/var/baz/canz"} | ${true}
18+
${"example.com/awesomecorp/network/happycloud//examples/foo"} | ${false}
19+
${"www.googleapis.com/storage/v1/BUCKET_NAME/PATH_TO_MODULE"} | ${false}
20+
`("isRegistryModule($source)", ({ source, expected }) => {
21+
it(`expects ${expected}`, () => {
22+
expect(isRegistryModule(source)).toBe(expected);
23+
});
24+
});
25+
});

packages/@cdktf/commons/src/terraform-module.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright (c) HashiCorp, Inc
22
// SPDX-License-Identifier: MPL-2.0
3-
import isValidDomain from "is-valid-domain";
3+
import { isFQDN } from "validator";
44

55
// Logic from https://github.com/hashicorp/terraform/blob/e09b831f6ee35d37b11b8dcccd3a6d6f6db5e5ff/internal/addrs/module_source.go#L198
66
export function isRegistryModule(source: string) {
@@ -15,7 +15,7 @@ export function isRegistryModule(source: string) {
1515
return false;
1616
}
1717

18-
if (parts.length === 4 && !isValidDomain(parts[0])) {
18+
if (parts.length === 4 && !isFQDN(parts[0])) {
1919
return false;
2020
}
2121

yarn.lock

+10-7
Original file line numberDiff line numberDiff line change
@@ -2405,6 +2405,11 @@
24052405
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-9.0.8.tgz#7545ba4fc3c003d6c756f651f3bf163d8f0f29ba"
24062406
integrity sha512-jg+97EGIcY9AGHJJRaaPVgetKDsrTgbRjQ5Msgjh/DQKEFl0DtyRr/VCOyD1T2R1MNeWPK/u7JoGhlDZnKBAfA==
24072407

2408+
2409+
version "13.12.2"
2410+
resolved "https://registry.yarnpkg.com/@types/validator/-/validator-13.12.2.tgz#760329e756e18a4aab82fc502b51ebdfebbe49f5"
2411+
integrity sha512-6SlHBzUW8Jhf3liqrGGXyTJSIFe4nqlJ5A5KaMZ2l/vbM3Wh3KSybots/wfWVzNLK4D1NZluDlSQIbIEPx6oyA==
2412+
24082413
"@types/wrap-ansi@^3.0.0":
24092414
version "3.0.0"
24102415
resolved "https://registry.yarnpkg.com/@types/wrap-ansi/-/wrap-ansi-3.0.0.tgz#18b97a972f94f60a679fd5c796d96421b9abb9fd"
@@ -6930,13 +6935,6 @@ is-upper-case@^2.0.2:
69306935
dependencies:
69316936
tslib "^2.0.3"
69326937

6933-
6934-
version "0.1.6"
6935-
resolved "https://registry.yarnpkg.com/is-valid-domain/-/is-valid-domain-0.1.6.tgz#3c85469d2938f170c8f82ce6e52df8ad9fca8105"
6936-
integrity sha512-ZKtq737eFkZr71At8NxOFcP9O1K89gW3DkdrGMpp1upr/ueWjj+Weh4l9AI4rN0Gt8W2M1w7jrG2b/Yv83Ljpg==
6937-
dependencies:
6938-
punycode "^2.1.1"
6939-
69406938
is-weakmap@^2.0.2:
69416939
version "2.0.2"
69426940
resolved "https://registry.yarnpkg.com/is-weakmap/-/is-weakmap-2.0.2.tgz#bf72615d649dfe5f699079c54b83e47d1ae19cfd"
@@ -12230,6 +12228,11 @@ validate-npm-package-name@^5.0.0:
1223012228
dependencies:
1223112229
builtins "^5.0.0"
1223212230

12231+
12232+
version "13.12.0"
12233+
resolved "https://registry.yarnpkg.com/validator/-/validator-13.12.0.tgz#7d78e76ba85504da3fee4fd1922b385914d4b35f"
12234+
integrity sha512-c1Q0mCiPlgdTVVVIJIrBuxNicYE+t/7oKeI9MWLj3fh/uq2Pxh/3eeWbVZ4OcGW1TUf53At0njHw5SMdA3tmMg==
12235+
1223312236
w3c-hr-time@^1.0.2:
1223412237
version "1.0.2"
1223512238
resolved "https://registry.yarnpkg.com/w3c-hr-time/-/w3c-hr-time-1.0.2.tgz#0a89cdf5cc15822df9c360543676963e0cc308cd"

0 commit comments

Comments
 (0)