Merge pull request #3088 from thaJeztah/2.7_backport_fix_cloudfront_middleware

[release/2.7 backport] Bugfix: Make ipfilteredby not required
This commit is contained in:
Derek McGowan 2020-02-23 00:07:58 -08:00 committed by GitHub
commit bdf503a444
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -138,15 +138,17 @@ func newCloudFrontStorageMiddleware(storageDriver storagedriver.StorageDriver, o
// parse ipfilteredby // parse ipfilteredby
var awsIPs *awsIPs var awsIPs *awsIPs
if ipFilteredBy := options["ipfilteredby"].(string); ok { if i, ok := options["ipfilteredby"]; ok {
if ipFilteredBy, ok := i.(string); ok {
switch strings.ToLower(strings.TrimSpace(ipFilteredBy)) { switch strings.ToLower(strings.TrimSpace(ipFilteredBy)) {
case "", "none": case "", "none":
awsIPs = nil awsIPs = nil
case "aws": case "aws":
newAWSIPs(ipRangesURL, updateFrequency, nil) awsIPs = newAWSIPs(ipRangesURL, updateFrequency, nil)
case "awsregion": case "awsregion":
var awsRegion []string var awsRegion []string
if regions, ok := options["awsregion"].(string); ok { if i, ok := options["awsregion"]; ok {
if regions, ok := i.(string); ok {
for _, awsRegions := range strings.Split(regions, ",") { for _, awsRegions := range strings.Split(regions, ",") {
awsRegion = append(awsRegion, strings.ToLower(strings.TrimSpace(awsRegions))) awsRegion = append(awsRegion, strings.ToLower(strings.TrimSpace(awsRegions)))
} }
@ -154,12 +156,16 @@ func newCloudFrontStorageMiddleware(storageDriver storagedriver.StorageDriver, o
} else { } else {
return nil, fmt.Errorf("awsRegion must be a comma separated string of valid aws regions") return nil, fmt.Errorf("awsRegion must be a comma separated string of valid aws regions")
} }
} else {
return nil, fmt.Errorf("awsRegion is not defined")
}
default: default:
return nil, fmt.Errorf("ipfilteredby only allows a string the following value: none|aws|awsregion") return nil, fmt.Errorf("ipfilteredby only allows a string the following value: none|aws|awsregion")
} }
} else { } else {
return nil, fmt.Errorf("ipfilteredby only allows a string with the following value: none|aws|awsregion") return nil, fmt.Errorf("ipfilteredby only allows a string with the following value: none|aws|awsregion")
} }
}
return &cloudFrontStorageMiddleware{ return &cloudFrontStorageMiddleware{
StorageDriver: storageDriver, StorageDriver: storageDriver,