in ext.py [0:0]
def ext_valid_bucket_regions(value, rule_obj, path):
# Validate required fields in resources
if not isinstance(value, dict):
print("Did not receives a resources dictionary...")
return False
if "Type" not in value:
print("Type is a required resources field")
return False
if "Description" not in value:
print("Description is a required resources field")
return False
if "Region" not in value:
print("Region is a required resources field")
return False
if "Explore" in value and not isinstance(value["Explore"], list):
print("Explore must be an array of links")
return False
# Make sure this is a dict, and a bucket, then validate the region
if value["Type"] == "S3 Bucket":
bucket = value["ARN"]
parts = bucket.split(":::")
if not parts[0] == "arn:aws:s3":
# This is probably not on public aws so we can't check
return True
bucket = parts[1]
parts = bucket.split("/")
bucket = parts[0]
url = "https://{}.s3.amazonaws.com".format(bucket)
region = get_bucket_region(url)
if region is None:
print("The bucket {} does not exist".format(bucket))
return False
if not value["Region"].lower() == region.lower():
print(
"The region for bucket {} is listed as {} but is actually {}".format(
bucket, value["Region"], region
)
)
return False
return True