Skip to content

Commit

Permalink
replace is-valid-domain by validator.isFQDN
Browse files Browse the repository at this point in the history
  • Loading branch information
joaope committed Dec 13, 2024
1 parent c297b4f commit 4b3fb9e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
5 changes: 3 additions & 2 deletions packages/@cdktf/commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@
"cross-spawn": "7.0.6",
"follow-redirects": "1.15.9",
"fs-extra": "11.2.0",
"is-valid-domain": "0.1.6",
"log4js": "6.9.1",
"strip-ansi": "6.0.1",
"uuid": "9.0.1"
"uuid": "9.0.1",
"validator": "13.12.0"
},
"devDependencies": {
"@types/follow-redirects": "1.14.4",
"@types/fs-extra": "11.0.4",
"@types/uuid": "9.0.8",
"@types/validator": "13.12.2",
"@typescript-eslint/eslint-plugin": "4.33.0",
"@typescript-eslint/parser": "4.33.0",
"eslint-config-prettier": "8.10.0",
Expand Down
25 changes: 25 additions & 0 deletions packages/@cdktf/commons/src/terraform-module.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { isRegistryModule } from "./terraform-module";

describe("terraform-module", () => {
describe.each`
source | expected
${"hashicorp/consul/aws"} | ${true}
${"hashicorp/consul/aws//foo"} | ${false}
${"./consul"} | ${false}
${"[email protected]:hashicorp/example.git"} | ${false}
${"github.com/hashicorp/example"} | ${false}
${"github.com/hashicorp/terraform-cidr-subnets"} | ${false}
${"bitbucket.org/hashicorp/terraform-consul-aws"} | ${false}
${"foo/var/baz/qux"} | ${false}
${"foo.com/var/baz"} | ${true}
${".foo.com/var/baz"} | ${false}
${"f-o-o.com/var/baz"} | ${true}
${"foo.com/var/baz/canz"} | ${true}
${"example.com/awesomecorp/network/happycloud//examples/foo"} | ${false}
${"www.googleapis.com/storage/v1/BUCKET_NAME/PATH_TO_MODULE"} | ${false}
`("isRegistryModule($source)", ({ source, expected }) => {
it(`expects ${expected}`, () => {
expect(isRegistryModule(source)).toBe(expected);
});
});
});
4 changes: 2 additions & 2 deletions packages/@cdktf/commons/src/terraform-module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) HashiCorp, Inc
// SPDX-License-Identifier: MPL-2.0
import isValidDomain from "is-valid-domain";
import { isFQDN } from "validator";

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

if (parts.length === 4 && !isValidDomain(parts[0])) {
if (parts.length === 4 && !isFQDN(parts[0])) {
return false;
}

Expand Down
17 changes: 10 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2405,6 +2405,11 @@
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-9.0.8.tgz#7545ba4fc3c003d6c756f651f3bf163d8f0f29ba"
integrity sha512-jg+97EGIcY9AGHJJRaaPVgetKDsrTgbRjQ5Msgjh/DQKEFl0DtyRr/VCOyD1T2R1MNeWPK/u7JoGhlDZnKBAfA==

"@types/[email protected]":
version "13.12.2"
resolved "https://registry.yarnpkg.com/@types/validator/-/validator-13.12.2.tgz#760329e756e18a4aab82fc502b51ebdfebbe49f5"
integrity sha512-6SlHBzUW8Jhf3liqrGGXyTJSIFe4nqlJ5A5KaMZ2l/vbM3Wh3KSybots/wfWVzNLK4D1NZluDlSQIbIEPx6oyA==

"@types/wrap-ansi@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/wrap-ansi/-/wrap-ansi-3.0.0.tgz#18b97a972f94f60a679fd5c796d96421b9abb9fd"
Expand Down Expand Up @@ -6930,13 +6935,6 @@ is-upper-case@^2.0.2:
dependencies:
tslib "^2.0.3"

[email protected]:
version "0.1.6"
resolved "https://registry.yarnpkg.com/is-valid-domain/-/is-valid-domain-0.1.6.tgz#3c85469d2938f170c8f82ce6e52df8ad9fca8105"
integrity sha512-ZKtq737eFkZr71At8NxOFcP9O1K89gW3DkdrGMpp1upr/ueWjj+Weh4l9AI4rN0Gt8W2M1w7jrG2b/Yv83Ljpg==
dependencies:
punycode "^2.1.1"

is-weakmap@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/is-weakmap/-/is-weakmap-2.0.2.tgz#bf72615d649dfe5f699079c54b83e47d1ae19cfd"
Expand Down Expand Up @@ -12230,6 +12228,11 @@ validate-npm-package-name@^5.0.0:
dependencies:
builtins "^5.0.0"

[email protected]:
version "13.12.0"
resolved "https://registry.yarnpkg.com/validator/-/validator-13.12.0.tgz#7d78e76ba85504da3fee4fd1922b385914d4b35f"
integrity sha512-c1Q0mCiPlgdTVVVIJIrBuxNicYE+t/7oKeI9MWLj3fh/uq2Pxh/3eeWbVZ4OcGW1TUf53At0njHw5SMdA3tmMg==

w3c-hr-time@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/w3c-hr-time/-/w3c-hr-time-1.0.2.tgz#0a89cdf5cc15822df9c360543676963e0cc308cd"
Expand Down

0 comments on commit 4b3fb9e

Please sign in to comment.