Mitch Garnaat

Merging changes.

......@@ -34,7 +34,7 @@ from kappa.context import Context
@click.argument(
'command',
required=True,
type=click.Choice(['deploy', 'test', 'tail', 'add-event-source', 'delete'])
type=click.Choice(['deploy', 'test', 'tail', 'add-event-sources', 'delete'])
)
def main(config=None, debug=False, command=None):
ctx = Context(config, debug)
......@@ -54,7 +54,7 @@ def main(config=None, debug=False, command=None):
click.echo('Deleting ...')
ctx.delete()
click.echo('...done')
elif command == 'add-event-source':
elif command == 'add-event-sources':
click.echo('Adding event sources ...')
ctx.add_event_sources()
click.echo('...done')
......
......@@ -100,6 +100,15 @@ class S3EventSource(EventSource):
LOG.exception('Unable to add S3 event source')
def remove(self, function):
LOG.debug('removing s3 notification')
response = self._s3.get_bucket_notification(
Bucket=self._get_bucket_name())
LOG.debug(response)
if 'CloudFunctionConfiguration' in response:
fn_arn = response['CloudFunctionConfiguration']['CloudFunction']
if fn_arn == function.arn:
del response['CloudFunctionConfiguration']
response = self._s3.put_bucket_notification(
Bucket=self._get_bucket_name(),
NotificationConfiguration=response)
LOG.debug(response)
......
......@@ -26,8 +26,18 @@ class Log(object):
aws = kappa.aws.get_aws(self._context)
self._log_svc = aws.create_client('logs')
def _check_for_log_group(self):
LOG.debug('checking for log group')
response = self._log_svc.describe_log_groups()
log_group_names = [lg['logGroupName'] for lg in response['logGroups']]
return self.log_group_name in log_group_names
def streams(self):
LOG.debug('getting streams for log group: %s', self.log_group_name)
if not self._check_for_log_group():
LOG.info(
'log group %s has not been created yet', self.log_group_name)
return []
response = self._log_svc.describe_log_streams(
logGroupName=self.log_group_name)
LOG.debug(response)
......@@ -35,6 +45,10 @@ class Log(object):
def tail(self):
LOG.debug('tailing log group: %s', self.log_group_name)
if not self._check_for_log_group():
LOG.info(
'log group %s has not been created yet', self.log_group_name)
return []
latest_stream = None
streams = self.streams()
for stream in streams:
......
botocore==0.80.0
botocore==0.82.0
click==3.3
PyYAML>=3.11
mock>=1.0.1
......
......@@ -5,7 +5,7 @@ from setuptools import setup, find_packages
import os
requires = [
'botocore==0.80.0',
'botocore==0.82.0',
'click==3.3',
'PyYAML>=3.11'
]
......