Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix URL validation to allow for kubernetes types #385

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/src/main/scala/besom/types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ object types:
*
* type = package ":" [ module ":" ] type name ;
* package = identifier ;
* module = identifier ;
* module = identifier ; // this actually lies a bit because it has to allow "."
* type name = identifier ;
* identifier = unicode letter { unicode letter | unicode digit | "_" } ; // this actually lies a bit because it has to allow "/"
* ```
Expand All @@ -202,7 +202,7 @@ object types:
*/

private inline val urnRegex =
"""urn:pulumi:(?<stack>[^:]+|[^:]*::[^:]*)::(?<project>[^:]+|[^:]*::[^:]*)::(?<parentType>(?:(\p{L}[\p{L}\p{N}_/]*)(?::(\p{L}[\p{L}\p{N}_/]*))?:(\p{L}[\p{L}\p{N}_/]*)(?:\$))*)(?<resourceType>(\p{L}[\p{L}\p{N}_/]*)(?::(\p{L}[\p{L}\p{N}_/]*))?:(\p{L}[\p{L}\p{N}_/]*))::(?<resourceName>[^:]+|[^:]*::[^:]*)"""
"""urn:pulumi:(?<stack>[^:]+|[^:]*::[^:]*)::(?<project>[^:]+|[^:]*::[^:]*)::(?<parentType>(?:(\p{L}[\p{L}\p{N}_/]*)(?::(\p{L}[\p{L}\p{N}_/\\.]*))?:(\p{L}[\p{L}\p{N}_/]*)(?:\$))*)(?<resourceType>(\p{L}[\p{L}\p{N}_/]*)(?::(\p{L}[\p{L}\p{N}_/\\.]*))?:(\p{L}[\p{L}\p{N}_/]*))::(?<resourceName>[^:]+|[^:]*::[^:]*)"""

private[types] val UrnRegex = urnRegex.r

Expand Down
8 changes: 8 additions & 0 deletions core/src/test/scala/besom/util/URNTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ class URNTest extends munit.FunSuite with CompileAssertions:
"urn:pulumi:stack::project::pulumi:pulumi:Stack::stack-name"
)

val kubernetesIngressUrn = URN(
"urn:pulumi:stack::project::kubernetes:networking.k8s.io/v1:Ingress::my-ingress"
)

val doubleDottedResourceTypeUrn = URN(
"urn:pulumi:stack::project::custom:resources.example.org:Resource$besom:testing.example.com/test:Resource::my-test-resource"
)

test("URN.apply should only work for correct URNs") {
failsToCompile("""
import besom.types.URN
Expand Down
Loading