Skip to content

Commit

Permalink
- Added CodeStart NotifciationRule Name filter for resource name gene…
Browse files Browse the repository at this point in the history
…ration

- Fixed unique listener cert name in ALB
- Fixed DeploymentPipeline notification rules if a rule does not have any event ids.
  • Loading branch information
gitwater committed Apr 21, 2021
1 parent e419427 commit 75e08dd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
20 changes: 14 additions & 6 deletions src/paco/cftemplates/cftemplates.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ def resource_name_filter(self, name, filter_id, hash_long_names):
message = "ReplicationGroupId must be 40 characters or less"
elif filter_id == 'SecurityGroup.GroupName':
pass
elif filter_id == 'CodeStar.NotificationRuleName':
if len(name) > 64:
max_name_len = 64
message = "CodeStar NotificationRule name must be 64 characters or less"
else:
message = 'Unknown filter_id'

Expand All @@ -357,28 +361,32 @@ def resource_char_filter(self, ch, filter_id, remove_invalids=False):
# Universal check
if ch.isalnum() == True:
return ch
valid_ch_list = ''
# SecurityGroup Group Name
# Constraints for EC2-VPC: a-z, A-Z, 0-9, spaces, and ._-:/()#,@[]+=&;{}!$*
if filter_id == 'SecurityGroup.GroupName':
if ch in ' ._-:/()#,@[]+=&;{}!$*':
return ch
valid_ch_list = ' ._-:/()#,@[]+=&;{}!$*'
elif filter_id in [
'IAM.Role.RoleName',
'IAM.ManagedPolicy.ManagedPolicyName',
'IAM.Policy.PolicyName']:
if ch in '_+=,.@-.':
return ch
valid_ch_list = '_+=,.@-.'
elif filter_id == 'ElastiCache.ReplicationGroup.ReplicationGroupId':
if ch in '-':
return ch
valid_ch_list = '-'
elif filter_id in [
'EC2.ElasticLoadBalancingV2.LoadBalancer.Name',
'EC2.ElasticLoadBalancingV2.TargetGroup.Name']:
# Only alphanum and dases are allowed
pass
elif filter_id in [
'CodeStar.NotificationRuleName']:
valid_ch_list = '-_ '
else:
raise StackException(PacoErrorCode.Unknown, message="Invalid filter Id: "+filter_id)

if ch in valid_ch_list:
return ch

if remove_invalids == True:
return ''

Expand Down
2 changes: 2 additions & 0 deletions src/paco/cftemplates/lb.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from paco.cftemplates.cftemplates import StackTemplate
from paco.cftemplates.cftemplates import StackOutputParam
from paco.models.references import get_model_obj_from_ref
from paco import utils
import troposphere
import troposphere.elasticloadbalancingv2

Expand Down Expand Up @@ -284,6 +285,7 @@ def init_lb(self, aws_name, template_title):

# ListenerCertificates
if len(ssl_cert_param_obj_list) > 0:
unique_listener_cert_name = utils.md5sum(str_data=unique_listener_cert_name)
logical_listener_cert_name = self.create_cfn_logical_id_join([logical_listener_name, 'Certificate', unique_listener_cert_name])
troposphere.elasticloadbalancingv2.ListenerCertificate(
title=logical_listener_cert_name,
Expand Down
7 changes: 5 additions & 2 deletions src/paco/cftemplates/notification_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, stack, paco_ctx, app_name, env_name, rules_arn_ref_list):
app_config = get_parent_by_interface(self.resource, schemas.IApplication)
notifications = app_config.notifications

if notifications != None and len(notifications.keys()) > 0:
if len(self.resource.notification_events) > 0 and notifications != None and len(notifications.keys()) > 0:
notify_param_cache = []
for notify_group_name in notifications.keys():
for sns_group_name in notifications[notify_group_name].groups:
Expand All @@ -53,7 +53,10 @@ def __init__(self, stack, paco_ctx, app_name, env_name, rules_arn_ref_list):
value=f'{self.resource.paco_ref}.arn'
)

rule_name = self.create_resource_name(f'{self.env_name}-{self.app_name}-{self.resource_group_name}-{self.resource.name}-{self.aws_region}')
rule_name = self.create_resource_name(
f'{self.env_name}-{self.app_name}-{self.resource_group_name}-{self.resource.name}-{self.aws_region}',
hash_long_names=True,
filter_id='CodeStar.NotificationRuleName')
rule_dict = {
'DetailType': 'FULL',
'EventTypeIds': event_id_list,
Expand Down

0 comments on commit 75e08dd

Please sign in to comment.