Skip to content

Commit

Permalink
Fix URL validation to allow for kubernetes types
Browse files Browse the repository at this point in the history
- allow for a dot in the URN's module part
  • Loading branch information
pawelprazak committed Feb 10, 2024
1 parent 5a08f0b commit 4e900bd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
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 @@ -183,7 +183,7 @@ object types:
* package = identifier ;
* module = identifier ;
* type name = identifier ;
* identifier = unicode letter { unicode letter | unicode digit | "_" } ; // this actually lies a bit because it has to allow "/"
* identifier = unicode letter { unicode letter | unicode digit | "_" } ; // this actually lies a bit because it has to allow "/" and "."
* ```
*
* So let's start with the easy part, the first part of the regex is just a constant string: `urn:pulumi:`. Then we have these
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
4 changes: 4 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,10 @@ 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"
)

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

0 comments on commit 4e900bd

Please sign in to comment.