Skip to content

Conversation

@vakalapa
Copy link
Contributor

@vakalapa vakalapa commented Dec 1, 2021

Reason for Change:

Due to wrong regex the hostip is extracted out wrong resulting in 400 badrequest from NMAgent

https://regex101.com/r/pkrHQv/1

var rgx = regexp.MustCompile("^http[s]?://(.*?)/joinedVirtualNetworks.*?$")

below is a log snippet, the host ip should be just the IP and not "168.63.129.16/machine/plugins/?comp=nmagent&type=NetworkManagement" regex is not parsing.

[Azure-CNS] Storing ncGetVersionURL for NC ID 53347415-65c7-47af-b13d-31ed8acd1272: HOST IP 168.63.129.16/machine/plugins/?comp=nmagent&type=NetworkManagement , join net url http://168.63.129.16/machine/plugins/?comp=nmagent&type=NetworkManagement/joinedVirtualNetworks/4941a21f-1a8d-4d0f-8256-cc6e73a8cd22/api-version/1, urlfmt, http://%s/machine/plugins/?comp=nmagent&type=NetworkManagement/interfaces/%s/networkContainers/%s/version/authenticationToken/%s/api-version/1 , ncGetVersionURL: http://168.63.129.16/machine/plugins/?comp=nmagent&type=NetworkManagement/machine/plugins/?comp=nmagent&type=NetworkManagement/interfaces/10.92.0.29/networkContainers/53347415-65c7-47af-b13d-31ed8acd1272/version/authenticationToken/7598a099-1292-480b-a1cd-3d6df5038578/api-version/1

Issue Fixed:

Requirements:

Notes:

Copy link
Collaborator

@rbtr rbtr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import "net/url"
...
u, err := url.Parse(urlStr)
if err != nil {
    return err
}
host := u.Host

the net package has solved parsing URLs to extract hosts, paths, queries, etc (and recomposing safe URLs from those pieces). let's lean on them 🙂

Copy link
Contributor

@ramiro-gamarra ramiro-gamarra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"The plural of regex is regrets"

@vakalapa vakalapa merged commit 83d161e into master Dec 2, 2021
@vakalapa vakalapa deleted the vakr/fixnmagenthostipregex branch December 2, 2021 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants