Skip to content

Commit

Permalink
hubble: rename url local variable to uri to avoid confusion with net/url
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Perrin <alex@isovalent.com>
  • Loading branch information
kaworu authored and sayboras committed Mar 5, 2024
1 parent 82006e0 commit fe76af5
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions pkg/hubble/parser/seven/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package seven

import (
"fmt"
neturl "net/url"
"net/url"
"sort"
"strings"

Expand All @@ -29,16 +29,16 @@ func decodeHTTP(flowType accesslog.FlowType, http *accesslog.LogRecordHTTP, opts
headers = append(headers, &flowpb.HTTPHeader{Key: key, Value: filteredValue})
}
}
url, _ := neturl.Parse(http.URL.String())
filterURL(url, opts.HubbleRedactSettings)
uri, _ := url.Parse(http.URL.String())
filterURL(uri, opts.HubbleRedactSettings)

if flowType == accesslog.TypeRequest {
// Set only fields that are relevant for requests.
return &flowpb.Layer7_Http{
Http: &flowpb.HTTP{
Method: http.Method,
Protocol: http.Protocol,
Url: url.String(),
Url: uri.String(),
Headers: headers,
},
}
Expand All @@ -49,16 +49,16 @@ func decodeHTTP(flowType accesslog.FlowType, http *accesslog.LogRecordHTTP, opts
Code: uint32(http.Code),
Method: http.Method,
Protocol: http.Protocol,
Url: url.String(),
Url: uri.String(),
Headers: headers,
},
}
}

func (p *Parser) httpSummary(flowType accesslog.FlowType, http *accesslog.LogRecordHTTP, flow *flowpb.Flow) string {
url, _ := neturl.Parse(http.URL.String())
filterURL(url, p.opts.HubbleRedactSettings)
httpRequest := http.Method + " " + url.String()
uri, _ := url.Parse(http.URL.String())
filterURL(uri, p.opts.HubbleRedactSettings)
httpRequest := http.Method + " " + uri.String()
switch flowType {
case accesslog.TypeRequest:
return fmt.Sprintf("%s %s", http.Protocol, httpRequest)
Expand Down Expand Up @@ -105,16 +105,16 @@ func filterHeader(key string, value string, redactSettings options.HubbleRedactS
// conditionally redacts sensitive values.
// If configured and user info exists, it removes the password from the flow.
// If configured, it removes the URL's query parts from the flow.
func filterURL(url *neturl.URL, redactSettings options.HubbleRedactSettings) {
if url != nil {
if redactSettings.RedactHTTPUserInfo && url.User != nil {
if _, ok := url.User.Password(); ok {
url.User = neturl.UserPassword(url.User.Username(), defaults.SensitiveValueRedacted)
func filterURL(uri *url.URL, redactSettings options.HubbleRedactSettings) {
if uri != nil {
if redactSettings.RedactHTTPUserInfo && uri.User != nil {
if _, ok := uri.User.Password(); ok {
uri.User = url.UserPassword(uri.User.Username(), defaults.SensitiveValueRedacted)
}
}
if redactSettings.RedactHTTPQuery {
url.RawQuery = ""
url.Fragment = ""
uri.RawQuery = ""
uri.Fragment = ""
}
}
}

0 comments on commit fe76af5

Please sign in to comment.