Skip to content

Commit efce93e

Browse files
PDM-892 mypy fixes and setup-java action update
1 parent e8c0b72 commit efce93e

File tree

5 files changed

+25
-18
lines changed

5 files changed

+25
-18
lines changed

.gitallowed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
token: \$\{\{ secrets.GITHUB_TOKEN \}\}
3-
"token": response.get\("SessionToken"\)
3+
"token": response\["SessionToken"\]
44
token=credentials\["token"\]
55

66
.*(GITHUB|SONAR)_TOKEN: \$\{\{ secrets.(GITHUB|SONAR)_TOKEN \}\}

.github/workflows/merge-develop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858

5959
- name: setup java
6060
if: github.actor != 'dependabot[bot]' && (success() || failure())
61-
uses: actions/setup-java@v4
61+
uses: actions/setup-java@v5
6262
with:
6363
distribution: "corretto"
6464
java-version: "17"

.github/workflows/pull-request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ jobs:
145145

146146
- name: setup java
147147
if: success() || failure()
148-
uses: actions/setup-java@v4
148+
uses: actions/setup-java@v5
149149
with:
150150
distribution: "corretto"
151151
java-version: "17"

nhs_aws_helpers/__init__.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
from mypy_boto3_ssm.client import SSMClient
7676
from mypy_boto3_stepfunctions import SFNClient
7777
from mypy_boto3_sts.client import STSClient
78+
from mypy_boto3_sts.type_defs import AssumeRoleRequestTypeDef
7879

7980
from nhs_aws_helpers.common import run_in_executor
8081
from nhs_aws_helpers.s3_object_writer import S3ObjectWriter
@@ -1056,19 +1057,19 @@ def assumed_credentials(
10561057

10571058
sts_client = boto3.client("sts", region_name=region, endpoint_url=endpoint_url)
10581059

1059-
params = {
1060-
"RoleArn": f"arn:aws:iam::{account_id}:role/{role}",
1061-
"RoleSessionName": role_session_name,
1062-
"DurationSeconds": duration_seconds,
1063-
}
1060+
params = AssumeRoleRequestTypeDef(
1061+
RoleArn=f"arn:aws:iam::{account_id}:role/{role}",
1062+
RoleSessionName=role_session_name,
1063+
DurationSeconds=duration_seconds,
1064+
)
10641065

1065-
response = sts_client.assume_role(**params).get("Credentials")
1066+
response = sts_client.assume_role(**params)["Credentials"]
10661067

10671068
credentials = {
1068-
"access_key": response.get("AccessKeyId"),
1069-
"secret_key": response.get("SecretAccessKey"),
1070-
"token": response.get("SessionToken"),
1071-
"expiry_time": response.get("Expiration").isoformat(),
1069+
"access_key": response["AccessKeyId"],
1070+
"secret_key": response["SecretAccessKey"],
1071+
"token": response["SessionToken"],
1072+
"expiry_time": response["Expiration"].isoformat(),
10721073
}
10731074
return credentials
10741075

tests/aws_tests.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22
import os
3-
from typing import Any, cast
3+
from typing import Any, Literal, TypedDict, cast
44
from uuid import uuid4
55

66
import pytest
@@ -247,14 +247,20 @@ def test_s3_retries(
247247
key = f"{expected_folder}/filename.txt"
248248
httpserver.expect_request(f"/{temp_s3_bucket.name}/{key}").respond_with_json({}, status=503)
249249

250+
# Type-identical spec to match botocore's internal typing of _RetryDict
251+
class BotocoreRetries(TypedDict, total=False):
252+
total_max_attempts: int
253+
max_attempts: int
254+
mode: Literal["legacy", "standard", "adaptive"]
255+
250256
config = Config(
251257
connect_timeout=float(os.environ.get("BOTO_CONNECT_TIMEOUT", "1")),
252258
read_timeout=float(os.environ.get("BOTO_READ_TIMEOUT", "1")),
253259
max_pool_connections=int(os.environ.get("BOTO_MAX_POOL_CONNECTIONS", "10")),
254-
retries={
255-
"mode": os.environ.get("BOTO_RETRIES_MODE", "standard"), # type: ignore[typeddict-item]
256-
"total_max_attempts": int(os.environ.get("BOTO_RETRIES_TOTAL_MAX_ATTEMPTS", "2")),
257-
},
260+
retries=BotocoreRetries(
261+
mode=os.environ.get("BOTO_RETRIES_MODE", "standard"), # type: ignore[typeddict-item]
262+
total_max_attempts=int(os.environ.get("BOTO_RETRIES_TOTAL_MAX_ATTEMPTS", "2")),
263+
),
258264
)
259265

260266
def _post_create_aws(boto_module: str, _: str, client):

0 commit comments

Comments
 (0)