Jose Diaz-Gonzalez

simplify event source retrieval

......@@ -22,10 +22,10 @@ import sys
import kappa.function
import kappa.restapi
import kappa.event_source.dynamodb_stream as dynamodb_stream
import kappa.event_source.kinesis as kinesis
import kappa.event_source.s3 as s3
import kappa.event_source.sns as sns
import kappa.event_source.dynamodb_stream
import kappa.event_source.kinesis
import kappa.event_source.s3
import kappa.event_source.sns
import kappa.policy
import kappa.role
import kappa.awsclient
......@@ -168,27 +168,27 @@ class Context(object):
def _create_event_sources(self):
env_cfg = self.config['environments'][self.environment]
if 'event_sources' in env_cfg:
if 'event_sources' not in env_cfg:
return
event_sources = env_cfg.get('event_sources', {})
if not event_sources:
return
event_source_map = {
'dynamodb': kappa.event_source.dynamodb_stream.DynamoDBStreamEventSource,
'kinesis': kappa.event_source.kinesis.KinesisEventSource,
's3': kappa.event_source.s3.S3EventSource,
'sns': kappa.event_source.sns.SNSEventSource,
}
for event_source_cfg in event_sources:
_, _, svc, _ = event_source_cfg['arn'].split(':', 3)
if svc == 'kinesis':
self.event_sources.append(
kinesis.KinesisEventSource(self, event_source_cfg))
elif svc == 's3':
event_source = event_source_map.get(svc, None)
if not event_source:
raise ValueError('Unknown event source: {0}'.format(
event_source_cfg['arn']))
self.event_sources.append(
s3.S3EventSource(self, event_source_cfg))
elif svc == 'sns':
self.event_sources.append(
sns.SNSEventSource(self, event_source_cfg))
elif svc == 'dynamodb':
self.event_sources.append(
dynamodb_stream.DynamoDBStreamEventSource(self, event_source_cfg))
else:
msg = 'Unknown event source: %s' % event_source_cfg['arn']
raise ValueError(msg)
event_source(self, event_source_cfg))
def add_event_sources(self):
for event_source in self.event_sources:
......