Verify if input endpoint URL is valid.
(endpointURL url.URL)
| 157 | |
| 158 | // Verify if input endpoint URL is valid. |
| 159 | func isValidEndpointURL(endpointURL url.URL) error { |
| 160 | if endpointURL == sentinelURL { |
| 161 | return errInvalidArgument("Endpoint url cannot be empty.") |
| 162 | } |
| 163 | if endpointURL.Path != "/" && endpointURL.Path != "" { |
| 164 | return errInvalidArgument("Endpoint url cannot have fully qualified paths.") |
| 165 | } |
| 166 | host := endpointURL.Hostname() |
| 167 | if !s3utils.IsValidIP(host) && !s3utils.IsValidDomain(host) { |
| 168 | msg := "Endpoint: " + endpointURL.Host + " does not follow ip address or domain name standards." |
| 169 | return errInvalidArgument(msg) |
| 170 | } |
| 171 | |
| 172 | if strings.Contains(host, ".s3.amazonaws.com") { |
| 173 | if !s3utils.IsAmazonEndpoint(endpointURL) { |
| 174 | return errInvalidArgument("Amazon S3 endpoint should be 's3.amazonaws.com'.") |
| 175 | } |
| 176 | } |
| 177 | if strings.Contains(host, ".googleapis.com") { |
| 178 | if !s3utils.IsGoogleEndpoint(endpointURL) { |
| 179 | return errInvalidArgument("Google Cloud Storage endpoint should be 'storage.googleapis.com'.") |
| 180 | } |
| 181 | } |
| 182 | if strings.Contains(host, "s3-outposts") { |
| 183 | if !s3utils.IsAmazonOutpostsEndpoint(endpointURL) { |
| 184 | return errInvalidArgument("S3 Outposts endpoint must match <prefix>.s3-outposts.<region>.amazonaws.com") |
| 185 | } |
| 186 | } |
| 187 | return nil |
| 188 | } |
| 189 | |
| 190 | // Verify if input expires value is valid. |
| 191 | func isValidExpiry(expires time.Duration) error { |