mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Drop leading path of KUBECTL.EXE if it shows up in User-Agent.
This commit is contained in:
parent
32600927d9
commit
4cff7c3d30
@ -109,9 +109,14 @@ func InstrumentRouteFunc(verb, resource string, routeFunc restful.RouteFunction)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func cleanUserAgent(ua string) string {
|
func cleanUserAgent(ua string) string {
|
||||||
|
// We collapse all "web browser"-type user agents into one "browser" to reduce metric cardinality.
|
||||||
if strings.HasPrefix(ua, "Mozilla/") {
|
if strings.HasPrefix(ua, "Mozilla/") {
|
||||||
return "Browser"
|
return "Browser"
|
||||||
}
|
}
|
||||||
|
// If an old "kubectl.exe" has passed us its full path, we discard the path portion.
|
||||||
|
if exeIdx := strings.LastIndex(strings.ToLower(ua), "kubectl.exe"); exeIdx != -1 {
|
||||||
|
return ua[exeIdx:]
|
||||||
|
}
|
||||||
return ua
|
return ua
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +31,14 @@ func TestCleanUserAgent(t *testing.T) {
|
|||||||
In: "kubectl/v1.2.4",
|
In: "kubectl/v1.2.4",
|
||||||
Out: "kubectl/v1.2.4",
|
Out: "kubectl/v1.2.4",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
In: `C:\Users\Kubernetes\kubectl.exe/v1.5.4`,
|
||||||
|
Out: "kubectl.exe/v1.5.4",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
In: `C:\Program Files\kubectl.exe/v1.5.4`,
|
||||||
|
Out: "kubectl.exe/v1.5.4",
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
if cleanUserAgent(tc.In) != tc.Out {
|
if cleanUserAgent(tc.In) != tc.Out {
|
||||||
t.Errorf("Failed to clean User-Agent: %s", tc.In)
|
t.Errorf("Failed to clean User-Agent: %s", tc.In)
|
||||||
|
Loading…
Reference in New Issue
Block a user