diff --git a/pkg/s3utils/utils.go b/pkg/s3utils/utils.go index 056e78a67a..de66fb118f 100644 --- a/pkg/s3utils/utils.go +++ b/pkg/s3utils/utils.go @@ -31,6 +31,7 @@ import ( // Sentinel URL is the default url value which is invalid. var sentinelURL = url.URL{} +var host string // IsValidDomain validates if input string is a valid domain name. func IsValidDomain(host string) bool { @@ -223,10 +224,11 @@ func IsAmazonPrivateLinkEndpoint(endpointURL url.URL) bool { // IsGoogleEndpoint - Match if it is exactly Google cloud storage endpoint. func IsGoogleEndpoint(endpointURL url.URL) bool { + host := HasPortNumber(endpointURL) if endpointURL == sentinelURL { return false } - return endpointURL.Host == "storage.googleapis.com" + return host == "storage.googleapis.com" } // Expects ascii encoded strings - from output of urlEncodePath @@ -409,3 +411,13 @@ func CheckValidObjectName(objectName string) error { } return CheckValidObjectNamePrefix(objectName) } + +//checks for port number +func HasPortNumber(endpointURL url.URL) string { + if colonIndex := strings.LastIndex(endpointURL.Host, ":"); colonIndex != -1 { + host = endpointURL.Host[:colonIndex] + } else { + host = endpointURL.Host + } + return host +} diff --git a/pkg/s3utils/utils_test.go b/pkg/s3utils/utils_test.go index f99738ba9a..9d545f4b9e 100644 --- a/pkg/s3utils/utils_test.go +++ b/pkg/s3utils/utils_test.go @@ -284,6 +284,8 @@ func TestIsGoogleEndpoint(t *testing.T) { // valid inputs. {"http://storage.googleapis.com", true}, {"https://storage.googleapis.com", true}, + {"http://storage.googleapis.com:80", true}, + {"https://storage.googleapis.com:443", true}, } for i, testCase := range testCases {