Skip to content

Commit a771640

Browse files
committed
Fix duplicate AWS::Logs::ResourcePolicy
The newly added LogResourcePolicy already existed as ResourcePolicy in Logs. Prefer the older one as it aligns with the AWS naming. This does keep the newly added validation and tests.
1 parent e1706e5 commit a771640

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

tests/test_logs.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import unittest
22

33
from troposphere import Retain
4-
from troposphere.logs import Destination, LogGroup, validate_resource_policy, LogResourcePolicy
4+
from troposphere.logs import (
5+
Destination,
6+
LogGroup,
7+
ResourcePolicy,
8+
validate_resource_policy,
9+
)
510

611

712
class TestLogs(unittest.TestCase):
@@ -36,18 +41,30 @@ def test_log_destination(self):
3641
self.assertIn("Properties", log_destination_json)
3742

3843
def test_validate_resource_policy(self):
39-
for s in ["{ \"Version\": \"2012-10-17\", \"Statement\": [ { \"Sid\": \"Route53LogsToCloudWatchLogs\", \"Effect\": \"Allow\", \"Principal\": { \"Service\": [ \"route53.amazonaws.com\" ] }, \"Action\":\"logs:PutLogEvents\", \"Resource\": \"logArn\" } ] }", {'Version': '2012-10-17', 'Statement': [{'Sid': 'Route53LogsToCloudWatchLogs', 'Effect': 'Allow', 'Principal': {'Service': ['route53.amazonaws.com']}, 'Action': 'logs:PutLogEvents', 'Resource': 'logArn'}]}]:
44+
for s in [
45+
'{ "Version": "2012-10-17", "Statement": [ { "Sid": "Route53LogsToCloudWatchLogs", "Effect": "Allow", "Principal": { "Service": [ "route53.amazonaws.com" ] }, "Action":"logs:PutLogEvents", "Resource": "logArn" } ] }',
46+
{
47+
"Version": "2012-10-17",
48+
"Statement": [
49+
{
50+
"Sid": "Route53LogsToCloudWatchLogs",
51+
"Effect": "Allow",
52+
"Principal": {"Service": ["route53.amazonaws.com"]},
53+
"Action": "logs:PutLogEvents",
54+
"Resource": "logArn",
55+
}
56+
],
57+
},
58+
]:
4059
validate_resource_policy(s)
41-
log_policy = LogResourcePolicy(
42-
"TestLogPolicy",
43-
PolicyName='TestLogPolicy',
44-
PolicyDocument=s
60+
log_policy = ResourcePolicy(
61+
"TestLogPolicy", PolicyName="TestLogPolicy", PolicyDocument=s
4562
)
4663
expected = log_policy.to_dict()
47-
properties = expected['Properties']
48-
self.assertEqual(properties.get('PolicyDocument'), s)
64+
properties = expected["Properties"]
65+
self.assertEqual(properties.get("PolicyDocument"), s)
4966

50-
for s in ["", "H"*5121, "TEXT", {}]:
67+
for s in ["", "H" * 5121, "TEXT", {}]:
5168
with self.assertRaises(ValueError):
5269
validate_resource_policy(s)
5370

troposphere/logs.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import json
2+
13
from . import AWSObject, AWSProperty
24
from .compat import policytypes
35
from .constants import LOGS_ALLOWED_RETENTION_DAYS as RETENTION_DAYS
46
from .validators import integer_list_item, json_checker
5-
import json
67

78
policytypes = policytypes + (str,)
89

@@ -93,7 +94,7 @@ class ResourcePolicy(AWSObject):
9394
resource_type = "AWS::Logs::ResourcePolicy"
9495

9596
props = {
96-
"PolicyDocument": (str, True),
97+
"PolicyDocument": (validate_resource_policy, True),
9798
"PolicyName": (str, True),
9899
}
99100

@@ -107,12 +108,3 @@ class SubscriptionFilter(AWSObject):
107108
"LogGroupName": (str, True),
108109
"RoleArn": (str, False),
109110
}
110-
111-
112-
class LogResourcePolicy(AWSObject):
113-
resource_type = "AWS::Logs::ResourcePolicy"
114-
115-
props = {
116-
"PolicyDocument": (validate_resource_policy, True),
117-
"PolicyName": (str, True),
118-
}

0 commit comments

Comments
 (0)