You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by el...@apache.org on 2021/06/06 08:56:45 UTC

[airflow] branch main updated: Add support for extra parameters to samba client (#16115)

This is an automated email from the ASF dual-hosted git repository.

eladkal pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new a47a254  Add support for extra parameters to samba client (#16115)
a47a254 is described below

commit a47a2548bed8a8e7206fe490a9be03b0513b4059
Author: Malthe Borch <mb...@gmail.com>
AuthorDate: Sun Jun 6 10:56:12 2021 +0200

    Add support for extra parameters to samba client (#16115)
    
    * Add support for extra parameters to samba client
    
    * Add description of extra fields
    
    * Reformat extra field descriptions
    
    * Add spelling for 'NetBIOS'
    
    * Fix imports
    
    * Format as code to avoid spellcheck errors
    
    * Add word to spellcheck
    
    * Fix order
---
 airflow/providers/samba/hooks/samba.py    | 24 ++++++++++++++++++++++++
 docs/spelling_wordlist.txt                |  2 ++
 tests/providers/samba/hooks/test_samba.py | 18 +++++++++++++-----
 3 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/airflow/providers/samba/hooks/samba.py b/airflow/providers/samba/hooks/samba.py
index e792ba6..f8234eb 100644
--- a/airflow/providers/samba/hooks/samba.py
+++ b/airflow/providers/samba/hooks/samba.py
@@ -36,12 +36,36 @@ class SambaHook(BaseHook):
         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.
+
+        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,
             share=self.conn.schema,
             username=self.conn.login,
             ip=self.conn.host,
             password=self.conn.password,
+            **self.conn.extra_dejson,
         )
         return samba
 
diff --git a/docs/spelling_wordlist.txt b/docs/spelling_wordlist.txt
index e5d4c7f..f37a4a0 100644
--- a/docs/spelling_wordlist.txt
+++ b/docs/spelling_wordlist.txt
@@ -265,6 +265,7 @@ Naik
 Namenode
 Namespace
 Neo4j
+NetBIOS
 Nextdoor
 Nones
 NotFound
@@ -882,6 +883,7 @@ img
 imgcat
 impyla
 incompliancies
+inexhaustive
 infile
 infoType
 infoTypes
diff --git a/tests/providers/samba/hooks/test_samba.py b/tests/providers/samba/hooks/test_samba.py
index 61b90c7..f384e9e 100644
--- a/tests/providers/samba/hooks/test_samba.py
+++ b/tests/providers/samba/hooks/test_samba.py
@@ -16,18 +16,24 @@
 # specific language governing permissions and limitations
 # under the License.
 
+import json
 import unittest
 from unittest import mock
 from unittest.mock import call
 
 import pytest
-import smbclient
 
 from airflow.exceptions import AirflowException
 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 +41,14 @@ class TestSambaHook(unittest.TestCase):
         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')