Skip to content

Commit

Permalink
Fix hooks extended from http hook (apache#16109)
Browse files Browse the repository at this point in the history
(cherry picked from commit 10ed42a)
  • Loading branch information
msumit authored and potiuk committed Jun 22, 2021
1 parent ce8bf57 commit a659c37
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 9 deletions.
5 changes: 5 additions & 0 deletions airflow/providers/airbyte/hooks/airbyte.py
Expand Up @@ -33,6 +33,11 @@ class AirbyteHook(HttpHook):
:type api_version: str
"""

conn_name_attr = 'airbyte_conn_id'
default_conn_name = 'airbyte_default'
conn_type = 'airbyte'
hook_name = 'Airbyte'

RUNNING = "running"
SUCCEEDED = "succeeded"
CANCELLED = "cancelled"
Expand Down
5 changes: 5 additions & 0 deletions airflow/providers/dingding/hooks/dingding.py
Expand Up @@ -48,6 +48,11 @@ class DingdingHook(HttpHook):
:type at_all: bool
"""

conn_name_attr = 'dingding_conn_id'
default_conn_name = 'dingding_default'
conn_type = 'dingding'
hook_name = 'Dingding'

def __init__(
self,
dingding_conn_id='dingding_default',
Expand Down
3 changes: 3 additions & 0 deletions airflow/providers/dingding/provider.yaml
Expand Up @@ -43,3 +43,6 @@ hooks:
- integration-name: IBM Cloudant
python-modules:
- airflow.providers.dingding.hooks.dingding

hook-class-names:
- airflow.providers.dingding.hooks.dingding.DingdingHook
5 changes: 5 additions & 0 deletions airflow/providers/discord/hooks/discord_webhook.py
Expand Up @@ -54,6 +54,11 @@ class DiscordWebhookHook(HttpHook):
:type proxy: str
"""

conn_name_attr = 'http_conn_id'
default_conn_name = 'discord_default'
conn_type = 'discord'
hook_name = 'Discord'

def __init__(
self,
http_conn_id: Optional[str] = None,
Expand Down
3 changes: 3 additions & 0 deletions airflow/providers/discord/provider.yaml
Expand Up @@ -40,3 +40,6 @@ hooks:
- integration-name: Discord
python-modules:
- airflow.providers.discord.hooks.discord_webhook

hook-class-names:
- airflow.providers.discord.hooks.discord_webhook.DiscordWebhookHook
5 changes: 5 additions & 0 deletions airflow/providers/opsgenie/hooks/opsgenie_alert.py
Expand Up @@ -41,6 +41,11 @@ class OpsgenieAlertHook(HttpHook):
"""

conn_name_attr = 'opsgenie_conn_id'
default_conn_name = 'opsgenie_default'
conn_type = 'opsgenie'
hook_name = 'Opsgenie'

def __init__(self, opsgenie_conn_id: str = 'opsgenie_default', *args, **kwargs) -> None:
super().__init__(http_conn_id=opsgenie_conn_id, *args, **kwargs) # type: ignore[misc]

Expand Down
3 changes: 3 additions & 0 deletions airflow/providers/opsgenie/provider.yaml
Expand Up @@ -41,3 +41,6 @@ hooks:
- integration-name: Opsgenie
python-modules:
- airflow.providers.opsgenie.hooks.opsgenie_alert

hook-class-names:
- airflow.providers.opsgenie.hooks.opsgenie_alert.OpsgenieAlertHook
5 changes: 5 additions & 0 deletions airflow/providers/slack/hooks/slack_webhook.py
Expand Up @@ -61,6 +61,11 @@ class SlackWebhookHook(HttpHook):
:type proxy: str
"""

conn_name_attr = 'http_conn_id'
default_conn_name = 'slack_default'
conn_type = 'slackwebhook'
hook_name = 'Slack Webhook'

# pylint: disable=too-many-arguments
def __init__(
self,
Expand Down
3 changes: 3 additions & 0 deletions airflow/providers/slack/provider.yaml
Expand Up @@ -43,3 +43,6 @@ hooks:
python-modules:
- airflow.providers.slack.hooks.slack
- airflow.providers.slack.hooks.slack_webhook

hook-class-names:
- airflow.providers.slack.hooks.slack_webhook.SlackWebhookHook
Expand Up @@ -118,7 +118,7 @@ function discover_all_hooks() {
group_start "Listing available hooks via 'airflow providers hooks'"
COLUMNS=180 airflow providers hooks

local expected_number_of_hooks=65
local expected_number_of_hooks=70
local actual_number_of_hooks
actual_number_of_hooks=$(airflow providers hooks --output table | grep -c "| apache" | xargs)
if [[ ${actual_number_of_hooks} != "${expected_number_of_hooks}" ]]; then
Expand Down
5 changes: 5 additions & 0 deletions tests/core/test_providers_manager.py
Expand Up @@ -91,6 +91,7 @@
]

CONNECTIONS_LIST = [
'airbyte',
'asana',
'aws',
'azure',
Expand All @@ -104,6 +105,8 @@
'cloudant',
'databricks',
'dataprep',
'dingding',
'discord',
'docker',
'druid',
'elasticsearch',
Expand Down Expand Up @@ -133,6 +136,7 @@
'mysql',
'neo4j',
'odbc',
'opsgenie',
'oracle',
'pig_cli',
'postgres',
Expand All @@ -143,6 +147,7 @@
'samba',
'segment',
'sftp',
'slackwebhook',
'snowflake',
'spark',
'spark_jdbc',
Expand Down
2 changes: 1 addition & 1 deletion tests/providers/airbyte/hooks/test_airbyte.py
Expand Up @@ -44,7 +44,7 @@ class TestAirbyteHook(unittest.TestCase):
def setUp(self):
db.merge_conn(
Connection(
conn_id='airbyte_conn_id_test', conn_type='http', host='http://test-airbyte', port=8001
conn_id='airbyte_conn_id_test', conn_type='airbyte', host='http://test-airbyte', port=8001
)
)
self.hook = AirbyteHook(airbyte_conn_id=self.airbyte_conn_id)
Expand Down
2 changes: 1 addition & 1 deletion tests/providers/dingding/hooks/test_dingding.py
Expand Up @@ -33,7 +33,7 @@ def setUp(self):
db.merge_conn(
Connection(
conn_id=self.conn_id,
conn_type='http',
conn_type='dingding',
host='https://oapi.dingtalk.com',
password='you_token_here',
)
Expand Down
2 changes: 1 addition & 1 deletion tests/providers/discord/hooks/test_discord_webhook.py
Expand Up @@ -52,7 +52,7 @@ def setUp(self):
db.merge_conn(
Connection(
conn_id='default-discord-webhook',
conn_type='http',
conn_type='discord',
host='https://discordapp.com/api/',
extra='{"webhook_endpoint": "webhooks/00000/some-discord-token_000"}',
)
Expand Down
2 changes: 1 addition & 1 deletion tests/providers/opsgenie/hooks/test_opsgenie_alert.py
Expand Up @@ -70,7 +70,7 @@ def setUp(self):
db.merge_conn(
Connection(
conn_id=self.conn_id,
conn_type='http',
conn_type='opsgenie',
host='https://api.opsgenie.com/',
password='eb243592-faa2-4ba2-a551q-1afdf565c889',
)
Expand Down
10 changes: 6 additions & 4 deletions tests/providers/slack/hooks/test_slack_webhook.py
Expand Up @@ -60,26 +60,28 @@ def setUp(self):
db.merge_conn(
Connection(
conn_id='slack-webhook-default',
conn_type='http',
conn_type='slackwebhook',
extra='{"webhook_token": "your_token_here"}',
)
)
db.merge_conn(
Connection(
conn_id='slack-webhook-url',
conn_type='http',
conn_type='slackwebhook',
host='https://hooks.slack.com/services/T000/B000/XXX',
)
)
db.merge_conn(
Connection(
conn_id='slack-webhook-host', conn_type='http', host='https://hooks.slack.com/services/T000/'
conn_id='slack-webhook-host',
conn_type='slackwebhook',
host='https://hooks.slack.com/services/T000/',
)
)
db.merge_conn(
Connection(
conn_id='slack-webhook-with-password',
conn_type='http',
conn_type='slackwebhook',
password='your_token_here',
)
)
Expand Down

0 comments on commit a659c37

Please sign in to comment.