Skip to content

Commit 23c3257

Browse files
authored
Merge pull request #38 from PostHog/tom/fix-wrong-param-name
Fix type error
2 parents 7d223cb + dd7c67a commit 23c3257

20 files changed

Lines changed: 76 additions & 42 deletions

CLAUDE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
Always run these commands before committing changes:
66

77
```bash
8+
# Run type checking
9+
cd src && uv run pyright .
10+
11+
# Run tests
12+
cd src && uv run pytest -q
13+
814
# Run all pre-commit hooks (linting, formatting, terraform docs, etc.)
915
uv run --directory src --extra dev pre-commit run --all-files
1016
```

run-tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set -e
55
cd src
66
uv sync --no-install-project --extra dev
77
LOG_LEVEL=DEBUG uv run pytest -q $1
8+
uv run pyright .
89
cd ..
910

1011
uvx pre-commit run -a

src/analytics.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@
2424
from typing import TYPE_CHECKING
2525

2626
if TYPE_CHECKING:
27-
import posthog as posthog_module
27+
import types
28+
2829

2930
APPLICATION = "aws-sso-elevator"
3031
logger = logging.getLogger(__name__)
3132

3233

3334
@lru_cache(maxsize=1)
34-
def get_posthog_client() -> posthog_module | None:
35+
def get_posthog_client() -> types.ModuleType | None:
3536
"""Get configured PostHog client, or None if not configured.
3637
3738
Returns cached client instance. The client is configured on first call

src/cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def set_cached_permission_sets(
292292
logger.warning(f"Failed to cache permission sets: {e}", extra={"error": str(e)})
293293

294294

295-
def _compute_data_hash(data: T) -> str:
295+
def _compute_data_hash(data: object) -> str:
296296
"""Compute SHA256 hash of data for comparison.
297297
298298
Args:
@@ -303,7 +303,7 @@ def _compute_data_hash(data: T) -> str:
303303
"""
304304
try:
305305
# Convert to JSON string with sorted keys for consistent hashing
306-
json_str = json.dumps([item.dict() if hasattr(item, "dict") else item for item in data], sort_keys=True)
306+
json_str = json.dumps([item.dict() if hasattr(item, "dict") else item for item in data], sort_keys=True) # pyright: ignore[reportGeneralTypeIssues]
307307
return hashlib.sha256(json_str.encode("utf-8")).hexdigest()
308308
except Exception as e:
309309
logger.warning(f"Failed to compute hash: {e}")

src/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,4 +268,5 @@ def check_and_refresh_config(s3_client: S3Client) -> Config:
268268
except Exception as e:
269269
logger.warning(f"Failed to check config freshness: {e}")
270270

271+
assert _config is not None
271272
return _config

src/entities/model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ class BaseModel(PydanticBaseModel):
3030
def dict(self, *args, **kwargs) -> dict: # noqa: ANN101, ANN003, ANN002, ARG002
3131
"""Converts instance to dict representation of it. Workaround for https://github.com/pydantic/pydantic/issues/1090"""
3232
# Manually convert to avoid Pydantic serialization issues with frozensets of frozen models
33-
return _convert_to_serializable(self)
33+
return _convert_to_serializable(self) # type: ignore[return-value]
3434

3535
def json(self, *args, **kwargs) -> str: # noqa: ANN101, ANN003, ANN002
3636
"""Converts instance to JSON string. Compatibility wrapper for Pydantic v2."""
3737
# In Pydantic v2, use model_dump_json instead
3838
return self.model_dump_json(*args, **kwargs)
3939

4040

41-
def json_default(o: object) -> str | dict:
41+
def json_default(o: object) -> str | dict | list:
4242
if isinstance(o, PydanticBaseModel):
4343
return o.dict()
4444
elif dataclasses.is_dataclass(o):
45-
return dataclasses.asdict(o)
45+
return dataclasses.asdict(o) # type: ignore[arg-type]
4646
elif isinstance(o, enum.Enum):
4747
return o.value
4848
return str(o)

src/event_publisher.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import os
1212

1313
import boto3
14-
from botocore.exceptions import ClientError
1514
from mypy_boto3_events import EventBridgeClient
1615

