Run black on moto & test directories.

This commit is contained in:
Asher Foa 2019-10-31 08:44:26 -07:00
commit 96e5b1993d
507 changed files with 52541 additions and 47814 deletions

View file

@ -6,8 +6,15 @@ from moto.s3 import s3_backends
class S3ConfigQuery(ConfigQueryModel):
def list_config_service_resources(self, resource_ids, resource_name, limit, next_token, backend_region=None, resource_region=None):
def list_config_service_resources(
self,
resource_ids,
resource_name,
limit,
next_token,
backend_region=None,
resource_region=None,
):
# The resource_region only matters for aggregated queries as you can filter on bucket regions for them.
# For other resource types, you would need to iterate appropriately for the backend_region.
@ -20,14 +27,14 @@ class S3ConfigQuery(ConfigQueryModel):
# If no filter was passed in for resource names/ids then return them all:
if not resource_ids and not resource_name:
bucket_list = list(self.backends['global'].buckets.keys())
bucket_list = list(self.backends["global"].buckets.keys())
else:
# Match the resource name / ID:
bucket_list = []
filter_buckets = [resource_name] if resource_name else resource_ids
for bucket in self.backends['global'].buckets.keys():
for bucket in self.backends["global"].buckets.keys():
if bucket in filter_buckets:
bucket_list.append(bucket)
@ -37,7 +44,7 @@ class S3ConfigQuery(ConfigQueryModel):
region_buckets = []
for bucket in bucket_list:
if self.backends['global'].buckets[bucket].region_name == region_filter:
if self.backends["global"].buckets[bucket].region_name == region_filter:
region_buckets.append(bucket)
bucket_list = region_buckets
@ -61,17 +68,29 @@ class S3ConfigQuery(ConfigQueryModel):
start = sorted_buckets.index(next_token)
# Get the list of items to collect:
bucket_list = sorted_buckets[start:(start + limit)]
bucket_list = sorted_buckets[start : (start + limit)]
if len(sorted_buckets) > (start + limit):
new_token = sorted_buckets[start + limit]
return [{'type': 'AWS::S3::Bucket', 'id': bucket, 'name': bucket, 'region': self.backends['global'].buckets[bucket].region_name}
for bucket in bucket_list], new_token
return (
[
{
"type": "AWS::S3::Bucket",
"id": bucket,
"name": bucket,
"region": self.backends["global"].buckets[bucket].region_name,
}
for bucket in bucket_list
],
new_token,
)
def get_config_resource(self, resource_id, resource_name=None, backend_region=None, resource_region=None):
def get_config_resource(
self, resource_id, resource_name=None, backend_region=None, resource_region=None
):
# Get the bucket:
bucket = self.backends['global'].buckets.get(resource_id, {})
bucket = self.backends["global"].buckets.get(resource_id, {})
if not bucket:
return
@ -89,12 +108,12 @@ class S3ConfigQuery(ConfigQueryModel):
config_data = bucket.to_config_dict()
# The 'configuration' field is also a JSON string:
config_data['configuration'] = json.dumps(config_data['configuration'])
config_data["configuration"] = json.dumps(config_data["configuration"])
# Supplementary config need all values converted to JSON strings if they are not strings already:
for field, value in config_data['supplementaryConfiguration'].items():
for field, value in config_data["supplementaryConfiguration"].items():
if not isinstance(value, str):
config_data['supplementaryConfiguration'][field] = json.dumps(value)
config_data["supplementaryConfiguration"][field] = json.dumps(value)
return config_data