alb-sdk icon indicating copy to clipboard operation
alb-sdk copied to clipboard

Go client doesn't query escape parameters provided to Avi

Open christianang opened this issue 11 months ago • 0 comments

Describe the bug

The go client does not query escape parameters provided to it. I've tested this with Avi 30.1.1, which results in a HTTP 400 error.

Error I see:

2024/03/01 22:07:12 Encountered an error on GET request to URL https://<avi-ip>/api/network?name=VM Network: HTTP code: 400; error from Controller: <nil>

Reproduction steps

Here is a minimal example of the issue. Notably this doesn't work with Avi 30.1.1, but it did work with previous versions, so there was probably a change introduced in 30.1.1.

package main

import (
	"log"
	"os"

	"github.com/vmware/alb-sdk/go/clients"
	"github.com/vmware/alb-sdk/go/session"
)

func main() {
	aviURL := os.Args[1]
	aviUsername := os.Args[2]
	aviPassword := os.Args[3]

	aviClient, err := clients.NewAviClient(aviURL, aviUsername,
		session.SetPassword(aviPassword),
		session.SetTenant("admin"),
		session.SetInsecure)
	if err != nil {
		log.Fatalln(err)
	}

	// Works
	_, err = aviClient.Network.GetByName("VM+Network")
	if err != nil {
		log.Fatalln(err)
	}

	// Doesn't work
	_, err = aviClient.Network.GetByName("VM Network")
	if err != nil {
		log.Fatalln(err)
	}
}

Run by

go run main.go <avi-url> <username> <password>

Expected behavior

I expect the client library to query escape the parameters I provide to it, to create a well-formed url that can be used to make REST requests to the Avi API. For example, in my example providing VM Network to the aviClient.Network.GetByName function should result in a path param that looks like ?name=VM+Network instead of ?name=VM Network.

Additional context

No response

christianang avatar Mar 01 '24 22:03 christianang