Skip to content

Commit 4d68292

Browse files
committed
Ruff fixes
1 parent 50760bc commit 4d68292

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

scripts/fetch_boundaries_from_api.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -488,20 +488,20 @@ def fetch_all_adm0(self) -> None:
488488
f"Updated: {self.stats['adm0_metadata_updated']}"
489489
)
490490

491-
# Fetch countries that are missing from /ALL/ endpoint but available directly
492-
# Note: Some countries (like India) are excluded from the bulk /ALL/ API response
493-
# but are still available via direct ISO code requests
494-
KNOWN_MISSING_COUNTRIES = [
491+
# Fetch countries that are missing from /ALL/ endpoint but available
492+
# directly. Some countries (like India) are excluded from the bulk /ALL/
493+
# API response but are still available via direct ISO code requests.
494+
known_missing_countries = [
495495
"IND"
496496
] # India is not in /ALL/ but available directly
497497

498-
if KNOWN_MISSING_COUNTRIES:
498+
if known_missing_countries:
499499
logger.info(
500-
f"Fetching {len(KNOWN_MISSING_COUNTRIES)} known missing countries "
500+
f"Fetching {len(known_missing_countries)} known missing countries "
501501
f"not included in /ALL/ endpoint"
502502
)
503503

504-
for iso_code in KNOWN_MISSING_COUNTRIES:
504+
for iso_code in known_missing_countries:
505505
logger.info(f"Fetching missing country: {iso_code}")
506506
try:
507507
api_data = self.api_client.get_boundary_metadata(iso_code, "ADM0")
@@ -573,16 +573,17 @@ def fetch_all_adm1(self) -> None:
573573
)
574574

575575
# Fetch ADM1 data for countries missing from /ALL/ endpoint
576-
KNOWN_MISSING_COUNTRIES = [
576+
known_missing_countries = [
577577
"IND"
578578
] # India is not in /ALL/ but available directly
579579

580-
if KNOWN_MISSING_COUNTRIES:
580+
if known_missing_countries:
581581
logger.info(
582-
f"Fetching ADM1 data for {len(KNOWN_MISSING_COUNTRIES)} known missing countries"
582+
f"Fetching ADM1 data for {len(known_missing_countries)} "
583+
"known missing countries"
583584
)
584585

585-
for iso_code in KNOWN_MISSING_COUNTRIES:
586+
for iso_code in known_missing_countries:
586587
logger.info(f"Fetching ADM1 for missing country: {iso_code}")
587588
try:
588589
self.fetch_country_adm1(iso_code)

scripts/setup/setup_ec2_instance_role.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def create_role(iam_client, account_id, region):
5959
response = iam_client.create_role(
6060
RoleName=ROLE_NAME,
6161
AssumeRolePolicyDocument=json.dumps(trust_policy),
62-
Description="Role for EC2 instances running Trends.Earth API with CodeDeploy",
62+
Description="EC2 role for Trends.Earth API with CodeDeploy",
6363
Tags=[
6464
{"Key": "Project", "Value": "TrendsEarthAPI"},
6565
{"Key": "ManagedBy", "Value": "automation"},
@@ -114,7 +114,9 @@ def attach_policies(iam_client, account_id, region):
114114
"ecr:GetDownloadUrlForLayer",
115115
"ecr:BatchGetImage",
116116
],
117-
"Resource": f"arn:aws:ecr:{region}:{account_id}:repository/trendsearth-api",
117+
"Resource": (
118+
f"arn:aws:ecr:{region}:{account_id}:repository/trendsearth-api"
119+
),
118120
},
119121
{
120122
"Sid": "S3DeploymentBucket",
@@ -134,7 +136,9 @@ def attach_policies(iam_client, account_id, region):
134136
"logs:PutLogEvents",
135137
"logs:DescribeLogStreams",
136138
],
137-
"Resource": f"arn:aws:logs:{region}:{account_id}:log-group:/aws/codedeploy/*",
139+
"Resource": (
140+
f"arn:aws:logs:{region}:{account_id}:log-group:/aws/codedeploy/*"
141+
),
138142
},
139143
],
140144
}
@@ -211,7 +215,7 @@ def main(profile=None, region=None):
211215

212216
# Create role
213217
print("\n📋 Creating IAM role...")
214-
role_arn = create_role(clients["iam"], account_id, actual_region)
218+
create_role(clients["iam"], account_id, actual_region)
215219

216220
# Attach policies
217221
print("\n📋 Attaching policies...")

scripts/setup/setup_github_oidc.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,29 +66,31 @@ def create_oidc_provider(iam_client):
6666
except ClientError as e:
6767
if e.response["Error"]["Code"] == "EntityAlreadyExists":
6868
account_id = boto3.client("sts").get_caller_identity()["Account"]
69-
arn = f"arn:aws:iam::{account_id}:oidc-provider/token.actions.githubusercontent.com"
69+
oidc_provider = "token.actions.githubusercontent.com"
70+
arn = f"arn:aws:iam::{account_id}:oidc-provider/{oidc_provider}"
7071
print(f"ℹ️ OIDC provider already exists: {arn}")
7172
return arn
7273
raise
7374

7475

7576
def create_trust_policy(account_id):
7677
"""Create the trust policy for the GitHub Actions role."""
78+
oidc_provider = "token.actions.githubusercontent.com"
7779
return {
7880
"Version": "2012-10-17",
7981
"Statement": [
8082
{
8183
"Effect": "Allow",
8284
"Principal": {
83-
"Federated": f"arn:aws:iam::{account_id}:oidc-provider/token.actions.githubusercontent.com"
85+
"Federated": (
86+
f"arn:aws:iam::{account_id}:oidc-provider/{oidc_provider}"
87+
)
8488
},
8589
"Action": "sts:AssumeRoleWithWebIdentity",
8690
"Condition": {
87-
"StringEquals": {
88-
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
89-
},
91+
"StringEquals": {f"{oidc_provider}:aud": "sts.amazonaws.com"},
9092
"StringLike": {
91-
"token.actions.githubusercontent.com:sub": f"repo:{GITHUB_ORG}/{GITHUB_REPO}:*"
93+
f"{oidc_provider}:sub": (f"repo:{GITHUB_ORG}/{GITHUB_REPO}:*")
9294
},
9395
},
9496
}

0 commit comments

Comments
 (0)