From 9535183c6ac5343833e4c5e72931ee95fbb1f3ee Mon Sep 17 00:00:00 2001 From: Balazs Czoma Date: Fri, 1 Mar 2024 16:11:53 -0500 Subject: [PATCH] Fix support for IPv6 address and port --- README.md | 2 +- ci/module-test/main.tf | 5 +++-- ci/template-test/main.tf | 2 +- internal/gen-template/main.tf | 3 ++- main.tf | 3 ++- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9c69df2..e8f0779 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Adding extra OAuth JWT claims to the REST consumer is not supported in the curre * `msg_vpn_name` - REST delivery points are specific to a Message VPN on the broker. * `rest_delivery_point_name` - The name of the REST delivery point to be created. -* `url` - The REST consumer destination URL including base URL and endpoint path. The path portion of the URL may contain [substitution expressions](https://docs.solace.com/Messaging/Substitution-Expressions-Overview.htm). +* `url` - The REST consumer destination URL including base URL and endpoint path. The path portion of the URL may contain [substitution expressions](https://docs.solace.com/Messaging/Substitution-Expressions-Overview.htm). To specify an IPv6 address with port, the required format is the address to be [enclosed in square brackets](https://www.rfc-editor.org/rfc/rfc3986.html#section-3.2.2). * `queue_name` - The name of the queue to bind to. Important: The REST delivery point must have permission to consume messages from the queue — to achieve this, the queue’s owner must be set to `#rdp/` or the queue’s permissions for non-owner clients must be set to at least `consume` level access. Queue ingress and egress must also be enabled. diff --git a/ci/module-test/main.tf b/ci/module-test/main.tf index ca79764..18fd4d3 100644 --- a/ci/module-test/main.tf +++ b/ci/module-test/main.tf @@ -15,9 +15,10 @@ module "testrdp" { msg_vpn_name = "default" queue_name = solacebroker_msg_vpn_queue.myqueue.queue_name - url = "http://example.com/$${msgId()}" + url = "https://example.com" rest_delivery_point_name = "my_rdp" enabled = false + client_profile_name = "default" request_headers = [ { header_name = "header1" @@ -67,7 +68,7 @@ module "testrdp2" { msg_vpn_name = "default" queue_name = solacebroker_msg_vpn_queue.myqueue.queue_name - url = "http://example.com/$${msgId()}" + url = "http://[2001:db8:3333:4444:5555:6666:7777:8888]:12345/$${msgId()}" rest_delivery_point_name = "my_rdp2" request_headers = module.testrdp.request_headers protected_request_headers = module.testrdp.protected_request_headers diff --git a/ci/template-test/main.tf b/ci/template-test/main.tf index 015b18c..ebe1dc0 100644 --- a/ci/template-test/main.tf +++ b/ci/template-test/main.tf @@ -67,7 +67,7 @@ module "testrdp2" { msg_vpn_name = "default" queue_name = solacebroker_msg_vpn_queue.myqueue.queue_name - url = "http://example.com/$${msgId()}" + url = "http://[2001:db8:3333:4444:5555:6666:7777:8888]:12345/$${msgId()}" rest_delivery_point_name = "my_rdp2" request_headers = module.testrdp.request_headers protected_request_headers = module.testrdp.protected_request_headers diff --git a/internal/gen-template/main.tf b/internal/gen-template/main.tf index d87a505..59a37a1 100644 --- a/internal/gen-template/main.tf +++ b/internal/gen-template/main.tf @@ -1,7 +1,8 @@ locals { tls = startswith(lower(var.url), "https:") slashSplit = split("/", var.url) - hostPortSplit = split(":", local.slashSplit[2]) + isIpV6HostPort = length(split("]", local.slashSplit[2])) == 2 + hostPortSplit = local.isIpV6HostPort ? split("]:", trimprefix(local.slashSplit[2], "[")) : split(":", local.slashSplit[2]) host = local.hostPortSplit[0] port = length(local.hostPortSplit) == 2 ? tonumber(local.hostPortSplit[1]) : (local.tls ? 443 : 80) path = "/${join("/", slice(local.slashSplit, 3, length(local.slashSplit)))}" diff --git a/main.tf b/main.tf index a1a846e..dcda027 100644 --- a/main.tf +++ b/main.tf @@ -15,7 +15,8 @@ locals { tls = startswith(lower(var.url), "https:") slashSplit = split("/", var.url) - hostPortSplit = split(":", local.slashSplit[2]) + isIpV6HostPort = length(split("]", local.slashSplit[2])) == 2 + hostPortSplit = local.isIpV6HostPort ? split("]:", trimprefix(local.slashSplit[2], "[")) : split(":", local.slashSplit[2]) host = local.hostPortSplit[0] port = length(local.hostPortSplit) == 2 ? tonumber(local.hostPortSplit[1]) : (local.tls ? 443 : 80) path = "/${join("/", slice(local.slashSplit, 3, length(local.slashSplit)))}"