From 9dc31dd4b34b28619f2d6645f680104547846e72 Mon Sep 17 00:00:00 2001 From: ShaikMohammad Shakeel Date: Wed, 31 Jul 2019 13:17:03 +0530 Subject: [PATCH 01/13] add subject in aws sns hook --- airflow/contrib/hooks/aws_sns_hook.py | 14 ++++++++++++-- tests/contrib/hooks/test_aws_sns_hook.py | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/airflow/contrib/hooks/aws_sns_hook.py b/airflow/contrib/hooks/aws_sns_hook.py index 7d5658afaf7c7..dcf6f68fc7dd6 100644 --- a/airflow/contrib/hooks/aws_sns_hook.py +++ b/airflow/contrib/hooks/aws_sns_hook.py @@ -41,7 +41,7 @@ def get_conn(self): self.conn = self.get_client_type('sns') return self.conn - def publish_to_target(self, target_arn, message): + def publish_to_target(self, target_arn, message, subject=None): """ Publish a message to a topic or an endpoint. @@ -49,6 +49,8 @@ def publish_to_target(self, target_arn, message): :type target_arn: str :param message: the default message you want to send :param message: str + :param subject: subject of message + :type subject: str """ conn = self.get_conn() @@ -57,8 +59,16 @@ def publish_to_target(self, target_arn, message): 'default': message } + if subject is None: + return conn.publish( + TargetArn=target_arn, + Message=json.dumps(messages), + MessageStructure='json' + ) + return conn.publish( TargetArn=target_arn, Message=json.dumps(messages), - MessageStructure='json' + MessageStructure='json', + Subject = subject ) diff --git a/tests/contrib/hooks/test_aws_sns_hook.py b/tests/contrib/hooks/test_aws_sns_hook.py index 480e29d08842e..9c22e0b0b7eb5 100644 --- a/tests/contrib/hooks/test_aws_sns_hook.py +++ b/tests/contrib/hooks/test_aws_sns_hook.py @@ -42,9 +42,10 @@ def test_publish_to_target(self): message = "Hello world" topic_name = "test-topic" + subject = "test-subject" target = hook.get_conn().create_topic(Name=topic_name).get('TopicArn') - response = hook.publish_to_target(target, message) + response = hook.publish_to_target(target, message, subject) self.assertTrue('MessageId' in response) From 34d56161fd3a6efad09c5bb44ec14b4ad0650d69 Mon Sep 17 00:00:00 2001 From: ShaikMohammad Shakeel Date: Wed, 31 Jul 2019 14:40:18 +0530 Subject: [PATCH 02/13] flake8 fix --- airflow/contrib/hooks/aws_sns_hook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airflow/contrib/hooks/aws_sns_hook.py b/airflow/contrib/hooks/aws_sns_hook.py index dcf6f68fc7dd6..6d47fc74b5dd9 100644 --- a/airflow/contrib/hooks/aws_sns_hook.py +++ b/airflow/contrib/hooks/aws_sns_hook.py @@ -70,5 +70,5 @@ def publish_to_target(self, target_arn, message, subject=None): TargetArn=target_arn, Message=json.dumps(messages), MessageStructure='json', - Subject = subject + Subject=subject ) From 1ff52eddec07f788c437d2754eb402bc96028d2a Mon Sep 17 00:00:00 2001 From: ShaikMohammad Shakeel Date: Wed, 31 Jul 2019 19:23:13 +0530 Subject: [PATCH 03/13] flake8 fix --- airflow/contrib/hooks/aws_sns_hook.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/airflow/contrib/hooks/aws_sns_hook.py b/airflow/contrib/hooks/aws_sns_hook.py index 6d47fc74b5dd9..af4d1fa99fcab 100644 --- a/airflow/contrib/hooks/aws_sns_hook.py +++ b/airflow/contrib/hooks/aws_sns_hook.py @@ -54,11 +54,10 @@ def publish_to_target(self, target_arn, message, subject=None): """ conn = self.get_conn() - messages = { 'default': message } - + if subject is None: return conn.publish( TargetArn=target_arn, From dbe60774fd267aa06d99a40a8e0ecd8e9bc232a3 Mon Sep 17 00:00:00 2001 From: ShaikMohammad Shakeel Date: Wed, 31 Jul 2019 19:44:33 +0530 Subject: [PATCH 04/13] flake8 fix --- airflow/contrib/hooks/aws_sns_hook.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/airflow/contrib/hooks/aws_sns_hook.py b/airflow/contrib/hooks/aws_sns_hook.py index af4d1fa99fcab..6d47fc74b5dd9 100644 --- a/airflow/contrib/hooks/aws_sns_hook.py +++ b/airflow/contrib/hooks/aws_sns_hook.py @@ -54,10 +54,11 @@ def publish_to_target(self, target_arn, message, subject=None): """ conn = self.get_conn() + messages = { 'default': message } - + if subject is None: return conn.publish( TargetArn=target_arn, From 1ed3dbc3905890724f800ed672b83897147321bb Mon Sep 17 00:00:00 2001 From: shaikshakeel Date: Thu, 17 Oct 2019 12:07:05 +0530 Subject: [PATCH 05/13] add without subject testcase --- tests/contrib/hooks/test_aws_sns_hook.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/contrib/hooks/test_aws_sns_hook.py b/tests/contrib/hooks/test_aws_sns_hook.py index 9c22e0b0b7eb5..0aa28dbde25cb 100644 --- a/tests/contrib/hooks/test_aws_sns_hook.py +++ b/tests/contrib/hooks/test_aws_sns_hook.py @@ -49,6 +49,18 @@ def test_publish_to_target(self): self.assertTrue('MessageId' in response) + @mock_sns + def test_publish_to_target_without_subject(self): + hook = AwsSnsHook(aws_conn_id='aws_default') + + message = "Hello world" + topic_name = "test-topic" + target = hook.get_conn().create_topic(Name=topic_name).get('TopicArn') + + response = hook.publish_to_target(target, message) + + self.assertTrue('MessageId' in response) + if __name__ == '__main__': unittest.main() From 55a82d4978ccbcdcfc2972796e05eb68450dfc4c Mon Sep 17 00:00:00 2001 From: shaikshakeel Date: Thu, 17 Oct 2019 12:54:23 +0530 Subject: [PATCH 06/13] run test cases again --- tests/contrib/hooks/test_aws_sns_hook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/contrib/hooks/test_aws_sns_hook.py b/tests/contrib/hooks/test_aws_sns_hook.py index 0aa28dbde25cb..2965bb3cf8081 100644 --- a/tests/contrib/hooks/test_aws_sns_hook.py +++ b/tests/contrib/hooks/test_aws_sns_hook.py @@ -54,7 +54,7 @@ def test_publish_to_target_without_subject(self): hook = AwsSnsHook(aws_conn_id='aws_default') message = "Hello world" - topic_name = "test-topic" + topic_name = "test-topic-without-subject" target = hook.get_conn().create_topic(Name=topic_name).get('TopicArn') response = hook.publish_to_target(target, message) From b1535967154cfee05819118ead14f919abc3940d Mon Sep 17 00:00:00 2001 From: shaikshakeel Date: Thu, 17 Oct 2019 15:24:34 +0530 Subject: [PATCH 07/13] run test cases --- tests/contrib/hooks/test_aws_sns_hook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/contrib/hooks/test_aws_sns_hook.py b/tests/contrib/hooks/test_aws_sns_hook.py index 2965bb3cf8081..0aa28dbde25cb 100644 --- a/tests/contrib/hooks/test_aws_sns_hook.py +++ b/tests/contrib/hooks/test_aws_sns_hook.py @@ -54,7 +54,7 @@ def test_publish_to_target_without_subject(self): hook = AwsSnsHook(aws_conn_id='aws_default') message = "Hello world" - topic_name = "test-topic-without-subject" + topic_name = "test-topic" target = hook.get_conn().create_topic(Name=topic_name).get('TopicArn') response = hook.publish_to_target(target, message) From dfb8cb3b8ac98097f29f7d8a66e1b6a0bfd60666 Mon Sep 17 00:00:00 2001 From: shaikshakeel Date: Mon, 21 Oct 2019 16:59:31 +0530 Subject: [PATCH 08/13] run test cases --- tests/contrib/hooks/test_aws_sns_hook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/contrib/hooks/test_aws_sns_hook.py b/tests/contrib/hooks/test_aws_sns_hook.py index 0aa28dbde25cb..2965bb3cf8081 100644 --- a/tests/contrib/hooks/test_aws_sns_hook.py +++ b/tests/contrib/hooks/test_aws_sns_hook.py @@ -54,7 +54,7 @@ def test_publish_to_target_without_subject(self): hook = AwsSnsHook(aws_conn_id='aws_default') message = "Hello world" - topic_name = "test-topic" + topic_name = "test-topic-without-subject" target = hook.get_conn().create_topic(Name=topic_name).get('TopicArn') response = hook.publish_to_target(target, message) From ee57dd8b18c588ca8d98a6bd39262127eed7c088 Mon Sep 17 00:00:00 2001 From: shaikshakeel Date: Tue, 22 Oct 2019 12:15:09 +0530 Subject: [PATCH 09/13] run testcases --- tests/contrib/hooks/test_aws_sns_hook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/contrib/hooks/test_aws_sns_hook.py b/tests/contrib/hooks/test_aws_sns_hook.py index 2965bb3cf8081..0aa28dbde25cb 100644 --- a/tests/contrib/hooks/test_aws_sns_hook.py +++ b/tests/contrib/hooks/test_aws_sns_hook.py @@ -54,7 +54,7 @@ def test_publish_to_target_without_subject(self): hook = AwsSnsHook(aws_conn_id='aws_default') message = "Hello world" - topic_name = "test-topic-without-subject" + topic_name = "test-topic" target = hook.get_conn().create_topic(Name=topic_name).get('TopicArn') response = hook.publish_to_target(target, message) From fd6caa37f9673355e8fcf95c36fbd4a295c3e643 Mon Sep 17 00:00:00 2001 From: shaikshakeel Date: Mon, 28 Oct 2019 23:45:30 +0530 Subject: [PATCH 10/13] update README.md with freshworks company --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3bb90fd3209e5..b5fb25fb353a7 100644 --- a/README.md +++ b/README.md @@ -434,6 +434,7 @@ Currently **officially** using Airflow: 1. [Zenly](https://zen.ly) [[@cerisier](https://github.com/cerisier) & [@jbdalido](https://github.com/jbdalido)] 1. [Zymergen](https://www.zymergen.com/) 1. [Zynga](https://www.zynga.com) +1. [Freshworks](https://www.freshworks.com/) [[@shaikshakeel](https://github.com/shaikshakeel)] ## Who Maintains Apache Airflow? From 7c98f83ec49f8355c96eefb75cac9eeb15e17662 Mon Sep 17 00:00:00 2001 From: shaikshakeel Date: Mon, 28 Oct 2019 23:55:42 +0530 Subject: [PATCH 11/13] remove unmerged sns code --- airflow/contrib/hooks/aws_sns_hook.py | 9 --------- tests/contrib/hooks/test_aws_sns_hook.py | 13 ------------- 2 files changed, 22 deletions(-) diff --git a/airflow/contrib/hooks/aws_sns_hook.py b/airflow/contrib/hooks/aws_sns_hook.py index 6d47fc74b5dd9..cf9b9541dbaa8 100644 --- a/airflow/contrib/hooks/aws_sns_hook.py +++ b/airflow/contrib/hooks/aws_sns_hook.py @@ -49,8 +49,6 @@ def publish_to_target(self, target_arn, message, subject=None): :type target_arn: str :param message: the default message you want to send :param message: str - :param subject: subject of message - :type subject: str """ conn = self.get_conn() @@ -59,13 +57,6 @@ def publish_to_target(self, target_arn, message, subject=None): 'default': message } - if subject is None: - return conn.publish( - TargetArn=target_arn, - Message=json.dumps(messages), - MessageStructure='json' - ) - return conn.publish( TargetArn=target_arn, Message=json.dumps(messages), diff --git a/tests/contrib/hooks/test_aws_sns_hook.py b/tests/contrib/hooks/test_aws_sns_hook.py index 0aa28dbde25cb..480e29d08842e 100644 --- a/tests/contrib/hooks/test_aws_sns_hook.py +++ b/tests/contrib/hooks/test_aws_sns_hook.py @@ -40,19 +40,6 @@ def test_get_conn_returns_a_boto3_connection(self): def test_publish_to_target(self): hook = AwsSnsHook(aws_conn_id='aws_default') - message = "Hello world" - topic_name = "test-topic" - subject = "test-subject" - target = hook.get_conn().create_topic(Name=topic_name).get('TopicArn') - - response = hook.publish_to_target(target, message, subject) - - self.assertTrue('MessageId' in response) - - @mock_sns - def test_publish_to_target_without_subject(self): - hook = AwsSnsHook(aws_conn_id='aws_default') - message = "Hello world" topic_name = "test-topic" target = hook.get_conn().create_topic(Name=topic_name).get('TopicArn') From 5522d402a7c777acd77c7e73b11cf66245a7def6 Mon Sep 17 00:00:00 2001 From: shaikshakeel Date: Mon, 28 Oct 2019 23:56:52 +0530 Subject: [PATCH 12/13] remove subject from aws_sns_hook.py --- airflow/contrib/hooks/aws_sns_hook.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/airflow/contrib/hooks/aws_sns_hook.py b/airflow/contrib/hooks/aws_sns_hook.py index cf9b9541dbaa8..7d5658afaf7c7 100644 --- a/airflow/contrib/hooks/aws_sns_hook.py +++ b/airflow/contrib/hooks/aws_sns_hook.py @@ -41,7 +41,7 @@ def get_conn(self): self.conn = self.get_client_type('sns') return self.conn - def publish_to_target(self, target_arn, message, subject=None): + def publish_to_target(self, target_arn, message): """ Publish a message to a topic or an endpoint. @@ -60,6 +60,5 @@ def publish_to_target(self, target_arn, message, subject=None): return conn.publish( TargetArn=target_arn, Message=json.dumps(messages), - MessageStructure='json', - Subject=subject + MessageStructure='json' ) From e75538aa889c56f2a16549847c89fc3a8a3be6ca Mon Sep 17 00:00:00 2001 From: shaikshakeel Date: Tue, 29 Oct 2019 01:52:24 +0530 Subject: [PATCH 13/13] maintain alphabetic order --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b5fb25fb353a7..ca08a832318d6 100644 --- a/README.md +++ b/README.md @@ -234,6 +234,7 @@ Currently **officially** using Airflow: 1. [Flipp](https://www.flipp.com) [[@sethwilsonwishabi](https://github.com/sethwilsonwishabi)] 1. [Format](https://www.format.com) [[@format](https://github.com/4ormat) & [@jasonicarter](https://github.com/jasonicarter)] 1. [FreshBooks](https://github.com/freshbooks) [[@DinoCow](https://github.com/DinoCow)] +1. [Freshworks](https://www.freshworks.com/) [[@shaikshakeel](https://github.com/shaikshakeel)] 1. [FullContact](https://github.com/fullcontact) 1. [Fuller, Inc.](https://en.fuller-inc.com/) [[@wutali](https://github.com/wutali) & [@sh-tech](https://github.com/sh-tech)] 1. [Fundera](https://fundera.com) [[@andyxhadji](https://github.com/andyxhadji)] @@ -434,7 +435,6 @@ Currently **officially** using Airflow: 1. [Zenly](https://zen.ly) [[@cerisier](https://github.com/cerisier) & [@jbdalido](https://github.com/jbdalido)] 1. [Zymergen](https://www.zymergen.com/) 1. [Zynga](https://www.zynga.com) -1. [Freshworks](https://www.freshworks.com/) [[@shaikshakeel](https://github.com/shaikshakeel)] ## Who Maintains Apache Airflow?