vmware / vmware/alb-sdk

Go client doesn't query escape parameters provided to Avi

Open
#2,902 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Java
Stars
76
Forks
69
Avg merge
1d 1h
Merged PRs (30d)
60

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Go client's Network.GetByName entry point and trace how its name parameter becomes the REST request URL. Reproduce the difference between "VM+Network" and "VM Network" against the Avi API, then verify that the latter is query-escaped and produces a successful request.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.