-
Notifications
You must be signed in to change notification settings - Fork 453
feat(event_sources): add AWS Config Rule event data class #2175
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
Merged
rubenfonseca
merged 19 commits into
aws-powertools:develop
from
leandrodamascena:dataclass/awsconfig
Jun 15, 2023
Merged
Changes from 10 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
cb61bce
feat(dataclass): adding dataclass events
leandrodamascena 0b88d33
feat(dataclass): adding dataclass events
leandrodamascena 1b93326
feat(dataclass): adding examples and more fields
leandrodamascena 4393ea0
feat(dataclass): improving docstring
leandrodamascena c5db6b0
feat(dataclass): tests and small fixes
leandrodamascena 440f0d1
feat(dataclass): tests and small fixes
leandrodamascena 95a5fdf
Merge branch 'develop' into dataclass/awsconfig
leandrodamascena 0797c2c
feat(dataclass): improving code coverage
leandrodamascena c9cd24b
feat(dataclass): adding fields to test class
leandrodamascena 5bd9808
feat(dataclass): more fields
leandrodamascena 08f994d
Merge remote-tracking branch 'upstream/develop' into dataclass/awsconfig
leandrodamascena 0db1025
docs: highlight
leandrodamascena a35fd71
Merge branch 'develop' into dataclass/awsconfig
leandrodamascena 1a2a37c
Merge branch 'develop' into dataclass/awsconfig
leandrodamascena 70f8380
commenting
leandrodamascena 06b3319
Commit
leandrodamascena 39ae25c
feat: adding cache to json fields
leandrodamascena b0ebf65
doc: adding docstring
leandrodamascena 8aabf85
Merge remote-tracking branch 'upstream/develop' into dataclass/awsconfig
leandrodamascena File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
336 changes: 336 additions & 0 deletions
336
aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,336 @@ | ||
from __future__ import annotations | ||
|
||
import json | ||
from typing import Dict, List, Optional | ||
|
||
from aws_lambda_powertools.utilities.data_classes.common import DictWrapper | ||
|
||
|
||
def get_invoke_event( | ||
invoking_event: dict, | ||
) -> AWSConfigConfigurationChanged | AWSConfigScheduledNotification | AWSConfigOversizedConfiguration: | ||
message_type = invoking_event.get("messageType") | ||
|
||
if message_type == "ScheduledNotification": | ||
return AWSConfigScheduledNotification(invoking_event) | ||
|
||
if message_type == "OversizedConfigurationItemChangeNotification": | ||
return AWSConfigOversizedConfiguration(invoking_event) | ||
|
||
# Default return is ConfigurationChanged | ||
return AWSConfigConfigurationChanged(invoking_event) | ||
|
||
|
||
class AWSConfigConfigurationChanged(DictWrapper): | ||
@property | ||
def configuration_item_diff(self) -> Dict: | ||
"""The configuration item diff of the ConfigurationItemChangeNotification event.""" | ||
return self["configurationItemDiff"] | ||
|
||
@property | ||
def configuration_item(self) -> AWSConfigConfigurationItemChanged: | ||
"""The configuration item of the ConfigurationItemChangeNotification event.""" | ||
return AWSConfigConfigurationItemChanged(self["configurationItem"]) | ||
|
||
@property | ||
def raw_configuration_item(self) -> Dict: | ||
"""The raw configuration item of the ConfigurationItemChangeNotification event.""" | ||
return self["configurationItem"] | ||
|
||
@property | ||
def record_version(self) -> str: | ||
"""The record version of the ConfigurationItemChangeNotification event.""" | ||
return self["recordVersion"] | ||
|
||
@property | ||
def message_type(self) -> str: | ||
"""The message type of the ConfigurationItemChangeNotification event.""" | ||
return self["messageType"] | ||
|
||
@property | ||
def notification_creation_time(self) -> str: | ||
"""The notification creation time of the ConfigurationItemChangeNotification event.""" | ||
return self["notificationCreationTime"] | ||
|
||
|
||
class AWSConfigConfigurationItemChanged(DictWrapper): | ||
@property | ||
def related_events(self) -> List: | ||
"""The related events of the ConfigurationItemChangeNotification event.""" | ||
return self["relatedEvents"] | ||
|
||
@property | ||
def relationships(self) -> List: | ||
"""The relationships of the ConfigurationItemChangeNotification event.""" | ||
return self["relationships"] | ||
|
||
@property | ||
def configuration(self) -> Dict: | ||
"""The configuration of the ConfigurationItemChangeNotification event.""" | ||
return self["configuration"] | ||
|
||
@property | ||
def supplementary_configuration(self) -> Dict: | ||
"""The supplementary configuration of the ConfigurationItemChangeNotification event.""" | ||
return self["supplementaryConfiguration"] | ||
|
||
@property | ||
def tags(self) -> Dict: | ||
"""The tags of the ConfigurationItemChangeNotification event.""" | ||
return self["tags"] | ||
|
||
@property | ||
def configuration_item_version(self) -> str: | ||
"""The configuration item version of the ConfigurationItemChangeNotification event.""" | ||
return self["configurationItemVersion"] | ||
|
||
@property | ||
def configuration_item_capture_time(self) -> str: | ||
"""The configuration item capture time of the ConfigurationItemChangeNotification event.""" | ||
return self["configurationItemCaptureTime"] | ||
|
||
@property | ||
def configuration_state_id(self) -> str: | ||
"""The configuration state id of the ConfigurationItemChangeNotification event.""" | ||
return self["configurationStateId"] | ||
|
||
@property | ||
def accountid(self) -> str: | ||
"""The accountid of the ConfigurationItemChangeNotification event.""" | ||
return self["awsAccountId"] | ||
|
||
@property | ||
def configuration_item_status(self) -> str: | ||
"""The configuration item status of the ConfigurationItemChangeNotification event.""" | ||
return self["configurationItemStatus"] | ||
|
||
@property | ||
def resource_type(self) -> str: | ||
"""The resource type of the ConfigurationItemChangeNotification event.""" | ||
return self["resourceType"] | ||
|
||
@property | ||
def resource_id(self) -> str: | ||
"""The resource id of the ConfigurationItemChangeNotification event.""" | ||
return self["resourceId"] | ||
|
||
@property | ||
def resource_name(self) -> str: | ||
"""The resource name of the ConfigurationItemChangeNotification event.""" | ||
return self["resourceName"] | ||
|
||
@property | ||
def resource_arn(self) -> str: | ||
"""The resource arn of the ConfigurationItemChangeNotification event.""" | ||
return self["ARN"] | ||
|
||
@property | ||
def region(self) -> str: | ||
"""The region of the ConfigurationItemChangeNotification event.""" | ||
return self["awsRegion"] | ||
|
||
@property | ||
def availability_zone(self) -> str: | ||
"""The availability zone of the ConfigurationItemChangeNotification event.""" | ||
return self["availabilityZone"] | ||
|
||
@property | ||
def configuration_state_md5_hash(self) -> str: | ||
"""The md5 hash of the state of the ConfigurationItemChangeNotification event.""" | ||
return self["configurationStateMd5Hash"] | ||
|
||
@property | ||
def resource_creation_time(self) -> str: | ||
"""The resource creation time of the ConfigurationItemChangeNotification event.""" | ||
return self["resourceCreationTime"] | ||
|
||
|
||
class AWSConfigScheduledNotification(DictWrapper): | ||
@property | ||
def accountid(self) -> str: | ||
"""The accountid of the ScheduledNotification event.""" | ||
return self["awsAccountId"] | ||
|
||
@property | ||
def notification_creation_time(self) -> str: | ||
"""The notification creation time of the ScheduledNotification event.""" | ||
return self["notificationCreationTime"] | ||
|
||
@property | ||
def record_version(self) -> str: | ||
"""The record version of the ScheduledNotification event.""" | ||
return self["recordVersion"] | ||
|
||
@property | ||
def message_type(self) -> str: | ||
"""The message type of the ScheduledNotification event.""" | ||
return self["messageType"] | ||
|
||
|
||
class AWSConfigOversizedConfiguration(DictWrapper): | ||
@property | ||
def configuration_item_summary(self) -> AWSConfigOversizedConfigurationItemSummary: | ||
"""The configuration item summary of the OversizedConfiguration event.""" | ||
return AWSConfigOversizedConfigurationItemSummary(self["configurationItemSummary"]) | ||
|
||
@property | ||
def raw_configuration_item_summary(self) -> str: | ||
"""The raw configuration item summary of the OversizedConfiguration event.""" | ||
return self["configurationItemSummary"] | ||
|
||
@property | ||
def message_type(self) -> str: | ||
"""The message type of the OversizedConfiguration event.""" | ||
return self["messageType"] | ||
|
||
@property | ||
def notification_creation_time(self) -> str: | ||
"""The notification creation time of the OversizedConfiguration event.""" | ||
return self["notificationCreationTime"] | ||
|
||
@property | ||
def record_version(self) -> str: | ||
"""The record version of the OversizedConfiguration event.""" | ||
return self["recordVersion"] | ||
|
||
|
||
class AWSConfigOversizedConfigurationItemSummary(DictWrapper): | ||
@property | ||
def change_type(self) -> str: | ||
"""The change type of the OversizedConfiguration event.""" | ||
return self["changeType"] | ||
|
||
@property | ||
def configuration_item_version(self) -> str: | ||
"""The configuration item version of the OversizedConfiguration event.""" | ||
return self["configurationItemVersion"] | ||
|
||
@property | ||
def configuration_item_capture_time(self) -> str: | ||
"""The configuration item capture time of the OversizedConfiguration event.""" | ||
return self["configurationItemCaptureTime"] | ||
|
||
@property | ||
def configuration_state_id(self) -> str: | ||
"""The configuration state id of the OversizedConfiguration event.""" | ||
return self["configurationStateId"] | ||
|
||
@property | ||
def accountid(self) -> str: | ||
"""The accountid of the OversizedConfiguration event.""" | ||
return self["awsAccountId"] | ||
|
||
@property | ||
def configuration_item_status(self) -> str: | ||
"""The configuration item status of the OversizedConfiguration event.""" | ||
return self["configurationItemStatus"] | ||
|
||
@property | ||
def resource_type(self) -> str: | ||
"""The resource type of the OversizedConfiguration event.""" | ||
return self["resourceType"] | ||
|
||
@property | ||
def resource_id(self) -> str: | ||
"""The resource id of the OversizedConfiguration event.""" | ||
return self["resourceId"] | ||
|
||
@property | ||
def resource_name(self) -> str: | ||
"""The resource name of the OversizedConfiguration event.""" | ||
return self["resourceName"] | ||
|
||
@property | ||
def resource_arn(self) -> str: | ||
"""The resource arn of the OversizedConfiguration event.""" | ||
return self["ARN"] | ||
|
||
@property | ||
def region(self) -> str: | ||
"""The region of the OversizedConfiguration event.""" | ||
return self["awsRegion"] | ||
|
||
@property | ||
def availability_zone(self) -> str: | ||
"""The availability zone of the OversizedConfiguration event.""" | ||
return self["availabilityZone"] | ||
|
||
@property | ||
def configuration_state_md5_hash(self) -> str: | ||
"""The state md5 hash of the OversizedConfiguration event.""" | ||
return self["configurationStateMd5Hash"] | ||
|
||
@property | ||
def resource_creation_time(self) -> str: | ||
"""The resource creation time of the OversizedConfiguration event.""" | ||
return self["resourceCreationTime"] | ||
|
||
|
||
class AWSConfigRuleEvent(DictWrapper): | ||
"""Events for AWS Config Rules | ||
Documentation: | ||
-------------- | ||
- https://docs.aws.amazon.com/config/latest/developerguide/evaluate-config_develop-rules_lambda-functions.html | ||
""" | ||
|
||
@property | ||
def version(self) -> str: | ||
"""The version of the event.""" | ||
return self["version"] | ||
|
||
@property | ||
def invoking_event( | ||
self, | ||
) -> AWSConfigConfigurationChanged | AWSConfigScheduledNotification | AWSConfigOversizedConfiguration: | ||
"""The invoking payload of the event.""" | ||
return get_invoke_event(json.loads(self["invokingEvent"])) | ||
|
||
@property | ||
def raw_invoking_event(self) -> str: | ||
"""The raw invoking payload of the event.""" | ||
return self["invokingEvent"] | ||
|
||
@property | ||
def rule_parameters(self) -> Dict: | ||
"""The parameters of the event.""" | ||
return json.loads(self["ruleParameters"]) | ||
|
||
@property | ||
def result_token(self) -> str: | ||
"""The result token of the event.""" | ||
return self["resultToken"] | ||
|
||
@property | ||
def event_left_scope(self) -> bool: | ||
"""The left scope of the event.""" | ||
return self["eventLeftScope"] | ||
|
||
@property | ||
def execution_role_arn(self) -> str: | ||
"""The execution role arn of the event.""" | ||
return self["executionRoleArn"] | ||
|
||
@property | ||
def config_rule_arn(self) -> str: | ||
"""The arn of the rule of the event.""" | ||
return self["configRuleArn"] | ||
|
||
@property | ||
def config_rule_name(self) -> str: | ||
"""The name of the rule of the event.""" | ||
return self["configRuleName"] | ||
|
||
@property | ||
def config_rule_id(self) -> str: | ||
"""The id of the rule of the event.""" | ||
return self["configRuleId"] | ||
|
||
@property | ||
def accountid(self) -> str: | ||
"""The accountid of the event.""" | ||
return self["accountId"] | ||
|
||
@property | ||
def evalution_mode(self) -> Optional[str]: | ||
"""The evalution mode of the event.""" | ||
return self.get("evaluationMode") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.