From 77397c6c4fcf6071bafae0b44397cc2f5db70fe9 Mon Sep 17 00:00:00 2001 From: Malthe Borch Date: Thu, 27 May 2021 15:16:18 +0200 Subject: [PATCH 1/8] Add support for extra parameters to samba client --- airflow/providers/samba/hooks/samba.py | 1 + tests/providers/samba/hooks/test_samba.py | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/airflow/providers/samba/hooks/samba.py b/airflow/providers/samba/hooks/samba.py index e792ba6fb9ad3..40c147c4ceb62 100644 --- a/airflow/providers/samba/hooks/samba.py +++ b/airflow/providers/samba/hooks/samba.py @@ -42,6 +42,7 @@ def get_conn(self) -> SambaClient: username=self.conn.login, ip=self.conn.host, password=self.conn.password, + **self.conn.extra_dejson, ) return samba diff --git a/tests/providers/samba/hooks/test_samba.py b/tests/providers/samba/hooks/test_samba.py index 61b90c7b0b414..489766811d4e8 100644 --- a/tests/providers/samba/hooks/test_samba.py +++ b/tests/providers/samba/hooks/test_samba.py @@ -20,6 +20,7 @@ from unittest import mock from unittest.mock import call +import json import pytest import smbclient @@ -27,7 +28,13 @@ from airflow.models import Connection from airflow.providers.samba.hooks.samba import SambaHook -connection = Connection(host='ip', schema='share', login='username', password='password') +connection = Connection( + host='ip', + schema='share', + login='username', + password='password', + extra=json.dumps({'workgroup': 'workgroup'}), +) class TestSambaHook(unittest.TestCase): @@ -35,12 +42,14 @@ def test_get_conn_should_fail_if_conn_id_does_not_exist(self): with pytest.raises(AirflowException): SambaHook('conn') + @mock.patch('airflow.providers.samba.hooks.samba.SambaClient') @mock.patch('airflow.hooks.base.BaseHook.get_connection') - def test_get_conn(self, get_conn_mock): + def test_get_conn(self, get_conn_mock, get_client_mock): get_conn_mock.return_value = connection hook = SambaHook('samba_default') - - assert isinstance(hook.get_conn(), smbclient.SambaClient) + conn = hook.get_conn() + assert str(get_client_mock.mock_calls[0].workgroup) == "workgroup" + assert conn is get_client_mock() get_conn_mock.assert_called_once_with('samba_default') @mock.patch('airflow.providers.samba.hooks.samba.SambaHook.get_conn') From 90ad4b42b0aa1f1aa1241709a8bcfed6169befa6 Mon Sep 17 00:00:00 2001 From: Malthe Borch Date: Thu, 27 May 2021 15:24:28 +0200 Subject: [PATCH 2/8] Add description of extra fields --- airflow/providers/samba/hooks/samba.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/airflow/providers/samba/hooks/samba.py b/airflow/providers/samba/hooks/samba.py index 40c147c4ceb62..6a149a47a3fca 100644 --- a/airflow/providers/samba/hooks/samba.py +++ b/airflow/providers/samba/hooks/samba.py @@ -36,6 +36,19 @@ def __init__(self, samba_conn_id: str = default_conn_name) -> None: self.conn = self.get_connection(samba_conn_id) def get_conn(self) -> SambaClient: + """ + Return a samba client object. + + You can provide optional parameters in the extra fields of + your connection. + + :param logdir: Base directory name for log/debug files. + :param kerberos: Try to authenticate with kerberos. + :param workgroup: Set the SMB domain of the username. + :param netbios_name: + This option allows you to override the NetBIOS name that + Samba uses for itself. + """ samba = SambaClient( server=self.conn.host, share=self.conn.schema, From 9a8beb8deac47978914526fa3a0e93e27731309a Mon Sep 17 00:00:00 2001 From: Malthe Borch Date: Thu, 27 May 2021 16:33:32 +0200 Subject: [PATCH 3/8] Reformat extra field descriptions --- airflow/providers/samba/hooks/samba.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/airflow/providers/samba/hooks/samba.py b/airflow/providers/samba/hooks/samba.py index 6a149a47a3fca..193c1f1468cc5 100644 --- a/airflow/providers/samba/hooks/samba.py +++ b/airflow/providers/samba/hooks/samba.py @@ -42,12 +42,22 @@ def get_conn(self) -> SambaClient: You can provide optional parameters in the extra fields of your connection. - :param logdir: Base directory name for log/debug files. - :param kerberos: Try to authenticate with kerberos. - :param workgroup: Set the SMB domain of the username. - :param netbios_name: - This option allows you to override the NetBIOS name that - Samba uses for itself. + Below is an inexhaustive list of these parameters: + + logdir + Base directory name for log/debug files. + + kerberos + Try to authenticate with kerberos. + + workgroup + Set the SMB domain of the username. + + netbios_name + This option allows you to override the NetBIOS name that + Samba uses for itself. + + For additional details, see `smbclient.SambaClient`. """ samba = SambaClient( server=self.conn.host, From 0364d1c7ff846fbe86985ceae1453ae11479c84a Mon Sep 17 00:00:00 2001 From: Malthe Borch Date: Thu, 3 Jun 2021 09:46:26 +0200 Subject: [PATCH 4/8] Add spelling for 'NetBIOS' --- docs/spelling_wordlist.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/spelling_wordlist.txt b/docs/spelling_wordlist.txt index e5d4c7f8acb81..b30092b1fc6d1 100644 --- a/docs/spelling_wordlist.txt +++ b/docs/spelling_wordlist.txt @@ -265,6 +265,7 @@ Naik Namenode Namespace Neo4j +NetBIOS Nextdoor Nones NotFound From 4ad6d0c2ddc88d403ebdd40e1437cd1e94aef268 Mon Sep 17 00:00:00 2001 From: Malthe Borch Date: Thu, 3 Jun 2021 09:46:33 +0200 Subject: [PATCH 5/8] Fix imports --- tests/providers/samba/hooks/test_samba.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/providers/samba/hooks/test_samba.py b/tests/providers/samba/hooks/test_samba.py index 489766811d4e8..f384e9e77cb70 100644 --- a/tests/providers/samba/hooks/test_samba.py +++ b/tests/providers/samba/hooks/test_samba.py @@ -16,13 +16,12 @@ # specific language governing permissions and limitations # under the License. +import json import unittest from unittest import mock from unittest.mock import call -import json import pytest -import smbclient from airflow.exceptions import AirflowException from airflow.models import Connection From f174072a2218f981ad8f88ae2366a53fdf049842 Mon Sep 17 00:00:00 2001 From: Malthe Borch Date: Thu, 3 Jun 2021 11:44:46 +0200 Subject: [PATCH 6/8] Format as code to avoid spellcheck errors --- airflow/providers/samba/hooks/samba.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/airflow/providers/samba/hooks/samba.py b/airflow/providers/samba/hooks/samba.py index 193c1f1468cc5..f8234ebe3df2b 100644 --- a/airflow/providers/samba/hooks/samba.py +++ b/airflow/providers/samba/hooks/samba.py @@ -44,16 +44,16 @@ def get_conn(self) -> SambaClient: Below is an inexhaustive list of these parameters: - logdir + `logdir` Base directory name for log/debug files. - kerberos + `kerberos` Try to authenticate with kerberos. - workgroup + `workgroup` Set the SMB domain of the username. - netbios_name + `netbios_name` This option allows you to override the NetBIOS name that Samba uses for itself. From 098dd5e586c8345698577491412c2633a6724fb5 Mon Sep 17 00:00:00 2001 From: Malthe Borch Date: Thu, 3 Jun 2021 13:33:03 +0200 Subject: [PATCH 7/8] Add word to spellcheck --- docs/spelling_wordlist.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/spelling_wordlist.txt b/docs/spelling_wordlist.txt index b30092b1fc6d1..900feb9d0845b 100644 --- a/docs/spelling_wordlist.txt +++ b/docs/spelling_wordlist.txt @@ -191,6 +191,7 @@ IdP ImageAnnotatorClient Imap Imberman +inexhaustive InsecureClient InspectContentResponse InspectTemplate From ea4e6aad04686a9e26d4e59e9b9508fe772fc4aa Mon Sep 17 00:00:00 2001 From: Malthe Borch Date: Fri, 4 Jun 2021 08:42:55 +0200 Subject: [PATCH 8/8] Fix order --- docs/spelling_wordlist.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/spelling_wordlist.txt b/docs/spelling_wordlist.txt index 900feb9d0845b..f37a4a08c632d 100644 --- a/docs/spelling_wordlist.txt +++ b/docs/spelling_wordlist.txt @@ -191,7 +191,6 @@ IdP ImageAnnotatorClient Imap Imberman -inexhaustive InsecureClient InspectContentResponse InspectTemplate @@ -884,6 +883,7 @@ img imgcat impyla incompliancies +inexhaustive infile infoType infoTypes