summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorRob van der Linde <rob@catalyst.net.nz>2023-05-16 13:54:59 +1200
committerAndrew Bartlett <abartlet@samba.org>2023-06-25 23:29:32 +0000
commit3da5be0b8f8ddbac05d58871f08448c3c4dc27b8 (patch)
treeb0581c562aec0206872e6fca85ade6bb24bc021f /python
parentd558b20ed10a1d7f07fcc861e0db5635998ba455 (diff)
downloadsamba-3da5be0b8f8ddbac05d58871f08448c3c4dc27b8.tar.gz
samba-3da5be0b8f8ddbac05d58871f08448c3c4dc27b8.tar.bz2
samba-3da5be0b8f8ddbac05d58871f08448c3c4dc27b8.zip
netcmd: move ldb_connect method to base class
This method is needed by just about every command and moving it here is another step towards elinimanting the base classes in domain/auth and domain/claim. The base classes are almost empty now, since introducing the model layer. The next step is to get rid of these base classes completely. Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Diffstat (limited to 'python')
-rw-r--r--python/samba/netcmd/__init__.py9
-rw-r--r--python/samba/netcmd/domain/auth/base.py9
-rw-r--r--python/samba/netcmd/domain/claim/base.py9
3 files changed, 9 insertions, 18 deletions
diff --git a/python/samba/netcmd/__init__.py b/python/samba/netcmd/__init__.py
index 659fcbea369..1401ea263a2 100644
--- a/python/samba/netcmd/__init__.py
+++ b/python/samba/netcmd/__init__.py
@@ -19,8 +19,10 @@
import optparse
import samba
from samba import colour
+from samba.auth import system_session
from samba.getopt import SambaOption, OptionError
from samba.logger import get_samba_logger
+from samba.samdb import SamDB
from ldb import LdbError, ERR_INVALID_CREDENTIALS
import sys
import traceback
@@ -141,6 +143,13 @@ class Command(object):
else:
print(f"{err}{klass}: {msg} - {evalue}", file=self.errf)
+ def ldb_connect(self, ldap_url, sambaopts, credopts):
+ """Helper to connect to Ldb database using command line opts."""
+ lp = sambaopts.get_loadparm()
+ creds = credopts.get_credentials(lp)
+ return SamDB(ldap_url, credentials=creds,
+ session_info=system_session(lp), lp=lp)
+
def show_command_error(self, e):
"""display a command error"""
if isinstance(e, CommandError):
diff --git a/python/samba/netcmd/domain/auth/base.py b/python/samba/netcmd/domain/auth/base.py
index 6734751e6ad..14301e5f83e 100644
--- a/python/samba/netcmd/domain/auth/base.py
+++ b/python/samba/netcmd/domain/auth/base.py
@@ -22,11 +22,9 @@
import json
-from samba.auth import system_session
from samba.netcmd import Command, CommandError
from samba.netcmd.encoders import JSONEncoder
from samba.netcmd.domain.models import AuthenticationPolicy
-from samba.samdb import SamDB
class SiloCommand(Command):
@@ -34,13 +32,6 @@ class SiloCommand(Command):
super().__init__(*args, **kwargs)
self.ldb = None
- def ldb_connect(self, ldap_url, sambaopts, credopts):
- """Helper to connect to Ldb database using command line opts."""
- lp = sambaopts.get_loadparm()
- creds = credopts.get_credentials(lp)
- return SamDB(ldap_url, credentials=creds,
- session_info=system_session(lp), lp=lp)
-
def print_json(self, data):
"""Print json on the screen using consistent formatting and sorting.
diff --git a/python/samba/netcmd/domain/claim/base.py b/python/samba/netcmd/domain/claim/base.py
index 393195a6fe9..e398c945b66 100644
--- a/python/samba/netcmd/domain/claim/base.py
+++ b/python/samba/netcmd/domain/claim/base.py
@@ -23,10 +23,8 @@
import json
from ldb import SCOPE_ONELEVEL
-from samba.auth import system_session
from samba.netcmd import Command
from samba.netcmd.encoders import JSONEncoder
-from samba.samdb import SamDB
class ClaimCommand(Command):
@@ -36,13 +34,6 @@ class ClaimCommand(Command):
super().__init__(*args, **kwargs)
self.ldb = None
- def ldb_connect(self, ldap_url, sambaopts, credopts):
- """Helper to connect to Ldb database using command line opts."""
- lp = sambaopts.get_loadparm()
- creds = credopts.get_credentials(lp)
- return SamDB(ldap_url, credentials=creds,
- session_info=system_session(lp), lp=lp)
-
def print_json(self, data):
"""Print json on the screen using consistent formatting and sorting.