From ca4f98cc05af604dca71b70d4e3f8985cca77b6c Mon Sep 17 00:00:00 2001 From: Anna Khmelnitsky Date: Fri, 24 May 2024 00:59:40 +0000 Subject: [PATCH] Escape password when requesting for session token When NSX password contains certain special characters(such as &), those need to be encoded when sent to session/create API Signed-off-by: Anna Khmelnitsky --- nsxt/provider.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/nsxt/provider.go b/nsxt/provider.go index b97318655..52eac81ad 100644 --- a/nsxt/provider.go +++ b/nsxt/provider.go @@ -13,6 +13,7 @@ import ( "math/rand" "net/http" "net/http/httputil" + "net/url" "os" "regexp" "strings" @@ -554,6 +555,12 @@ func configureNsxtClient(d *schema.ResourceData, clients *nsxtClients) error { username := d.Get("username").(string) password := d.Get("password").(string) + // The correct place to escape special chars would be inside the SDK + // However since the SDK is deprecated, we implement escaping here + // TODO implement this functionality with new mp-sdk + username = url.QueryEscape(username) + password = url.QueryEscape(password) + if needCreds { if username == "" { return fmt.Errorf("username must be provided")