Skip to content

Commit

Permalink
Make resource_policy abstract method to trigger typecheck (#2252)
Browse files Browse the repository at this point in the history
  • Loading branch information
meln1k authored Oct 17, 2024
1 parent a008325 commit 015bbfe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
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

0 comments on commit 015bbfe

Please sign in to comment.