Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make resource_policy abstract method to trigger typecheck #2252

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions fixlib/fixlib/baseresources.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import base64
import hashlib
import weakref
from abc import ABC
from abc import ABC, abstractmethod
from copy import deepcopy
from datetime import datetime, timezone, timedelta
from enum import Enum, StrEnum, unique
Expand Down Expand Up @@ -1633,8 +1633,9 @@ class PolicySource:

class HasResourcePolicy(ABC):
# returns a list of all policies that affects the resource (inline, attached, etc.)
@abstractmethod
def resource_policy(self, builder: Any) -> List[Tuple[PolicySource, Json]]:
raise NotImplementedError
pass


@frozen
Expand Down
10 changes: 8 additions & 2 deletions plugins/aws/fix_plugin_aws/resource/kinesis.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import ClassVar, Dict, Optional, List, Any
from typing import ClassVar, Dict, Optional, List, Any, Tuple
from json import loads as json_loads

from attrs import define, field
Expand All @@ -8,7 +8,7 @@
from fix_plugin_aws.resource.kms import AwsKmsKey
from fix_plugin_aws.aws_client import AwsClient
from fix_plugin_aws.utils import ToDict
from fixlib.baseresources import HasResourcePolicy, MetricName, ModelReference
from fixlib.baseresources import HasResourcePolicy, MetricName, ModelReference, PolicySource, PolicySourceKind
from fixlib.graph import Graph
from fixlib.json_bender import Bender, S, Bend, bend, ForallBend
from fixlib.types import Json
Expand Down Expand Up @@ -133,6 +133,12 @@ class AwsKinesisStream(AwsResource, HasResourcePolicy):
kinesis_key_id: Optional[str] = field(default=None)
kinesis_policy: Optional[Json] = field(default=None)

def resource_policy(self, builder: Any) -> List[Tuple[PolicySource, Dict[str, Any]]]:
if not self.kinesis_policy or not self.arn:
return []

return [(PolicySource(PolicySourceKind.resource, self.arn), self.kinesis_policy)]

@classmethod
def called_collect_apis(cls) -> List[AwsApiSpec]:
return [
Expand Down
Loading