1716
logger = logging.getLogger(__name__)
@@ -57,7 +56,7 @@ def publish_access_event(
5756
{
5857
"Source": "sso-elevator",
5958
"DetailType": "AccessChange",
60-
"EventBusArn": bus_arn,
59+
"EventBusName": bus_arn,
6160
"Detail": json.dumps(detail),
6261
}
6362
]
@@ -74,7 +73,7 @@ def publish_access_event(
7473
permission_set_name,
7574
account_id,
7675
)
77-
except ClientError:
76+
except Exception:
7877
logger.exception(
7978
"Error publishing EventBridge event",
8079
extra={"detail": detail},

src/group.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,14 @@ def approver_group_resolver(group_ids: frozenset[str]) -> set[str]:
147147
""",
148148
)
149149

150+
assert slack_response is not None
150151
blocks = slack_helpers.HeaderSectionBlock.set_status(
151-
blocks=slack_response["message"]["blocks"],
152+
blocks=slack_response["message"]["blocks"], # type: ignore[index]
152153
status_text=status_text,
153154
)
154155
client.chat_update(
155156
channel=cfg.slack_channel_id,
156-
ts=slack_response["ts"],
157+
ts=str(slack_response["ts"]),
157158
blocks=blocks,
158159
text=text,
159160
)
@@ -199,6 +200,7 @@ def approver_group_resolver(group_ids: frozenset[str]) -> set[str]:
199200
first_statement = list(decision.based_on_statements)[0] if decision.based_on_statements else None
200201
approver_emails = list(first_statement.approvers) if first_statement else []
201202
approver_groups = list(first_statement.approver_groups) if first_statement else []
203+
assert result.user_principal_id is not None
202204
early_revoke_payload = slack_helpers.EarlyRevokeButtonPayload(
203205
schedule_name=result.schedule_name,
204206
requester_slack_id=requester.id,
@@ -357,6 +359,7 @@ def approver_group_resolver(group_ids: frozenset[str]) -> set[str]:
357359
first_statement = list(decision.based_on_statements)[0] if decision.based_on_statements else None
358360
approver_emails = list(first_statement.approvers) if first_statement else []
359361
approver_groups = list(first_statement.approver_groups) if first_statement else []
362+
assert result.user_principal_id is not None
360363
early_revoke_payload = slack_helpers.EarlyRevokeButtonPayload(
361364
schedule_name=result.schedule_name,
362365
requester_slack_id=requester.id,

src/main.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ def approver_group_resolver(group_ids: frozenset[str]) -> set[str]:
390390
first_statement = list(decision.based_on_statements)[0] if decision.based_on_statements else None
391391
approver_emails = list(first_statement.approvers) if first_statement else []
392392
approver_groups = list(first_statement.approver_groups) if first_statement else []
393+
assert result.user_principal_id is not None
393394
early_revoke_payload = slack_helpers.EarlyRevokeButtonPayload(
394395
schedule_name=result.schedule_name,
395396
requester_slack_id=requester.id,
@@ -578,13 +579,14 @@ def approver_group_resolver(group_ids: frozenset[str]) -> set[str]:
578579
""",
579580
)
580581

582+
assert slack_response is not None
581583
blocks = slack_helpers.HeaderSectionBlock.set_status(
582-
blocks=slack_response["message"]["blocks"],
584+
blocks=slack_response["message"]["blocks"], # type: ignore[index]
583585
status_text=status_text,
584586
)
585587
client.chat_update(
586588
channel=cfg.slack_channel_id,
587-
ts=slack_response["ts"],
589+
ts=str(slack_response["ts"]),
588590
blocks=blocks,
589591
text=text,
590592
)
@@ -639,6 +641,7 @@ def approver_group_resolver(group_ids: frozenset[str]) -> set[str]:
639641
first_statement = list(decision.based_on_statements)[0] if decision.based_on_statements else None
640642
approver_emails = list(first_statement.approvers) if first_statement else []
641643
approver_groups = list(first_statement.approver_groups) if first_statement else []
644+
assert result.user_principal_id is not None
642645
early_revoke_payload = slack_helpers.EarlyRevokeButtonPayload(
643646
schedule_name=result.schedule_name,
644647
requester_slack_id=requester.id,
@@ -1000,6 +1003,7 @@ def handle_extend_grant_button_click(body: dict, client: WebClient, context: Bol
10001003

10011004
if payload.account_id and payload.permission_set_arn:
10021005
# Account access extension
1006+
assert payload.instance_arn is not None
10031007
account_assignment = sso.UserAccountAssignment(
10041008
instance_arn=payload.instance_arn,
10051009
account_id=payload.account_id,
@@ -1166,6 +1170,7 @@ def handle_early_revoke_modal_submission(body: dict, client: WebClient, context:
11661170
# Perform the revocation
11671171
if button_payload.account_id and button_payload.permission_set_arn:
11681172
# Account access revocation
1173+
assert button_payload.instance_arn is not None
11691174
user_account_assignment = sso.UserAccountAssignment(
11701175
instance_arn=button_payload.instance_arn,
11711176
account_id=button_payload.account_id,
@@ -1189,6 +1194,8 @@ def handle_early_revoke_modal_submission(body: dict, client: WebClient, context:
11891194
)
11901195
elif button_payload.group_id and button_payload.membership_id:
11911196
# Group access revocation
1197+
assert button_payload.group_name is not None
1198+
assert button_payload.identity_store_id is not None
11921199
group_assignment = sso.GroupAssignment(
11931200
group_name=button_payload.group_name,
11941201
group_id=button_payload.group_id,

src/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ dev = [
2323
"hypothesis[ghostwriter]>=6.71.0",
2424
"pre-commit>=4.0.0",
2525
"ruff>=0.14.9",
26+
"pyright>=1.1.0",
2627
]
2728

2829
[build-system]

0 commit comments

Comments
 (0)