public void AddEvent(string key, FunctionEventsModel value) { if (!events.ContainsKey(key)) { events.Add(key, value); } }
private void PrepareApplicationModel() { applicationModel.HasRestApi = application.Components .Any(c => c.Type == ComponentType.RestEndpoint); applicationModel.IsCorsEnabled = application.Components .Where(c => c.Type == ComponentType.RestEndpoint) .Any(c => c.InboundConnections.Any()); applicationModel.Functions = application.Components .Where(c => c.Type == ComponentType.Function) .Select(c => BuildFunction(c)) .ToList(); applicationModel.Tables = application.Components .Where(c => c.Type == ComponentType.Table) .Select(c => new TableModel { Name = c.Name, IsStreamEnabled = c.OutboundConnections.Any() }) .ToList(); applicationModel.Topics = application.Components .Where(c => c.Type == ComponentType.Topic) .Select(c => new TopicModel { Name = c.Name }) .ToList(); applicationModel.QueuePoliciesPerTopic = application.Components .Where(c => c.Type == ComponentType.Topic) .SelectMany(c => c.OutboundConnections.Where(conn => conn.Target.Type == ComponentType.Queue)) .GroupBy(conn => conn.Source.Name) .Select(g => new QueuePoliciesForTopic { TopicName = g.Key, QueueNames = g.Select(conn => conn.Target.Name).ToList() }) .ToList(); applicationModel.QueueTopicSubscriptions = application.Components .Where(c => c.Type == ComponentType.Topic) .SelectMany(c => c.OutboundConnections.Where(conn => conn.Target.Type == ComponentType.Queue)) .GroupBy(conn => new { Topic = conn.Source.Name, Queue = conn.Target.Name }) .Select(g => new QueueTopicSubscription { Topic = g.Key.Topic, Queue = g.Key.Queue, FilterPolicy = MergeSnsFilters( g.Select(conn => ParseSnsMessageAttributes(conn.Label)) .ToList() ) .ToDictionary(p => p.Key, p => new YamlValue(p.Value)) } ) .ToList(); applicationModel.Queues = application.Components .Where(c => c.Type == ComponentType.Queue) .Select(c => new QueueModel { Name = c.Name }) .ToList(); applicationModel.Buckets = application.Components .Where(c => c.Type == ComponentType.Bucket) .Select(c => new BucketModel { Name = c.Name, IsCorsEnabled = c.InboundConnections.Any(conn2 => conn2.Source.Type == ComponentType.Browser) }) .ToList(); var lambdaSnsSubs = application.Components .Where(c => c.Type == ComponentType.Topic) .SelectMany(c => c.OutboundConnections.Where(conn => conn.Target.Type == ComponentType.Function)) .GroupBy(conn => new { Topic = conn.Source.Name, Function = conn.Target.Name }) .Select(g => new { g.Key.Topic, g.Key.Function, FilterPolicy = MergeSnsFilters( g.Select(conn => ParseSnsMessageAttributes(conn.Label)) .ToList() ) .ToDictionary(p => p.Key, p => new YamlValue(p.Value)) } ) .ToList(); foreach (var item in lambdaSnsSubs) { var func = applicationModel.Functions.SingleOrDefault(f => f.Name == item.Function); if (func == null) { continue; } var @event = new FunctionEventsModel { Type = "SNS", Properties = new Dictionary <string, YamlValue> { { "Topic", $"!Ref {item.Topic}" }, } }; if (item.FilterPolicy.Count > 0) { @event.Properties.Add("FilterPolicy", item.FilterPolicy); } func.AddEvent( Regex.Replace(item.Topic, "[^a-zA-Z0-9]", "") + "SNS", @event ); } }