-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #319 from awslabs/master
RELEASE 0.8.2
- Loading branch information
Showing
10 changed files
with
659 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,25 @@ | ||
from rdklib import Evaluator, Evaluation, ConfigRule, ComplianceType | ||
<%ApplicableResources1%> | ||
class <%RuleName%>(ConfigRule): | ||
def evaluate_change(self, event, client_factory, configuration_item, valid_rule_parameters): | ||
############################### | ||
# Add your custom logic here. # | ||
############################### | ||
|
||
return [Evaluation(ComplianceType.NOT_APPLICABLE)] | ||
|
||
#def evaluate_periodic(self, event, client_factory, valid_rule_parameters): | ||
# pass | ||
|
||
def evaluate_parameters(self, rule_parameters): | ||
valid_rule_parameters = rule_parameters | ||
return valid_rule_parameters | ||
|
||
|
||
################################ | ||
# DO NOT MODIFY ANYTHING BELOW # | ||
################################ | ||
def lambda_handler(event, context): | ||
my_rule = <%RuleName%>() | ||
evaluator = Evaluator(my_rule<%ApplicableResources2%>) | ||
return evaluator.handle(event, context) |
This file contains 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,49 @@ | ||
import unittest | ||
from unittest.mock import patch, MagicMock | ||
from botocore.exceptions import ClientError | ||
import rdklib | ||
from rdklib import Evaluation, ComplianceType | ||
import rdklibtest | ||
|
||
############## | ||
# Parameters # | ||
############## | ||
|
||
# Define the default resource to report to Config Rules | ||
RESOURCE_TYPE = 'AWS::::Account' | ||
|
||
############# | ||
# Main Code # | ||
############# | ||
|
||
MODULE = __import__('<%RuleName%>') | ||
RULE = MODULE.<%RuleName%>() | ||
|
||
CLIENT_FACTORY = MagicMock() | ||
|
||
#example for mocking S3 API calls | ||
S3_CLIENT_MOCK = MagicMock() | ||
|
||
def mock_get_client(client_name, *args, **kwargs): | ||
if client_name == 's3': | ||
return S3_CLIENT_MOCK | ||
raise Exception("Attempting to create an unknown client") | ||
|
||
@patch.object(CLIENT_FACTORY, 'build_client', MagicMock(side_effect=mock_get_client)) | ||
class ComplianceTest(unittest.TestCase): | ||
|
||
rule_parameters = '{"SomeParameterKey":"SomeParameterValue","SomeParameterKey2":"SomeParameterValue2"}' | ||
|
||
invoking_event_iam_role_sample = '{"configurationItem":{"relatedEvents":[],"relationships":[],"configuration":{},"tags":{},"configurationItemCaptureTime":"2018-07-02T03:37:52.418Z","awsAccountId":"123456789012","configurationItemStatus":"ResourceDiscovered","resourceType":"AWS::IAM::Role","resourceId":"some-resource-id","resourceName":"some-resource-name","ARN":"some-arn"},"notificationCreationTime":"2018-07-02T23:05:34.445Z","messageType":"ConfigurationItemChangeNotification"}' | ||
|
||
def setUp(self): | ||
pass | ||
|
||
def test_sample(self): | ||
self.assertTrue(True) | ||
|
||
#def test_sample_2(self): | ||
# response = MODULE.lambda_handler(rdklib.build_lambda_configurationchange_event(self.invoking_event_iam_role_sample, self.rule_parameters), {}) | ||
# resp_expected = [] | ||
# resp_expected.append(rdklib.build_expected_response('NOT_APPLICABLE', 'some-resource-id', 'AWS::IAM::Role')) | ||
# rdklib.assert_successful_evaluation(self, response, resp_expected) |
Oops, something went wrong.